2016-04-30 10:46 GMT+02:00 Jean-Michaël Celerier < jeanmichael.celer...@gmail.com>:
> https://godbolt.org/g/DqBlFG > > With gcc -O1 > > float f(float x) > { > return 2. * x; > } > > becomes > > f(float): > addss %xmm0, %xmm0 > ret > > > and > > float g (float x) > { > return 2.f * x; > } > > becomes > > g(float): > addss %xmm0, %xmm0 > ret > > This is on x86. I was talking about ARM with single-precision FPUs and the general advice not to use double precision constants if possible there. This is what GCC itself says in the documentation for -Wdouble-promotion: -Wdouble-promotion (C, C++, Objective-C and Objective-C++ only)Give a warning when a value of type float is implicitly promoted to double. CPUs with a 32-bit “single-precision” floating-point unit implement float in hardware, but emulate double in software. On such a machine, doing computations using double values is much more expensive because of the overhead required for software emulation. It is easy to accidentally do computations with double because floating-point literals are implicitly of type double. For example, in: float area(float radius) { return 3.14159 * radius * radius; } the compiler performs the entire computation with double because the floating-point literal is a double.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest