Eri*_*ikR 4 assembly haskell ghc
我想确定GHC为给定函数生成的汇编.
这里,例如,是一些代码(应该)在一个字中旋转位 - 它将位0移动到位12,位12到14,位14移回0,类似地移位位置1,18,13和6.
找到生成rot0cw的.S文件中生成的程序集的最佳方法是 ghc -O2 -S ...什么?
我已经阅读了这个答案,但是..._rot0cw_closure在程序集输出中我没有看到任何答案.
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')
Run Code Online (Sandbox Code Playgroud)
我已经阅读了这个答案,但是
..._rot0cw_closure在程序集输出中我没有看到任何答案.
您需要为模块命名.例如module Main where,在开头添加*以进入Main_rot0cw_closure生成的程序集.
*严格来说,您的模块需要导出该功能.