On Friday, 5 August 2016 at 08:17:00 UTC, Ilya Yaroshenko wrote:
1. Could you please provide an assembler example with clang or recent gcc?

I have better: compile your favorite project with -Wdouble-promotion and enjoy the rain of warnings.

But try it yourself:

float foo(float a, float b) {
  return 3.0 * a / b;
}

GCC 5.3 gives me

foo(float, float):
        cvtss2sd        xmm0, xmm0
        cvtss2sd        xmm1, xmm1
        mulsd   xmm0, QWORD PTR .LC0[rip]
        divsd   xmm0, xmm1
        cvtsd2ss        xmm0, xmm0
        ret
.LC0:
        .long   0
        .long   1074266112

Which clearly uses double precision.

And clang 3.8:

LCPI0_0:
        .quad   4613937818241073152     # double 3
foo(float, float): # @foo(float, float)
        cvtss2sd        xmm0, xmm0
        mulsd   xmm0, qword ptr [rip + .LCPI0_0]
        cvtss2sd        xmm1, xmm1
        divsd   xmm0, xmm1
        cvtsd2ss        xmm0, xmm0
        ret

which uses double as well.

2. C compilers not promote double to 80-bit reals anyway.

VC++ does it on 32 bits build, but initialize the x87 unit to double precision (on 80 bits floats - yes that's a x87 setting).

VC++ will keep using float for x64 builds.

Intel compiler use compiler flags to promote or not.

In case you were wondering, this is not limited to X86/64 as GCC gives me on ARM:

foo(float, float):
        fmov    d2, 3.0e+0
        fcvt    d0, s0
        fmul    d0, d0, d2
        fcvt    d1, s1
        fdiv    d0, d0, d1
        fcvt    s0, d0
        ret

Which also promotes to double.

Reply via email to