Community
cancel
Showing results for 
Search instead for 
Did you mean: 
60 Views

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:

[cpp]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[/cpp]

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

[cpp]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[/cpp]

TIA,
Best regards,
Giovanni
0 Kudos
1 Reply
Georg_Z_Intel
Employee
60 Views

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
Reply