Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Intel compiler and NRVO?

Azua_Garcia__Giovann
394 Views
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
394 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
0 Kudos
Reply