This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
long double = unsigned long long
- To: gcc at gcc dot gnu dot org
- Subject: long double = unsigned long long
- From: Frank Klemm <pfk at fuchs dot offl dot uni-jena dot de>
- Date: Sun, 9 Sep 2001 05:08:10 +0200
- >Received: (from pfk@localhost)by fuchs.offl.uni-jena.de (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id FAA06415for gcc@gcc.gnu.org; Sun, 9 Sep 2001 05:08:10 +0200
------------------------------------------ C-code
unsigned long long x;
long double y;
main()
{
y = x;
}
------------------------------------------ -O2 -fomit-frame-pointer -march=athlon ....
.section .rodata
.align 16
.LC0:
.long 0x0,0x80000000,0x403f
.text
.align 16
.globl main
.type main,@function
main:
movl x+4, %edx
movl x, %eax <--- we never need this data in a CPU register
pushl %edx
pushl %eax <--- what's that?
fildll (%esp)
addl $8, %esp
testl %edx, %edx
js .L3
.L2:
fstpt y
ret
.p2align 4,,7
.L3:
fldt .LC0
faddp %st, %st(1)
jmp .L2
------------------------------------------ optimized
.section .rodata
.align 4
.LC0:
.long 0x5F800000
.text
.align 16
.globl main
.type main,@function
main:
testb $0x80, x+7 <--- there are still a lot of other possibilities to check (signed ll)x < 0
fildll x
jnz .L2
.L3: fstpt y
ret
.p2align 4,,7
.L2:
fadds .LC0 <--- a float can EXACTLY store a 2^64. This constant can also be a part of the libm. Then we need this value only one time for every huge program.
jmp .L3
------------------------------------------ without jump
.align 16
.globl main
.type main,@function
main:
movl x+4, %eax
addl %eax, %eax
fildll x
sbbl %eax, %eax <--- CY operations are slow, maybe mispredicted jumps are worse
andl $0x5F800000, %eax
push %eax
fadds (%esp)
addl $4, %esp
fstpt y
ret
-------------------------------------------- without jumps
Also possible with conditional fcmov + fadd
Interest ?
--
Frank Klemm