Finding a GHC assembly for a function

I would like to determine what assembly the GHC produces for this function.

Here, for example, there is some code that (should) rotate bits around a word - it moves bit 0 to bit 12, bits 12-14, bit 14 back to 0 and similarly for positions 1, 18, 13 and 6.

What is the best way to find the assembly generated for rot0cwin the file .Sbeing created ghc -O2 -S ...?

I read this answer , but I do not see any ..._rot0cw_closurein the assembly.

import Data.Bits
import Data.Int (Int64)
import Text.Printf
import System.Environment

{-# INLINE maskbits #-}
-- set in word v the bits of b corresponding to the mask m
-- assume a bit in b is zero if not in the mask
maskbits v m b = (v .&. (complement m) .|. b)

{-# INLINE tb #-}
-- transfer bit i of word v to bit j of word m; assume bit j of m is 0
tb v i j m =  m .|. (rotate  (v .&. (bit i)) (j-i))

rot0cw :: Int64 -> Int64
rot0cw v = maskbits (maskbits v m1 b1) m2 b2
  where
    m1 = 0x0000005005
    b1 = tb v 0 2 . tb v 2 14 . tb v 14 12 . tb v 12 0 $ 0
    m2 = 0x0000002142
    b2 = tb v 1 8 . tb v 8 13 . tb v 13 6 . tb v 6 1 $ 0

showBits v = 
  let set = [ i | i <- [0..35], testBit v i ]
  in "bits set: " ++ (unwords $ map show set)

main = do
  (arg0:_) <- getArgs
  let v = read arg0 
  -- let v = 0x0000000005
  let v' = rot0cw v
  putStrLn $ printf "v  = 0x%010x = %12d %s" v v (showBits v)
  putStrLn $ printf "v' = 0x%010x = %12d %s" v' v' (showBits v')
+4
source share
2 answers

I read this answer, but I do not see any ..._rot0cw_closurein the assembly.

. module Main where *, Main_rot0cw_closure .

* , .

+5

rot0cw , . - :

module Asm(rot0cw) where

, , , Cmm -ddump-cmm, proc, . , GHC , . , , rot0cw_closure :

     cB2:
         if (Sp - 32 < SpLim) goto cB4;
         Hp = Hp + 16;
         if (Hp > HpLim) goto cB6;
         I64[Sp - 16] = stg_upd_frame_info;
         I64[Sp - 8] = R1;
         I64[Hp - 8] = S#_con_info;
         I64[Hp + 0] = 0;
         I64[Sp - 24] = Hp - 7;
         I64[Sp - 32] = stg_ap_p_info;
         R2 = $fNumInt64_closure;
         Sp = Sp - 32;
         jump fromInteger_info; // [R2]
     cB4: jump stg_gc_enter_1; // [R1]
     cB6:
         HpAlloc = 16;
         goto cB4;

:

_cB2:
    leaq -32(%rbp),%rax
    cmpq %r15,%rax
    jb _cB4
    addq $16,%r12
    cmpq 144(%r13),%r12
    ja _cB6
    movq $stg_upd_frame_info,-16(%rbp)
    movq %rbx,-8(%rbp)
    movq $S#_con_info,-8(%r12)
    movq $0,0(%r12)
    leaq -7(%r12),%rax
    movq %rax,-24(%rbp)
    movq $stg_ap_p_info,-32(%rbp)
    movl $$fNumInt64_closure,%r14d
    addq $-32,%rbp
    jmp fromInteger_info
_cB6:
    movq $16,192(%r13)
_cB4:
    jmp *-16(%r13)
    .size sat_info, .-sat_info

"" GC , . Cmm, .

+4

All Articles