std::norm improvement

Jaroslav Hajek highegg@gmail.com
Wed Mar 4 07:42:00 GMT 2009


Hello,

following a recent discussion on comp.lang.c++ about QOI vs.
performance of GCC's implementation of std::norm, it seems I succeeded
to create an implementation that retains the numerical robustness of
the present implementation, yet apparently achieves a higher
performance (avoids sqrt).
The current implementation, used for floating point types, simply
squares the result of std::abs.

I include the patch against gcc trunk (mady by svn diff) as well as
the test program I used to measure the impact.

With g++ 4.3.1, compiling by g++ -O3 test.cc, I get on a Core 2 Duo @ 2.83GHz:

testing floats...
time elapsed = 270000
residual = 7.62815e-20
testing doubles...
time elapsed = 240000
residual = 2.36858e-163

whereas with the patched header, I get:

testing floats...
time elapsed = 60000
residual = 5.40582e-20
testing doubles...
time elapsed = 110000
residual = 1.41387e-163

so it seems the patched version wins in terms of both accuracy and performance.

Please let me know if there's something more to do. The change is
minor, but here's a changelog entry just in case:

2009-03-04  Jaroslav Hajek  <highegg@gmail.com>

	* include/std/complex (_Norm_helper<true>::_S_do_it): Optimize.

regards

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: complex_norm.diff
Type: text/x-diff
Size: 749 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20090304/36b1e820/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cc
Type: text/x-c++src
Size: 1614 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20090304/36b1e820/attachment-0001.bin>


More information about the Libstdc++ mailing list