This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]