I have code that works mostly with single precision floating point numbers. Calls for transcendental functions occur quite often. Right now I am using the functions sin (), cos (), sqrt (), etc., which take and return double. When it is compiled for x87 only, I do not know the difference between single and double precision. I read in the Agner Fog Optimization Guide, however, that software versions of these functions using SSE instructions are faster for single-precision floating-point numbers.
My question is whether the compiler will automatically use a faster function when it encounters something like:
float x = 1.23;
float y = sin(x);
Or does the rounding rule preclude such an optimization?
It would be simple enough to search and replace and see if there is an increase in performance. The problem is that I also need pointers to these functions. In MSVC, the functions sinf (), cosf (), and friends are built-in functions. Therefore, using them will require a bit of gymnastics. Before I make an effort, I would like to know if it is worth doing.
Besides MSVC, I also configure gcc.
source
share