wgb@tntdev.tnt.com (William G. Bunton) (05/23/89)
Gcc-1.35 generates incorrect assembler code when subtracting an int
from a double. Configuration is:
Linked `config.h' to `config/xm-i386v.h'.
Linked `tm.h' to `config/tm-i386gas.h'.
Linked `md' to `config/i386.md'.
Linked `aux-output.c' to `config/out-i386.c'.
Links are now set up for use with a i386g.
OS is ISC 386/ix version 2.0.1 (sysVr3.2). Machine is ITT Xtra 386.
The following file prints -32101.000000, it should print 32101.000000:
main()
{
double dval;
int ival;
dval = 32467.0;
ival = 366;
dval -= (double)ival;
printf("value is %f\n", dval);
}
----------------------
ksh1 [424]$ gcc -v t.c
gcc version 1.35
/gnu/lib/gcc-cpp -v -undef -D__GNUC__ -Dunix -Di386 -D__unix__ -D__i386__ t.c /tmp/cca07742.cpp
GNU CPP version 1.35
/gnu/lib/gcc-cc1 /tmp/cca07742.cpp -quiet -dumpbase t.c -version -o /tmp/cca07742.s
GNU C version 1.35 (80386, BSD syntax) compiled by GNU C version 1.35.
/gnu/lib/gcc-as -o t.o /tmp/cca07742.s
/gnu/lib/gcc-ld /gnu/lib/crt0.o t.o /gnu/lib/gcc-gnulib -lc
ksh1 [425]$ a.out
value is -32101.000000
ksh1 [426]$ gcc -S t.c
ksh1 [427]$ cat t.s
.file "t.c"
gcc_compiled.:
.text
.align 2
LC0:
.double 0d3.24670000000000000000e+04
LC1:
.ascii "value is %f\12\0"
.align 2
.globl _main
_main:
pushl %ebp
movl %esp,%ebp
subl $12,%esp
pushl LC0
popl -8(%ebp)
pushl LC0+4
popl -4(%ebp)
movl $366,-12(%ebp)
fildl -12(%ebp) <========
fldl -8(%ebp) <========
fsubp %st,%st(1)
fstpl -8(%ebp)
pushl -4(%ebp)
pushl -8(%ebp)
pushl $LC1
call _printf
L1:
leave
ret
ksh1 [428]$
----------------------
The problem is with the marked lines. The load of the double should
occur before the load of the int.
Bill
--
William G. Bunton wgb@tntdev.tnt.com {uunet,natinst}!tntdev!wgb
Tools & Techniques, Inc. Austin, TX