This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
uint64_t => float/double/long double
- To: gcc at gcc dot gnu dot org
- Subject: uint64_t => float/double/long double
- From: Frank Klemm <pfk at fuchs dot offl dot uni-jena dot de>
- Date: Fri, 5 Oct 2001 23:31:56 +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 XAA03864for gcc@gcc.gnu.org; Fri, 5 Oct 2001 23:31:56 +0200
C code:
----------------------------------------------------------
long double x;
unsigned long long y;
int main ( void )
{
x = y;
return 0;
}
----------------------------------------------------------
Generated code with:
gcc-3.0.2-20010917 -S -O4 -fomit-frame-pointer -mpreferred-stack-boundary=2 example.c
----------------------------------------------------------
.LC0: .long 0x0,0x80000000,0x403f
.text
.global main
.type main,@function
main:
movl y+4, %ecx
movl y, %eax
pushl %ecx
pushl %eax
fildll (%esp)
addl $8, %esp
testl %ecx, %ecx
js .L3
.L2: fstpt x
xorl %eax, %eax
ret
.L3:
fldt .LC0 <--------------
faddp %st, %st(1) <--------------
jmp .L2
----------------------------------------------------------
The last three lines can be changed to:
----------------------------------------------------------
fadds .LC1
jmp .L2
.LC1: .long 0x5f800000 ## (float) 2^64
----------------------------------------------------------
You do not need a long double to store the value of 2^64.
This change should be done very easily.
Who is responsible ???
===========================================================
Other optimizations are to add several constants to libm.so
and use these from this library. Such constants are:
(float) 2**64
(float) 0.5
(float) 2.
(float) 3.
(double) 1/3.
(long double) 1/3.L
(double) 2.*M_PI
(long double) 2.L*M_PIl
(double) 0.1
(long double) 0.1
(float) 10.
Several library functions also need these values.
If such values are in libm.so, you can use the following code:
----------------------------------------------------------
fadds __twopower64
jmp .L2
----------------------------------------------------------
--
Frank Klemm