On sábado, 30 de abril de 2016 10:46:21 PDT Jean-Michaël Celerier wrote: > 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
Because 2 can be represented with no loss of precision in both single- and double-precision floating point. The compiler actually produced an "as-if" optimisation here. Try multiplying by something different, something that isn't precise, like 2.1. f: cvtss2sd %xmm0, %xmm0 mulsd .LC0(%rip), %xmm0 cvtsd2ss %xmm0, %xmm0 ret https://godbolt.org/g/4yEj4Y -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest