c++ - Bad optimization of std::fabs()? -


Recently I was working with an application that had the code:

 < Code> (Auto X = 0; x and lt; width - 1 - left; ++ x) {// store / reset points temp = hPoint = 0; (Int channel = 0; channel & lt; audioData.size (channel; ++) {if (peakmode) / * window size * fir rms * / {for (int z = 0; z  std :: fabs (hPoint)) hPoint = temp; }} .. some other code} ... some more code}  

This is inside a graphical render loop, which is up to 192kHz in many channels with buffers 50-100 times / second Is called. There are so many statistics that run through most inner loops, and profiling showed that it was a hotspot.

It happened to me that someone could float an integer and erase the sign bit, and put it back on something like this seen using only temporary:

  if (const float & amp; nbsp; (* ((* integer *) and temporary) & amp; ~ 0x80000000)> (const float & amp;; (* (* * *) and H point) & amp; ~ 0x80000000)) hPoint = temp;  

It reduced the render time by 12x, while still producing the same, valid output. Note that everything in AudiData is already clean to not include Nain / Infox / Denimlar, and there is only one series of [-1, 1]

Are there any corner cases, Where this optimization will give the wrong result - or, is not the standard library function so applicable? What do I have to do with dealing with non-normal values?

E: Layout of floating point model is analogous to ICE, and size (float) == size (int) == 4

OK, you set floating point mode to IEEE compliant. Typically, with the switch - fast-math as compiler can ignore IEEE corner cases like NAN, INF and Deniml. If the compiler also uses the internal code, then it might emit the same code.

BTW, If you are going to accept the IEEE format, there is no need to put float back on the IEEE format before the comparison is the Nifty: all < / Strikes> Positive finite values, a & lt; B and if only then reinterpret_cast & lt; Int_type & gt; (A) & lt; Reinterpret_cast & lt; Int_type & gt; (B)


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -