This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

long double = unsigned long long


------------------------------------------ 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]