Emitting constants to the .data section from the NatM monad
Johan Tibell
johan.tibell at gmail.com
Thu Dec 6 01:29:16 CET 2012
Hi!
I'm trying to implement word2Double# and I've looked at how e.g. LLVM
does it. LLVM outputs quite clever branchless code that uses two
predefined constants in the .data section. Is it possible to add
contents to the current .data section from a function in the NatM
monad e.g.
coerceWord2FP :: Width -> Width -> CmmExpr -> NatM Register
?
Cheers,
Johan
P.S. Given this C code
double f(unsigned long long u) { return u; }
LLVM generates this rather clever code:
.section __TEXT,__text,regular,pure_instructions
.section __TEXT,__literal8,8byte_literals
.align 3
LCPI1_0:
.long 1602224128 // constant we'd like to ouput
.long 0 // constant we'd like to ouput
.section __TEXT,__text,regular,pure_instructions
.globl _f
.align 4, 0x90
_f:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl 8(%ebp), %eax
movl 12(%ebp), %ecx
movl %ecx, -4(%ebp)
movl %eax, -8(%ebp)
testl %ecx, %ecx // check sign
sets %al // check sign
xorb $1, %al // check sign
movzbl %al, %eax // 0 if signed
fildll -8(%ebp) // load integer
fadds LCPI1_0(,%eax,4) // add one of two constants
fstpl -16(%ebp) // store and pop
fldl -16(%ebp)
addl $16, %esp
popl %ebp
ret
More information about the Glasgow-haskell-users
mailing list