floating point

Matthew Fluet mfluet@intertrust.com
Mon, 13 Aug 2001 14:24:20 -0700 (PDT)


> The flag could be processor specific, but then I would expect it to inline
> the instruction no matter what.  In the cos case, it only inlined it with
> -ffast-math, and otherwise did a full function call.

I guess the gcc info pages are inconsistent.  I remember when I was
implementing the floating-point for the codegen, I would write the
function in C, compile it with -O2 under gcc, look at the assembly and use
that.

Here's what I've got for sqrt:

[mfluet@vinous tests]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
[mfluet@vinous tests]$ cat asm.c
#include <math.h>

double Real_sqrt(double x) {return sqrt(x);}

int main(int argc, char* argv[]) {

  printf("%f\n", Real_sqrt(-5.0));
  return 1;
}
[mfluet@vinous tests]$ gcc -S -O2 asm.c
[mfluet@vinous tests]$ cat asm.s
        .file   "asm.c"
        .version        "01.01"
gcc2_compiled.:
.text
        .align 4
.globl Real_sqrt
        .type    Real_sqrt,@function
Real_sqrt:
        pushl   %ebp
        movl    %esp, %ebp
        fldl    8(%ebp)
#APP
        fsqrt
#NO_APP
        popl    %ebp
        ret
.Lfe1:
        .size    Real_sqrt,.Lfe1-Real_sqrt
                .section        .rodata
.LC35:
        .string "%f\n"
.text
        .align 4
.globl main
        .type    main,@function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        pushl   $-1072431104
        pushl   $0
        call    Real_sqrt
        popl    %eax
        fstpl   (%esp)
        pushl   $.LC35
        call    printf
        movl    $1, %eax
        leave
        ret
.Lfe2:
        .size    main,.Lfe2-main
        .ident  "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-81)"
[mfluet@vinous tests]$ gcc -lm asm.s
[mfluet@vinous tests]$ ./a.out
nan


With -ffast-math (but no -O2), I still get a call to sqrt.