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 On Fri, Apr 29, 2016 at 6:30 PM, Ola Røer Thorsen <o...@silentwings.no> wrote: > > > 2016-04-29 16:36 GMT+02:00 Jean-Michaël Celerier < > jeanmichael.celer...@gmail.com>: > >> >> On Fri, Apr 29, 2016 at 1:55 PM, Ola Røer Thorsen <o...@silentwings.no> >> wrote: >> >>> >>> float a = 1.0f; >>> float b = 2.0*a; // BAD! >>> float b = 2.0f*a; // Good! >>> >> >> Pretty sure that this would be a non-problem starting at -O1 optimization >> level. >> > > Well you're wrong. If you multiply with a double precision constant value > (2.0), the multiplication is done in double precision and the result is > then converted to single precision, regardless of the optimize level. This > makes a big difference on hardware that only support single-precision in > hardware (I know this from experience, not assumptions). > > > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest