summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen
diff options
context:
space:
mode:
authorViktor Dukhovni <ietf-dane@dukhovni.org>2020-10-05 01:43:26 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-11-05 00:50:23 -0500
commit17d5c51834d64f1762320b7abaa40c5686564f4d (patch)
tree0b7c681aa2968eb8611890868f69e57dde89ffd7 /testsuite/tests/codeGen
parent81560981fd9af7ea21b2592c405e9e22af838aab (diff)
downloadhaskell-17d5c51834d64f1762320b7abaa40c5686564f4d.tar.gz
Naming, value types and tests for Addr# atomics
The atomic Exchange and CAS operations on integral types are updated to take and return more natural `Word#` rather than `Int#` values. These are bit-block not arithmetic operations, and the sign bit plays no special role. Standardises the names to `atomic<OpType><ValType>Addr#`, where `OpType` is one of `Cas` or `Exchange` and `ValType` is presently either `Word` or `Addr`. Eventually, variants for `Word32` and `Word64` can and should be added, once #11953 and related issues (e.g. #13825) are resolved. Adds tests for `Addr#` CAS that mirror existing tests for `MutableByteArray#`.
Diffstat (limited to 'testsuite/tests/codeGen')
-rw-r--r--testsuite/tests/codeGen/should_compile/cg011.hs6
-rw-r--r--testsuite/tests/codeGen/should_run/cas_int.hs22
-rw-r--r--testsuite/tests/codeGen/should_run/cgrun080.hs15
3 files changed, 21 insertions, 22 deletions
diff --git a/testsuite/tests/codeGen/should_compile/cg011.hs b/testsuite/tests/codeGen/should_compile/cg011.hs
index 5d86621784..09e5497d61 100644
--- a/testsuite/tests/codeGen/should_compile/cg011.hs
+++ b/testsuite/tests/codeGen/should_compile/cg011.hs
@@ -4,8 +4,8 @@
module M where
-import GHC.Exts (atomicExchangeInt#, Int#, Addr#, State# )
+import GHC.Exts (atomicExchangeWordAddr#, Word#, Addr#, State# )
-swap :: Addr# -> Int# -> State# s -> (# #)
-swap ptr val s = case (atomicExchangeInt# ptr val s) of
+swap :: Addr# -> Word# -> State# s -> (# #)
+swap ptr val s = case (atomicExchangeWordAddr# ptr val s) of
(# s2, old_val #) -> (# #)
diff --git a/testsuite/tests/codeGen/should_run/cas_int.hs b/testsuite/tests/codeGen/should_run/cas_int.hs
index e1d4905944..fc830c4d8a 100644
--- a/testsuite/tests/codeGen/should_run/cas_int.hs
+++ b/testsuite/tests/codeGen/should_run/cas_int.hs
@@ -26,16 +26,16 @@ import GHC.Ptr
#include "MachDeps.h"
main = do
- alloca $ \(ptr_p :: Ptr (Ptr Int)) -> do
- alloca $ \(ptr_i :: Ptr Int) -> do
- alloca $ \(ptr_j :: Ptr Int) -> do
- poke ptr_i (1 :: Int)
- poke ptr_j (2 :: Int)
+ alloca $ \(ptr_p :: Ptr (Ptr Word)) -> do
+ alloca $ \(ptr_i :: Ptr Word) -> do
+ alloca $ \(ptr_j :: Ptr Word) -> do
+ poke ptr_i (1 :: Word)
+ poke ptr_j (2 :: Word)
--expected to swap
- res_i <- cas ptr_i 1 3 :: IO Int
+ res_i <- cas ptr_i 1 3 :: IO Word
-- expected to fail
- res_j <- cas ptr_j 1 4 :: IO Int
+ res_j <- cas ptr_j 1 4 :: IO Word
putStrLn "Returned results:"
--(1,2)
@@ -48,7 +48,7 @@ main = do
--(3,2)
print (i,j)
-cas :: Ptr Int -> Int -> Int -> IO Int
-cas (Ptr ptr) (I# expected) (I# desired)= do
- IO $ \s -> case (atomicCasInt# ptr expected desired s) of
- (# s2, old_val #) -> (# s2, I# old_val #)
+cas :: Ptr Word -> Word -> Word -> IO Word
+cas (Ptr ptr) (W# expected) (W# desired)= do
+ IO $ \s -> case (atomicCasWordAddr# ptr expected desired s) of
+ (# s2, old_val #) -> (# s2, W# old_val #)
diff --git a/testsuite/tests/codeGen/should_run/cgrun080.hs b/testsuite/tests/codeGen/should_run/cgrun080.hs
index 4e09cd7634..78d54700f9 100644
--- a/testsuite/tests/codeGen/should_run/cgrun080.hs
+++ b/testsuite/tests/codeGen/should_run/cgrun080.hs
@@ -25,8 +25,8 @@ import GHC.Types
main = do
alloca $ \ptr_i -> do
- poke ptr_i (1 :: Int)
- w1 <- newEmptyMVar :: IO (MVar Int)
+ poke ptr_i (1 :: Word)
+ w1 <- newEmptyMVar :: IO (MVar Word)
forkIO $ do
v <- swapN 50000 2 ptr_i
putMVar w1 v
@@ -37,15 +37,14 @@ main = do
-- Should be [1,2,3]
print $ sort [v0,v1,v2]
-swapN :: Int -> Int -> Ptr Int -> IO Int
+swapN :: Word -> Word -> Ptr Word -> IO Word
swapN 0 val ptr = return val
swapN n val ptr = do
val' <- swap ptr val
swapN (n-1) val' ptr
-swap :: Ptr Int -> Int -> IO Int
-swap (Ptr ptr) (I# val) = do
- IO $ \s -> case (atomicExchangeInt# ptr val s) of
- (# s2, old_val #) -> (# s2, I# old_val #)
-
+swap :: Ptr Word -> Word -> IO Word
+swap (Ptr ptr) (W# val) = do
+ IO $ \s -> case (atomicExchangeWordAddr# ptr val s) of
+ (# s2, old_val #) -> (# s2, W# old_val #)