Emitting constants to the .data section from the NatM monad

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

On 06/12/12 00:29, Johan Tibell wrote:
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
?
Yes, you can emit data. Look at the LDATA instruction in the X86 backend, for example, and see how we generate things like table jumps. So are you going to add the two missing MachOps, MO_UF_Conv & MO_FU_Conv? Cheers, Simon

On Thu, Dec 6, 2012 at 1:34 PM, Simon Marlow
So are you going to add the two missing MachOps, MO_UF_Conv & MO_FU_Conv?
I'm trying to add those. I'm now thinking that I will use C calls (which is still much faster than going via Integer) instead of emitting some assembly, as the former is much easier but still allows us to do the latter later. The LLVM backend will use the dedicated LLVM instruction for conversions so it will generate really good code. -- Johan

On 06/12/12 22:11, Johan Tibell wrote:
On Thu, Dec 6, 2012 at 1:34 PM, Simon Marlow
wrote: So are you going to add the two missing MachOps, MO_UF_Conv & MO_FU_Conv?
I'm trying to add those. I'm now thinking that I will use C calls (which is still much faster than going via Integer) instead of emitting some assembly, as the former is much easier but still allows us to do the latter later. The LLVM backend will use the dedicated LLVM instruction for conversions so it will generate really good code.
Sounds reasonable. Cheers, Simon
participants (2)
-
Johan Tibell
-
Simon Marlow