Follow changes in comparison primops (see #6135)
[ghc.git] / testsuite / tests / codeGen / should_run / cgrun066.hs
1 {-# LANGUAGE MagicHash, BangPatterns #-}
2
3 import Foreign.C
4 import Data.Word
5 import Foreign.Ptr
6 import GHC.Exts
7
8 import Control.Exception
9
10 hashStr :: Ptr Word8 -> Int -> Int
11 hashStr (Ptr a#) (I# len#) = loop 0# 0#
12 where
13 loop h n | isTrue# (n GHC.Exts.==# len#) = I# h
14 | otherwise = loop h2 (n GHC.Exts.+# 1#)
15 where !c = ord# (indexCharOffAddr# a# n)
16 !h2 = (c GHC.Exts.+# (h GHC.Exts.*# 128#)) `remInt#` 4091#
17
18 -- Infinite loops with new code generator + C-- optimizations
19 main = do
20 withCStringLen "ff" $ \(ptr, l) -> do
21 print (hashStr (castPtr ptr) l)