Bug 33293 - inlining std::inner_product()
Summary: inlining std::inner_product()
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.2.1
: P3 minor
Target Milestone: 4.3.0
Assignee: Paolo Carlini
Depends on:
Reported: 2007-09-03 16:47 UTC by Simon Marshall
Modified: 2007-09-04 08:43 UTC (History)
2 users (show)

See Also:
Host: sparc-sun-solaris2.8
Known to work:
Known to fail:
Last reconfirmed: 2007-09-03 17:20:12


Note You need to log in before you can comment on or make changes to this bug.
Description Simon Marshall 2007-09-03 16:47:42 UTC
I use std::inner_product() to do the vector multiplication when performing matrix multiplication.  This involves calling std::inner_product() within 2 nested loops (one across all rows, one across all columns).  Unfortunately, g++-4.1.2 will not, it seems, inline the call even at -O5.  If I provide my own version with an inline hint, it improves the speed of my matrix multiplication by ~15%, which is not to be sniffed at.

I suppose my questions would be:

(a) erm, do you need proof?

(b) should the compiler do the inlining regardless (ie, it's a compiler issue), or should the declaration of std::inner_product give a hint with the inline keyword (and perhaps also other functions)?

Comment 1 Paolo Carlini 2007-09-03 17:20:11 UTC
Note, in GCC any -Ox, x > 3 is identical to -O3.

Anyway, I think we can safely add inline to std::accumulate and std::inner_product.
Comment 2 paolo@gcc.gnu.org 2007-09-03 17:48:43 UTC
Subject: Bug 33293

Author: paolo
Date: Mon Sep  3 17:48:31 2007
New Revision: 128053

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128053
2007-09-03  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/33293
	* include/bits/stl_numeric.h (accumulate, inner_product):
	Add inline function-specifier.


Comment 3 Paolo Carlini 2007-09-03 17:50:06 UTC
Fixed for 4.3.0.
Comment 4 Simon Marshall 2007-09-04 08:01:40 UTC
Many thanks for the quick response.  Any chance it could make it into 4.2.2?
Comment 5 Paolo Carlini 2007-09-04 08:41:58 UTC
The patch itself is trivial but in our experience changing the inlining patterns can have far reaching and unpredictable fall-outs. Thus, better not touching the release branches, sorry.
Comment 6 Simon Marshall 2007-09-04 08:43:01 UTC
OK, thanks.