Intel compiler and NRVO?

Intel compiler and NRVO?

Hello,

Does the intel compiler supports NRVO (Named Return Value Optimization)? i.e. cheaply returning big objects by value in function signatures, if so are there examples of how this works?

For example I have a type matrix and I favor the following design and signature for obvious performance reasons:

template 
class tmatrix {
    void tmatrix::multiply(const tmatrix& b, tmatrix& c) const; // confusing and very unreadable 
};

// client code
tmatrix a, b, c;
// ...
a.multiply(b, c); // meaning c = a*b

if NRVO is suported then I can rely on the following alternative without any big memory copying performance penalty:

template 
class tmatrix {
    tmatrix tmatrix::operator=(const tmatrix& b) const; // note that returned object is by value!
};

// client code
tmatrix a, b, c;
// ...
c = a*b

TIA,
Best regards,
Giovanni

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello Giovanni,

(Named) Return Value Optimization (RVO) will be done by Intel® C++ Compiler. There are various examples that demonstrate the omission of the copy-ctor, e.g.:
http://msdn.microsoft.com/en-us/library/ms364057%28v=vs.80%29.aspx
http://en.wikipedia.org/wiki/Return_value_optimization

AFAIK it's on per default and there's no option to turn it off for our compiler. So, it's not possible to make a comparison between turned on RVO an turned off RVO.
The easiest way to verify is to use a debugger and set a break-point on the copy-ctor.

Best regards,

Georg Zitzlsberger

Leave a Comment

Please sign in to add a comment. Not a member? Join today