summaryrefslogtreecommitdiff
path: root/testsuite/tests/simplCore/should_run/simplrun007.hs
blob: 12bfb2d33532229ad435edf158fcd436d06d9766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE MagicHash #-}

-- Actually, this exercises prelude/PrelRules, but this is the closest
-- place I could find to put it...

import GHC.Exts
import Numeric
import Data.Bits

main = do phex (I# (uncheckedIShiftL#  (negateInt# 5#) 2#))
          phex (I# (uncheckedIShiftRA# (negateInt# 5#) 1#))
          phex (I# (uncheckedIShiftRL# (negateInt# 5#) 1#))
          phex (W# (uncheckedShiftL#   (int2Word# (negateInt# 5#)) 2#))
          phex (W# (uncheckedShiftRL#  (int2Word# (negateInt# 5#)) 1#))

phex x = putStrLn (showSigned (\x -> ("0x"++) . showHex x) 0 x "")

{- Too wordsize-dependant
phex x = putStrLn (hex x)
hex x = "0x" ++ [onedigit (fromIntegral ((x `shiftR` (i*4)) .&. 0xF))
                 | i <- [digits-1,digits-2..0]]
    where
    digits = bitSize x `div` 4
    onedigit n = "0123456789abcdef" !! n
-}