Hi

peter koch wrote:

Why are you changing between float and

double in the first place? You need a very good reason to use float:

double has better precision and is usually just as fast (or faster) as

well.

Weeeeell... I read a discussion about that recently, I would like to believe

it. But as I was trying to optimize some math code today, I looked it up

again. I can only say things about Intel processors, but...

From the "IntelĀ® 64 and IA-32 Architectures Optimization Reference Manual":

User/Source Coding Rule 15. (M impact, ML generality) Do not use double

precision unless necessary. Set the precision control (PC) field in the x87

FPU control word to "Single Precision". This allows single precision

(32-bit) computation to complete faster on some operations (for example,

divides due to early out). However, be careful of introducing more than a

total of two values for the floating point control word, or there will be a

large performance penalty. See Section 3.8.3.

[...]

3.8.3.2 Precision

If single precision is adequate, use it instead of double precision. This is

true because:

Single precision operations allow the use of longer SIMD vectors, since more

single precision data elements can fit in a register.

If the precision control (PC) field in the x87 FPU control word is set to

single precision, the floating-point divider can complete a

single-precision computation much faster than either a double-precision

computation or an extended double-precision computation. If the PC field is

set to double precision, this will enable those x87 FPU operations on

double-precision data to complete faster than extended double-precision

computation. These characteristics affect computations including

floating-point divide and square root.

Markus