Johan Tibell | 6 Dec 01:29 2012
Picon

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
(Continue reading)

Simon Marlow | 6 Dec 22:34 2012
Picon

Re: Emitting constants to the .data section from the NatM monad

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
Johan Tibell | 6 Dec 23:11 2012
Picon

Re: Emitting constants to the .data section from the NatM monad

On Thu, Dec 6, 2012 at 1:34 PM, Simon Marlow <marlowsd <at> gmail.com> 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.

-- Johan
Simon Marlow | 7 Dec 13:25 2012
Picon

Re: Emitting constants to the .data section from the NatM monad

On 06/12/12 22:11, Johan Tibell wrote:
> On Thu, Dec 6, 2012 at 1:34 PM, Simon Marlow <marlowsd <at> gmail.com> 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

Gmane