summaryrefslogtreecommitdiff
path: root/testsuite/tests/primops
diff options
context:
space:
mode:
authorMichal Terepeta <michal.terepeta@gmail.com>2015-08-03 08:41:13 +0200
committerBen Gamari <ben@smart-cactus.org>2015-08-03 08:41:32 +0200
commit92f5385d8b2be50848a2496199a481f299f4b53a (patch)
treee335893d9ff65b3df9f34dd5191b7a785eeeabfb /testsuite/tests/primops
parent37227d3400549c2a6844dfb8c34c0738edc69ecc (diff)
downloadhaskell-92f5385d8b2be50848a2496199a481f299f4b53a.tar.gz
Support MO_U_QuotRem2 in LLVM backend
This adds support for MO_U_QuotRem2 in LLVM backend. Similarly to MO_U_Mul2 we use the standard LLVM instructions (in this case 'udiv' and 'urem') but do the computation on double the word width (e.g., for 64-bit we will do them on 128 registers). Test Plan: validate Reviewers: rwbarton, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1100 GHC Trac Issues: #9430
Diffstat (limited to 'testsuite/tests/primops')
-rw-r--r--testsuite/tests/primops/should_run/T9430.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/testsuite/tests/primops/should_run/T9430.hs b/testsuite/tests/primops/should_run/T9430.hs
index aec2d264a1..eedc0a754b 100644
--- a/testsuite/tests/primops/should_run/T9430.hs
+++ b/testsuite/tests/primops/should_run/T9430.hs
@@ -34,6 +34,23 @@ checkW (expX, expY) op (W# a) (W# b) =
"Expected " ++ show expX ++ " and " ++ show expY
++ " but got " ++ show (W# x) ++ " and " ++ show (W# y)
+checkW2
+ :: (Word, Word) -- ^ expected results
+ -> (Word# -> Word# -> Word# -> (# Word#, Word# #))
+ -- ^ primop
+ -> Word -- ^ first argument
+ -> Word -- ^ second argument
+ -> Word -- ^ third argument
+ -> Maybe String -- ^ maybe error
+checkW2 (expX, expY) op (W# a) (W# b) (W# c) =
+ case op a b c of
+ (# x, y #)
+ | W# x == expX && W# y == expY -> Nothing
+ | otherwise ->
+ Just $
+ "Expected " ++ show expX ++ " and " ++ show expY
+ ++ " but got " ++ show (W# x) ++ " and " ++ show (W# y)
+
check :: String -> Maybe String -> IO ()
check s (Just err) = error $ "Error for " ++ s ++ ": " ++ err
check _ Nothing = return ()
@@ -91,3 +108,21 @@ main = do
checkW (2, maxBound - 2) timesWord2# maxBound 3
check "timesWord2# 3 maxBound" $
checkW (2, maxBound - 2) timesWord2# 3 maxBound
+
+ check "quotRemWord2# 0 0 1" $ checkW2 (0, 0) quotRemWord2# 0 0 1
+ check "quotRemWord2# 0 4 2" $ checkW2 (2, 0) quotRemWord2# 0 4 2
+ check "quotRemWord2# 0 7 3" $ checkW2 (2, 1) quotRemWord2# 0 7 3
+ check "quotRemWord2# 1 0 (2 ^ 63)" $
+ checkW2 (2, 0) quotRemWord2# 1 0 (2 ^ 63)
+ check "quotRemWord2# 1 1 (2 ^ 63)" $
+ checkW2 (2, 1) quotRemWord2# 1 1 (2 ^ 63)
+ check "quotRemWord2# 1 0 maxBound" $
+ checkW2 (1, 1) quotRemWord2# 1 0 maxBound
+ check "quotRemWord2# 2 0 maxBound" $
+ checkW2 (2, 2) quotRemWord2# 2 0 maxBound
+ check "quotRemWord2# 1 maxBound maxBound" $
+ checkW2 (2, 1) quotRemWord2# 1 maxBound maxBound
+ check "quotRemWord2# (2 ^ 63) 0 maxBound" $
+ checkW2 (2 ^ 63, 2 ^ 63) quotRemWord2# (2 ^ 63) 0 maxBound
+ check "quotRemWord2# (2 ^ 63) maxBound maxBound" $
+ checkW2 (2 ^ 63 + 1, 2 ^ 63) quotRemWord2# (2 ^ 63) maxBound maxBound