Re: floating point precision on gcc-4 differs using variables or arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Asfand,

>All the above is well and good, but please could someone answer the following question?  Is it easier for the compiler to work with numbers as variables (float a, float b, etc.) or as arrays (float data[4])  ?  By easier, I mean is it easier for it to perform optimisations.

I do not know.

I do know that the only way to really be certain is to profile your code with float, and profile it with double and measure the actual performance difference.

I also know that in C, the float data type is a second rate citizen, compared to double.  That may cause code pessimization as the compiler promotes float to double for parameter passing.  (C++ makes float a first rate data type; but there are still some C legacy aspects to C++ that haunts float.)  Passing in float* and/or working with float arrays will curtail that promotion behavior.

In the olden days, the rule of thumb was to avoid floating point data types for performance driven games.  But with these new fangled CPUs, floating point data types are as good (and in some cases, better!) than integer types.  So if you read something that recommends avoiding floating point, it may be out of step with current hardware.  Just a FYI.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux