[BUG][GCC] *Serious* optimization bug: Any gcc specialistsout there?
Stephan Rudlof
sr at evolgo.de
Fri Aug 4 22:24:26 UTC 2000
David Chase wrote:
<snipped>
> If you compile with the "-S" flag, you can look at the
> generated assembly language, and maybe see what happened
> there.
Here it is:
sr at Klaus:~/tmp > cat testDoubles.c
#include <stdio.h>
#include <math.h>
testDoubles () {
double arg1 = 1.0e20;
printf("\nsin(arg1): %e", sin(arg1));
printf("\n");
}
int main() { testDoubles(); return 0; }
sr at Klaus:~/tmp > gcc -S testDoubles.c
(working, but with possibly wrong result -7.469219e-01)
sr at Klaus:~/tmp > less testDoubles.s
.file "testDoubles.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "\nsin(arg1): %e"
.LC1:
.string "\n"
.text
.align 16
.globl testDoubles
.type testDoubles, at function
testDoubles:
pushl %ebp
movl %esp,%ebp
subl $8,%esp
movl $2025163840,-8(%ebp)
movl $1142271773,-4(%ebp)
fldl -8(%ebp)
subl $8,%esp
fstpl (%esp)
call sin
addl $8,%esp
subl $8,%esp
fstpl (%esp)
pushl $.LC0
call printf
addl $12,%esp
pushl $.LC1
call printf
addl $4,%esp
.L1:
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size testDoubles,.Lfe1-testDoubles
.align 16
.globl main
.type main, at function
main:
pushl %ebp
movl %esp,%ebp
call testDoubles
xorl %eax,%eax
jmp .L2
.align 16
.L2:
movl %ebp,%esp
popl %ebp
ret
.Lfe2:
.size main,.Lfe2-main
.ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)"
sr at Klaus:~/tmp > gcc -O -S testDoubles.c
(not working, result == arg)
sr at Klaus:~/tmp > less testDoubles.s
.file "testDoubles.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC47:
.string "\nsin(arg1): %e"
.LC48:
.string "\n"
.align 8
.LC46:
.long 0x78b58c40,0x4415af1d
.text
.align 16
.globl testDoubles
.type testDoubles, at function
testDoubles:
pushl %ebp
movl %esp,%ebp
fldl .LC46
#APP
fsin
#NO_APP
subl $8,%esp
fstpl (%esp)
pushl $.LC47
call printf
pushl $.LC48
call printf
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size testDoubles,.Lfe1-testDoubles
.align 16
.globl main
.type main, at function
main:
pushl %ebp
movl %esp,%ebp
call testDoubles
xorl %eax,%eax
movl %ebp,%esp
popl %ebp
ret
.Lfe2:
.size main,.Lfe2-main
.ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)"
sr at Klaus:~/tmp > gcc -O -D__NO_MATH_INLINES -S testDoubles.c
(working, but with possibly wrong result -7.469219e-01)
sr at Klaus:~/tmp > less testDoubles.s
.file "testDoubles.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC1:
.string "\nsin(arg1): %e"
.LC2:
.string "\n"
.align 8
.LC0:
.long 0x78b58c40,0x4415af1d
.text
.align 16
.globl testDoubles
.type testDoubles, at function
testDoubles:
pushl %ebp
movl %esp,%ebp
pushl $1142271773
pushl $2025163840
call sin
subl $8,%esp
fstpl (%esp)
pushl $.LC1
call printf
pushl $.LC2
call printf
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size testDoubles,.Lfe1-testDoubles
.align 16
.globl main
.type main, at function
main:
pushl %ebp
movl %esp,%ebp
call testDoubles
xorl %eax,%eax
movl %ebp,%esp
popl %ebp
ret
.Lfe2:
.size main,.Lfe2-main
.ident "GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)"
Observation: 'Working' versions use
call sin
not working
fsin
.
Don't know how to interpret this (haven't hacked Intel assembler in my
life).
Greetings,
Stephan
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|