diff options
author | John Ericson <git@JohnEricson.me> | 2019-06-03 23:47:10 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-01-07 00:11:31 -0500 |
commit | 06982b6cc886d65aa325475ddfb4ad38c69b2d96 (patch) | |
tree | a09811c44dd0e4fd774bc2de3fa10ea34f6409f4 /testsuite/tests/primops | |
parent | e981023eb1cfb2a0f6052763469252feee3e2d51 (diff) | |
download | haskell-06982b6cc886d65aa325475ddfb4ad38c69b2d96.tar.gz |
Make primops for `{Int,Word}32#`
Progress towards #19026.
The type was added before, but not its primops. We follow the
conventions in 36fcf9edee31513db2ddbf716ee0aa79766cbe69 and
2c959a1894311e59cd2fd469c1967491c1e488f3 for names and testing.
Along with the previous 8- and 16-bit primops, this will allow us to
avoid many conversions for 8-, 16-, and 32-bit sized numeric types.
Co-authored-by: Sylvain Henry <hsyl20@gmail.com>
Diffstat (limited to 'testsuite/tests/primops')
-rw-r--r-- | testsuite/tests/primops/should_run/ArithInt32.hs | 197 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithInt32.stdout | 8 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithWord32.hs | 194 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithWord32.stdout | 8 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpInt32.hs | 80 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpInt32.stdout | 6 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpWord32.hs | 80 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpWord32.stdout | 6 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ShowPrim.hs | 7 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ShowPrim.stdout | 1 |
10 files changed, 587 insertions, 0 deletions
diff --git a/testsuite/tests/primops/should_run/ArithInt32.hs b/testsuite/tests/primops/should_run/ArithInt32.hs new file mode 100644 index 0000000000..13b3bb026e --- /dev/null +++ b/testsuite/tests/primops/should_run/ArithInt32.hs @@ -0,0 +1,197 @@ +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} + +module Main where + +import Data.Int +import Data.List (findIndex) +import GHC.Prim +import GHC.Exts + +main :: IO () +main = do + + -- + -- Check if passing Int32# on the stack works (32 parameter function will + -- need to use stack for some of the them) + -- + let input = + [ ( (a + 0), (a + 1), (a + 2), (a + 3), + (a + 4), (a + 5), (a + 6), (a + 7), + (a + 8), (a + 9), (a + 10), (a + 11), + (a + 12), (a + 13), (a + 14), (a + 15) ) + | a <- allInt32 + ] + expected = + [ toInt32 + (a + b + c + d + e + f + g + h + + i + j + k + l + m + n + o + p) + | (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) <- input + ] + actual = + [ addMany a b c d e f g h i j k l m n o p + | (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) <- input + ] + checkResults "passing Int32# on the stack" input expected actual + + -- + -- negateInt32# + -- + let input = allInt32 + expected = [ toInt32 (negate a) | a <- input ] + actual = [ apply1 negateInt32# a | a <- input ] + checkResults "negateInt32#" input expected actual + + -- + -- plusInt32# + -- + let input = [ (a, b) | a <- allInt32, b <- allInt32 ] + expected = [ toInt32 (a + b) | (a, b) <- input ] + actual = [ apply2 plusInt32# a b | (a, b) <- input ] + checkResults "plusInt32#" input expected actual + + -- -- + -- -- subInt32# + -- -- + let input = [ (a, b) | a <- allInt32, b <- allInt32 ] + expected = [ toInt32 (a - b) | (a, b) <- input ] + actual = [ apply2 subInt32# a b | (a, b) <- input ] + checkResults "subInt32#" input expected actual + + -- + -- timesInt32# + -- + let input = [ (a, b) | a <- allInt32, b <- allInt32 ] + expected = [ toInt32 (a * b) | (a, b) <- input ] + actual = [ apply2 timesInt32# a b | (a, b) <- input ] + checkResults "timesInt32#" input expected actual + + -- + -- remInt32# + -- + let input = + [ (a, b) | a <- allInt32, b <- allInt32 + -- Don't divide by 0 or cause overflow + , b /= 0, not (a == -2147483648 && b == -1) + ] + expected = [ toInt32 (a `rem` b) | (a, b) <- input ] + actual = [ apply2 remInt32# a b | (a, b) <- input ] + checkResults "remInt32#" input expected actual + + -- + -- quotInt32# + -- + let input = + [ (a, b) | a <- allInt32, b <- allInt32 + , b /= 0, not (a == -2147483648 && b == -1) + ] + expected = [ toInt32 (a `quot` b) | (a, b) <- input ] + actual = [ apply2 quotInt32# a b | (a, b) <- input ] + checkResults "quotInt32#" input expected actual + + -- + -- quotRemInt32# + -- + let input = + [ (a, b) | a <- allInt32, b <- allInt32 + , b /= 0, not (a == -2147483648 && b == -1) + ] + expected = + [ (toInt32 q, toInt32 r) | (a, b) <- input + , let (q, r) = a `quotRem` b + ] + actual = [ apply3 quotRemInt32# a b | (a, b) <- input ] + checkResults "quotRemInt32#" input expected actual + + +checkResults + :: (Eq a, Eq b, Show a, Show b) => String -> [a] -> [b] -> [b] -> IO () +checkResults test inputs expected actual = + case findIndex (\(e, a) -> e /= a) (zip expected actual) of + Nothing -> putStrLn $ "Pass: " ++ test + Just i -> error $ + "FAILED: " ++ test ++ " for input: " ++ show (inputs !! i) + ++ " expected: " ++ show (expected !! i) + ++ " but got: " ++ show (actual !! i) + +-- testing across the entire Int32 range blows the memory, +-- hence choosing a smaller range +allInt32 :: [Int] +allInt32 = [ -50 .. 50 ] + +toInt32 :: Int -> Int +toInt32 a = fromIntegral (fromIntegral a :: Int32) + +addMany# + :: Int32# -> Int32# -> Int32# -> Int32# + -> Int32# -> Int32# -> Int32# -> Int32# + -> Int32# -> Int32# -> Int32# -> Int32# + -> Int32# -> Int32# -> Int32# -> Int32# + -> Int32# +addMany# a b c d e f g h i j k l m n o p = + a `plusInt32#` b `plusInt32#` c `plusInt32#` d `plusInt32#` + e `plusInt32#` f `plusInt32#` g `plusInt32#` h `plusInt32#` + i `plusInt32#` j `plusInt32#` k `plusInt32#` l `plusInt32#` + m `plusInt32#` n `plusInt32#` o `plusInt32#` p +{-# NOINLINE addMany# #-} + +addMany + :: Int -> Int -> Int -> Int + -> Int -> Int -> Int -> Int + -> Int -> Int -> Int -> Int + -> Int -> Int -> Int -> Int + -> Int +addMany (I# a) (I# b) (I# c) (I# d) + (I# e) (I# f) (I# g) (I# h) + (I# i) (I# j) (I# k) (I# l) + (I# m) (I# n) (I# o) (I# p) + = I# (extendInt32# int32) + where + !int32 = addMany# + (narrowInt32# a) (narrowInt32# b) (narrowInt32# c) (narrowInt32# d) + (narrowInt32# e) (narrowInt32# f) (narrowInt32# g) (narrowInt32# h) + (narrowInt32# i) (narrowInt32# j) (narrowInt32# k) (narrowInt32# l) + (narrowInt32# m) (narrowInt32# n) (narrowInt32# o) (narrowInt32# p) +{-# NOINLINE addMany #-} + +-- Convenient and also tests higher order functions on Int32# +apply1 :: (Int32# -> Int32#) -> Int -> Int +apply1 opToTest (I# a) = I# (extendInt32# (opToTest (narrowInt32# a))) +{-# NOINLINE apply1 #-} + +apply2 :: (Int32# -> Int32# -> Int32#) -> Int -> Int -> Int +apply2 opToTest (I# a) (I# b) = + let (# sa, sb #) = (# narrowInt32# a, narrowInt32# b #) + r = opToTest sa sb + in I# (extendInt32# r) +{-# NOINLINE apply2 #-} + +apply3 :: (Int32# -> Int32# -> (# Int32#, Int32# #)) -> Int -> Int -> (Int, Int) +apply3 opToTest (I# a) (I# b) = + let (# sa, sb #) = (# narrowInt32# a, narrowInt32# b #) + (# ra, rb #) = opToTest sa sb + in (I# (extendInt32# ra), I# (extendInt32# rb)) +{-# NOINLINE apply3 #-} + +instance + (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, + Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p) + => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) where + (a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1) == + (a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) = + a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2 && + e1 == e2 && f1 == f2 && g1 == g2 && h1 == h2 && + i1 == i2 && j1 == j2 && k1 == k2 && l1 == l2 && + m1 == m2 && n1 == n2 && o1 == o2 && p1 == p2 + +instance + (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, + Show i, Show j, Show k, Show l, Show m, Show n, Show o, Show p) + => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) where + show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + "(" ++ show a ++ "," ++ show b ++ "," ++ show c ++ "," ++ show d ++ + "," ++ show e ++ "," ++ show f ++ "," ++ show g ++ "," ++ show h ++ + "," ++ show i ++ "," ++ show j ++ "," ++ show k ++ "," ++ show l ++ + "," ++ show m ++ "," ++ show n ++ "," ++ show o ++ "," ++ show p ++ + ")" diff --git a/testsuite/tests/primops/should_run/ArithInt32.stdout b/testsuite/tests/primops/should_run/ArithInt32.stdout new file mode 100644 index 0000000000..7ce360bdab --- /dev/null +++ b/testsuite/tests/primops/should_run/ArithInt32.stdout @@ -0,0 +1,8 @@ +Pass: passing Int32# on the stack +Pass: negateInt32# +Pass: plusInt32# +Pass: subInt32# +Pass: timesInt32# +Pass: remInt32# +Pass: quotInt32# +Pass: quotRemInt32# diff --git a/testsuite/tests/primops/should_run/ArithWord32.hs b/testsuite/tests/primops/should_run/ArithWord32.hs new file mode 100644 index 0000000000..5756732ce0 --- /dev/null +++ b/testsuite/tests/primops/should_run/ArithWord32.hs @@ -0,0 +1,194 @@ +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} + +module Main where + +import Data.Word +import Data.Bits +import Data.List (findIndex) +import GHC.Prim +import GHC.Exts + +main :: IO () +main = do + + -- + -- Check if passing Word32# on the stack works (32 parameter function will + -- need to use stack for some of the them) + -- + let input = + [ ( (a + 0), (a + 1), (a + 2), (a + 3), + (a + 4), (a + 5), (a + 6), (a + 7), + (a + 8), (a + 9), (a + 10), (a + 11), + (a + 12), (a + 13), (a + 14), (a + 15) ) + | a <- allWord32 + ] + expected = + [ toWord32 + (a + b + c + d + e + f + g + h + + i + j + k + l + m + n + o + p) + | (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) <- input + ] + actual = + [ addMany a b c d e f g h i j k l m n o p + | (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) <- input + ] + checkResults "passing Word32# on the stack" input expected actual + + -- + -- notWord32# + -- + let input = allWord32 + expected = [ toWord32 (complement a) | a <- input ] + actual = [ apply1 notWord32# a | a <- input ] + checkResults "notWord32#" input expected actual + + -- + -- plusWord32# + -- + let input = [ (a, b) | a <- allWord32, b <- allWord32 ] + expected = [ toWord32 (a + b) | (a, b) <- input ] + actual = [ apply2 plusWord32# a b | (a, b) <- input ] + checkResults "plusWord32#" input expected actual + + -- + -- subWord32# + -- + let input = [ (a, b) | a <- allWord32, b <- allWord32 ] + expected = [ toWord32 (a - b) | (a, b) <- input ] + actual = [ apply2 subWord32# a b | (a, b) <- input ] + checkResults "subWord32#" input expected actual + + -- + -- timesWord32# + -- + let input = [ (a, b) | a <- allWord32, b <- allWord32 ] + expected = [ toWord32 (a * b) | (a, b) <- input ] + actual = [ apply2 timesWord32# a b | (a, b) <- input ] + checkResults "timesWord32#" input expected actual + + -- + -- remWord32# + -- + let input = + -- Don't divide by 0. + [ (a, b) | a <- allWord32, b <- allWord32 , b /= 0 ] + expected = [ toWord32 (a `rem` b) | (a, b) <- input ] + actual = [ apply2 remWord32# a b | (a, b) <- input ] + checkResults "remWord32#" input expected actual + + -- + -- quotWord32# + -- + let input = + [ (a, b) | a <- allWord32, b <- allWord32, b /= 0 ] + expected = [ toWord32 (a `quot` b) | (a, b) <- input ] + actual = [ apply2 quotWord32# a b | (a, b) <- input ] + checkResults "quotWord32#" input expected actual + + -- + -- quotRemWord32# + -- + let input = + [ (a, b) | a <- allWord32, b <- allWord32, b /= 0 ] + expected = + [ (toWord32 q, toWord32 r) | (a, b) <- input + , let (q, r) = a `quotRem` b + ] + actual = [ apply3 quotRemWord32# a b | (a, b) <- input ] + checkResults "quotRemWord32#" input expected actual + + +checkResults + :: (Eq a, Eq b, Show a, Show b) => String -> [a] -> [b] -> [b] -> IO () +checkResults test inputs expected actual = + case findIndex (\(e, a) -> e /= a) (zip expected actual) of + Nothing -> putStrLn $ "Pass: " ++ test + Just i -> error $ + "FAILED: " ++ test ++ " for input: " ++ show (inputs !! i) + ++ " expected: " ++ show (expected !! i) + ++ " but got: " ++ show (actual !! i) + +-- testing across the entire Word32 range blows the memory, +-- hence choosing a smaller range +allWord32 :: [Word] +allWord32 = [ 0 .. 100 ] + +toWord32 :: Word -> Word +toWord32 a = fromIntegral (fromIntegral a :: Word32) + +addMany# + :: Word32# -> Word32# -> Word32# -> Word32# + -> Word32# -> Word32# -> Word32# -> Word32# + -> Word32# -> Word32# -> Word32# -> Word32# + -> Word32# -> Word32# -> Word32# -> Word32# + -> Word32# +addMany# a b c d e f g h i j k l m n o p = + a `plusWord32#` b `plusWord32#` c `plusWord32#` d `plusWord32#` + e `plusWord32#` f `plusWord32#` g `plusWord32#` h `plusWord32#` + i `plusWord32#` j `plusWord32#` k `plusWord32#` l `plusWord32#` + m `plusWord32#` n `plusWord32#` o `plusWord32#` p +{-# NOINLINE addMany# #-} + +addMany + :: Word -> Word -> Word -> Word + -> Word -> Word -> Word -> Word + -> Word -> Word -> Word -> Word + -> Word -> Word -> Word -> Word + -> Word +addMany (W# a) (W# b) (W# c) (W# d) + (W# e) (W# f) (W# g) (W# h) + (W# i) (W# j) (W# k) (W# l) + (W# m) (W# n) (W# o) (W# p) + = W# (extendWord32# word32) + where + !word32 = + addMany# + (narrowWord32# a) (narrowWord32# b) (narrowWord32# c) (narrowWord32# d) + (narrowWord32# e) (narrowWord32# f) (narrowWord32# g) (narrowWord32# h) + (narrowWord32# i) (narrowWord32# j) (narrowWord32# k) (narrowWord32# l) + (narrowWord32# m) (narrowWord32# n) (narrowWord32# o) (narrowWord32# p) +{-# NOINLINE addMany #-} + +-- Convenient and also tests higher order functions on Word32# +apply1 :: (Word32# -> Word32#) -> Word -> Word +apply1 opToTest (W# a) = W# (extendWord32# (opToTest (narrowWord32# a))) +{-# NOINLINE apply1 #-} + +apply2 :: (Word32# -> Word32# -> Word32#) -> Word -> Word -> Word +apply2 opToTest (W# a) (W# b) = + let (# sa, sb #) = (# narrowWord32# a, narrowWord32# b #) + r = opToTest sa sb + in W# (extendWord32# r) +{-# NOINLINE apply2 #-} + +apply3 + :: (Word32# -> Word32# -> (# Word32#, Word32# #)) -> Word -> Word -> (Word, Word) +apply3 opToTest (W# a) (W# b) = + let (# sa, sb #) = (# narrowWord32# a, narrowWord32# b #) + (# ra, rb #) = opToTest sa sb + in (W# (extendWord32# ra), W# (extendWord32# rb)) +{-# NOINLINE apply3 #-} + +instance + (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, + Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o, Eq p) + => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) where + (a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1) == + (a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) = + a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2 && + e1 == e2 && f1 == f2 && g1 == g2 && h1 == h2 && + i1 == i2 && j1 == j2 && k1 == k2 && l1 == l2 && + m1 == m2 && n1 == n2 && o1 == o2 && p1 == p2 + +instance + (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, + Show i, Show j, Show k, Show l, Show m, Show n, Show o, Show p) + => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) where + show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + "(" ++ show a ++ "," ++ show b ++ "," ++ show c ++ "," ++ show d ++ + "," ++ show e ++ "," ++ show f ++ "," ++ show g ++ "," ++ show h ++ + "," ++ show i ++ "," ++ show j ++ "," ++ show k ++ "," ++ show l ++ + "," ++ show m ++ "," ++ show n ++ "," ++ show o ++ "," ++ show p ++ + ")" diff --git a/testsuite/tests/primops/should_run/ArithWord32.stdout b/testsuite/tests/primops/should_run/ArithWord32.stdout new file mode 100644 index 0000000000..cd05038fab --- /dev/null +++ b/testsuite/tests/primops/should_run/ArithWord32.stdout @@ -0,0 +1,8 @@ +Pass: passing Word32# on the stack +Pass: notWord32# +Pass: plusWord32# +Pass: subWord32# +Pass: timesWord32# +Pass: remWord32# +Pass: quotWord32# +Pass: quotRemWord32# diff --git a/testsuite/tests/primops/should_run/CmpInt32.hs b/testsuite/tests/primops/should_run/CmpInt32.hs new file mode 100644 index 0000000000..6f52ccecb1 --- /dev/null +++ b/testsuite/tests/primops/should_run/CmpInt32.hs @@ -0,0 +1,80 @@ +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE MagicHash #-} + +module Main where + +import Data.Int +import Data.List (findIndex) +import GHC.Prim +import GHC.Exts + + +-- Having a wrapper gives us two things: +-- * it's easier to test everything (no need for code using raw primops) +-- * we test the deriving mechanism for Int32# +data TestInt32 = T32 Int32# + deriving (Eq, Ord) + +mkT32 :: Int -> TestInt32 +mkT32 (I# a) = T32 (narrowInt32# a) + +main :: IO () +main = do + let input = [ (a, b) | a <- allInt32, b <- allInt32 ] + + -- + -- (==) + -- + let expected = [ a == b | (a, b) <- input ] + actual = [ mkT32 a == mkT32 b | (a, b) <- input ] + checkResults "(==)" input expected actual + + -- + -- (/=) + -- + let expected = [ a /= b | (a, b) <- input ] + actual = [ mkT32 a /= mkT32 b | (a, b) <- input ] + checkResults "(/=)" input expected actual + + -- + -- (<) + -- + let expected = [ a < b | (a, b) <- input ] + actual = [ mkT32 a < mkT32 b | (a, b) <- input ] + checkResults "(<)" input expected actual + + -- + -- (>) + -- + let expected = [ a > b | (a, b) <- input ] + actual = [ mkT32 a > mkT32 b | (a, b) <- input ] + checkResults "(>)" input expected actual + + -- + -- (<=) + -- + let expected = [ a <= b | (a, b) <- input ] + actual = [ mkT32 a <= mkT32 b | (a, b) <- input ] + checkResults "(<=)" input expected actual + + -- + -- (>=) + -- + let expected = [ a >= b | (a, b) <- input ] + actual = [ mkT32 a >= mkT32 b | (a, b) <- input ] + checkResults "(>=)" input expected actual + +checkResults + :: (Eq a, Eq b, Show a, Show b) => String -> [a] -> [b] -> [b] -> IO () +checkResults test inputs expected actual = + case findIndex (\(e, a) -> e /= a) (zip expected actual) of + Nothing -> putStrLn $ "Pass: " ++ test + Just i -> error $ + "FAILED: " ++ test ++ " for input: " ++ show (inputs !! i) + ++ " expected: " ++ show (expected !! i) + ++ " but got: " ++ show (actual !! i) + +-- testing across the entire Int32 range blows the memory, +-- hence choosing a smaller range +allInt32 :: [Int] +allInt32 = [ -50 .. 50 ] diff --git a/testsuite/tests/primops/should_run/CmpInt32.stdout b/testsuite/tests/primops/should_run/CmpInt32.stdout new file mode 100644 index 0000000000..191d2b4b26 --- /dev/null +++ b/testsuite/tests/primops/should_run/CmpInt32.stdout @@ -0,0 +1,6 @@ +Pass: (==) +Pass: (/=) +Pass: (<) +Pass: (>) +Pass: (<=) +Pass: (>=) diff --git a/testsuite/tests/primops/should_run/CmpWord32.hs b/testsuite/tests/primops/should_run/CmpWord32.hs new file mode 100644 index 0000000000..5e422aecab --- /dev/null +++ b/testsuite/tests/primops/should_run/CmpWord32.hs @@ -0,0 +1,80 @@ +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE MagicHash #-} + +module Main where + +import Data.Word +import Data.List (findIndex) +import GHC.Prim +import GHC.Exts + + +-- Having a wrapper gives us two things: +-- * it's easier to test everything (no need for code using raw primops) +-- * we test the deriving mechanism for Word32# +data TestWord32 = T32 Word32# + deriving (Eq, Ord) + +mkT32 :: Word -> TestWord32 +mkT32 (W# a) = T32 (narrowWord32# a) + +main :: IO () +main = do + let input = [ (a, b) | a <- allWord32, b <- allWord32 ] + + -- + -- (==) + -- + let expected = [ a == b | (a, b) <- input ] + actual = [ mkT32 a == mkT32 b | (a, b) <- input ] + checkResults "(==)" input expected actual + + -- + -- (/=) + -- + let expected = [ a /= b | (a, b) <- input ] + actual = [ mkT32 a /= mkT32 b | (a, b) <- input ] + checkResults "(/=)" input expected actual + + -- + -- (<) + -- + let expected = [ a < b | (a, b) <- input ] + actual = [ mkT32 a < mkT32 b | (a, b) <- input ] + checkResults "(<)" input expected actual + + -- + -- (>) + -- + let expected = [ a > b | (a, b) <- input ] + actual = [ mkT32 a > mkT32 b | (a, b) <- input ] + checkResults "(>)" input expected actual + + -- + -- (<=) + -- + let expected = [ a <= b | (a, b) <- input ] + actual = [ mkT32 a <= mkT32 b | (a, b) <- input ] + checkResults "(<=)" input expected actual + + -- + -- (>=) + -- + let expected = [ a >= b | (a, b) <- input ] + actual = [ mkT32 a >= mkT32 b | (a, b) <- input ] + checkResults "(>=)" input expected actual + +checkResults + :: (Eq a, Eq b, Show a, Show b) => String -> [a] -> [b] -> [b] -> IO () +checkResults test inputs expected actual = + case findIndex (\(e, a) -> e /= a) (zip expected actual) of + Nothing -> putStrLn $ "Pass: " ++ test + Just i -> error $ + "FAILED: " ++ test ++ " for input: " ++ show (inputs !! i) + ++ " expected: " ++ show (expected !! i) + ++ " but got: " ++ show (actual !! i) + +-- testing across the entire Word32 range blows the memory, +-- hence choosing a smaller range +allWord32 :: [Word] +allWord32 = [ 0 .. 100 ] diff --git a/testsuite/tests/primops/should_run/CmpWord32.stdout b/testsuite/tests/primops/should_run/CmpWord32.stdout new file mode 100644 index 0000000000..191d2b4b26 --- /dev/null +++ b/testsuite/tests/primops/should_run/CmpWord32.stdout @@ -0,0 +1,6 @@ +Pass: (==) +Pass: (/=) +Pass: (<) +Pass: (>) +Pass: (<=) +Pass: (>=) diff --git a/testsuite/tests/primops/should_run/ShowPrim.hs b/testsuite/tests/primops/should_run/ShowPrim.hs index e11a4934e6..ddeb661ec4 100644 --- a/testsuite/tests/primops/should_run/ShowPrim.hs +++ b/testsuite/tests/primops/should_run/ShowPrim.hs @@ -10,13 +10,20 @@ data Test1 = Test1 Int8# Word8# data Test2 = Test2 Int16# Word16# deriving (Show) +data Test3 = Test3 Int32# Word32# + deriving (Show) + test1 :: Test1 test1 = Test1 (narrowInt8# 1#) (narrowWord8# 2##) test2 :: Test2 test2 = Test2 (narrowInt16# 1#) (narrowWord16# 2##) +test3 :: Test3 +test3 = Test3 (narrowInt32# 1#) (narrowWord32# 2##) + main :: IO () main = do print test1 print test2 + print test3 diff --git a/testsuite/tests/primops/should_run/ShowPrim.stdout b/testsuite/tests/primops/should_run/ShowPrim.stdout index e2801b44fb..a5dc75f39d 100644 --- a/testsuite/tests/primops/should_run/ShowPrim.stdout +++ b/testsuite/tests/primops/should_run/ShowPrim.stdout @@ -1,2 +1,3 @@ Test1 (narrowInt8# 1#) (narrowWord8# 2##) Test2 (narrowInt16# 1#) (narrowWord16# 2##) +Test3 (narrowInt32# 1#) (narrowWord32# 2##) |