diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-10-20 11:39:16 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-11-06 07:53:42 -0400 |
commit | 20956e5784fe43781d156dd7ab02f0bff4ab41fb (patch) | |
tree | de4776b5223cc3e6c983bd4eec28cbef4f973a8f /testsuite | |
parent | 646c3e21dd30a2eaae46aafb8678d29f8e06054d (diff) | |
download | haskell-20956e5784fe43781d156dd7ab02f0bff4ab41fb.tar.gz |
Remove target dependent CPP for Word64/Int64 (#11470)
Primops types were dependent on the target word-size at *compiler*
compilation time. It's an issue for multi-target as GHC may not have the
correct primops types for the target.
This patch fixes some primops types: if they take or return fixed 64-bit
values they now always use `Int64#/Word64#`, even on 64-bit
architectures (where they used `Int#/Word#` before). Users of these
primops may now need to convert from Int64#/Word64# to Int#/Word# (a
no-op at runtime).
This is a stripped down version of !3658 which goes the all way of
changing the underlying primitive types of Word64/Int64. This is left
for future work.
T12545 allocations increase ~4% on some CI platforms and decrease ~3% on
AArch64.
Metric Increase:
T12545
Metric Decrease:
T12545
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/codeGen/should_run/T9340.hs | 8 | ||||
-rw-r--r-- | testsuite/tests/codeGen/should_run/cgrun072.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/codeGen/should_run/cgrun075.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/codeGen/should_run/cgrun076.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/concurrent/should_run/AtomicPrimops.hs | 17 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/T4442.hs | 16 |
6 files changed, 53 insertions, 0 deletions
diff --git a/testsuite/tests/codeGen/should_run/T9340.hs b/testsuite/tests/codeGen/should_run/T9340.hs index 45f791ba73..22f5824115 100644 --- a/testsuite/tests/codeGen/should_run/T9340.hs +++ b/testsuite/tests/codeGen/should_run/T9340.hs @@ -1,4 +1,5 @@ {-# LANGUAGE MagicHash #-} +{-# LANGUAGE CPP #-} import Control.Monad import Data.Bits @@ -6,6 +7,8 @@ import GHC.Exts import GHC.Word import Numeric (showHex) +#include "MachDeps.h" + -- Reference Implementation -- count trailing zeros @@ -58,8 +61,13 @@ ctzIUT32 (W# x#) = W# (ctz32# x#) clzIUT32 (W# x#) = W# (clz32# x#) ctzIUT64, clzIUT64 :: Word64 -> Word +#if WORD_SIZE_IN_BITS < 64 ctzIUT64 (W64# x#) = W# (ctz64# x#) clzIUT64 (W64# x#) = W# (clz64# x#) +#else +ctzIUT64 (W64# x#) = W# (ctz64# (wordToWord64# x#)) +clzIUT64 (W64# x#) = W# (clz64# (wordToWord64# x#)) +#endif main :: IO () main = do diff --git a/testsuite/tests/codeGen/should_run/cgrun072.hs b/testsuite/tests/codeGen/should_run/cgrun072.hs index b97ce56d01..729564b631 100644 --- a/testsuite/tests/codeGen/should_run/cgrun072.hs +++ b/testsuite/tests/codeGen/should_run/cgrun072.hs @@ -37,7 +37,11 @@ bswap32 :: Word32 -> Word32 bswap32 (W32# w#) = W32# (wordToWord32# (byteSwap32# (word32ToWord# w#))) bswap64 :: Word64 -> Word64 +#if WORD_SIZE_IN_BITS < 64 bswap64 (W64# w#) = W64# (byteSwap64# w#) +#else +bswap64 (W64# w#) = W64# (word64ToWord# (byteSwap64# (wordToWord64# w#))) +#endif slowBswap64 :: Word64 -> Word64 slowBswap64 w = diff --git a/testsuite/tests/codeGen/should_run/cgrun075.hs b/testsuite/tests/codeGen/should_run/cgrun075.hs index 5babde1254..1cac98b2dd 100644 --- a/testsuite/tests/codeGen/should_run/cgrun075.hs +++ b/testsuite/tests/codeGen/should_run/cgrun075.hs @@ -36,7 +36,11 @@ instance Pdep Word32 where pdep (W32# src#) (W32# mask#) = W32# (wordToWord32# (pdep32# (word32ToWord# src#) (word32ToWord# mask#))) instance Pdep Word64 where +#if WORD_SIZE_IN_BITS < 64 pdep (W64# src#) (W64# mask#) = W64# (pdep64# src# mask#) +#else + pdep (W64# src#) (W64# mask#) = W64# (word64ToWord# (pdep64# (wordToWord64# src#) (wordToWord64# mask#))) +#endif class SlowPdep a where slowPdep :: a -> a -> a diff --git a/testsuite/tests/codeGen/should_run/cgrun076.hs b/testsuite/tests/codeGen/should_run/cgrun076.hs index 4779b5beb8..ce26e375d0 100644 --- a/testsuite/tests/codeGen/should_run/cgrun076.hs +++ b/testsuite/tests/codeGen/should_run/cgrun076.hs @@ -36,7 +36,11 @@ instance Pext Word32 where pext (W32# src#) (W32# mask#) = W32# (wordToWord32# (pext32# (word32ToWord# src#) (word32ToWord# mask#))) instance Pext Word64 where +#if WORD_SIZE_IN_BITS < 64 pext (W64# src#) (W64# mask#) = W64# (pext64# src# mask#) +#else + pext (W64# src#) (W64# mask#) = W64# (word64ToWord# (pext64# (wordToWord64# src#) (wordToWord64# mask#))) +#endif class SlowPext a where slowPext :: a -> a -> a diff --git a/testsuite/tests/concurrent/should_run/AtomicPrimops.hs b/testsuite/tests/concurrent/should_run/AtomicPrimops.hs index b8adb3c621..05ac80dcad 100644 --- a/testsuite/tests/concurrent/should_run/AtomicPrimops.hs +++ b/testsuite/tests/concurrent/should_run/AtomicPrimops.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} @@ -14,6 +15,8 @@ import GHC.Int import GHC.IO import GHC.Word +#include "MachDeps.h" + -- | Iterations per worker. iters :: Word iters = 1000000 @@ -550,7 +553,11 @@ readInt32Array (MBA mba#) (I# ix#) = IO $ \ s# -> readInt64Array :: MByteArray -> Int -> IO Int64 readInt64Array (MBA mba#) (I# ix#) = IO $ \ s# -> case readInt64Array# mba# ix# s# of +#if WORD_SIZE_IN_BITS < 64 (# s2#, n# #) -> (# s2#, I64# n# #) +#else + (# s2#, n# #) -> (# s2#, I64# (int64ToInt# n#) #) +#endif atomicWriteIntArray :: MByteArray -> Int -> Int -> IO () atomicWriteIntArray (MBA mba#) (I# ix#) (I# n#) = IO $ \ s# -> @@ -584,8 +591,13 @@ casInt32Array (MBA mba#) (I# ix#) (I32# old#) (I32# new#) = IO $ \ s# -> casInt64Array :: MByteArray -> Int -> Int64 -> Int64 -> IO Int64 casInt64Array (MBA mba#) (I# ix#) (I64# old#) (I64# new#) = IO $ \ s# -> +#if WORD_SIZE_IN_BITS < 64 case casInt64Array# mba# ix# old# new# s# of (# s2#, old2# #) -> (# s2#, I64# old2# #) +#else + case casInt64Array# mba# ix# (intToInt64# old#) (intToInt64# new#) s# of + (# s2#, old2# #) -> (# s2#, I64# (int64ToInt# old2#) #) +#endif ------------------------------------------------------------------------ -- Wrappers around Addr# @@ -651,5 +663,10 @@ atomicCasWord32Ptr (Ptr addr#) (W32# old#) (W32# new#) = IO $ \ s# -> (# s2#, old2# #) -> (# s2#, W32# old2# #) atomicCasWord64Ptr :: Ptr Word64 -> Word64 -> Word64 -> IO Word64 atomicCasWord64Ptr (Ptr addr#) (W64# old#) (W64# new#) = IO $ \ s# -> +#if WORD_SIZE_IN_BITS < 64 case atomicCasWord64Addr# addr# old# new# s# of (# s2#, old2# #) -> (# s2#, W64# old2# #) +#else + case atomicCasWord64Addr# addr# (wordToWord64# old#) (wordToWord64# new#) s# of + (# s2#, old2# #) -> (# s2#, W64# (word64ToWord# old2#) #) +#endif diff --git a/testsuite/tests/primops/should_run/T4442.hs b/testsuite/tests/primops/should_run/T4442.hs index dfdf93cc4f..ad0c882533 100644 --- a/testsuite/tests/primops/should_run/T4442.hs +++ b/testsuite/tests/primops/should_run/T4442.hs @@ -222,11 +222,19 @@ main = do (\arr i s -> case readWord8ArrayAsInt32# arr i s of (# s', a #) -> (# s', I32# a #)) (\arr i (I32# a) s -> writeWord8ArrayAsInt32# arr i a s) 12345678 4 +#if WORD_SIZE_IN_BITS < 64 testInt64Array "Int64#" (\arr i -> I64# (indexWord8ArrayAsInt64# arr i)) (\arr i s -> case readWord8ArrayAsInt64# arr i s of (# s', a #) -> (# s', I64# a #)) (\arr i (I64# a) s -> writeWord8ArrayAsInt64# arr i a s) 1234567890123 8 +#else + testInt64Array "Int64#" + (\arr i -> I64# (int64ToInt# (indexWord8ArrayAsInt64# arr i))) + (\arr i s -> case readWord8ArrayAsInt64# arr i s of (# s', a #) -> (# s', I64# (int64ToInt# a) #)) + (\arr i (I64# a) s -> writeWord8ArrayAsInt64# arr i (intToInt64# a) s) + 1234567890123 8 +#endif testIntArray "Int#" (\arr i -> I# (indexWord8ArrayAsInt# arr i)) (\arr i s -> case readWord8ArrayAsInt# arr i s of (# s', a #) -> (# s', I# a #)) @@ -248,11 +256,19 @@ main = do (\arr i s -> case readWord8ArrayAsWord32# arr i s of (# s', a #) -> (# s', W32# a #)) (\arr i (W32# a) s -> writeWord8ArrayAsWord32# arr i a s) 12345678 4 +#if WORD_SIZE_IN_BITS < 64 testWord64Array "Word64#" (\arr i -> W64# (indexWord8ArrayAsWord64# arr i)) (\arr i s -> case readWord8ArrayAsWord64# arr i s of (# s', a #) -> (# s', W64# a #)) (\arr i (W64# a) s -> writeWord8ArrayAsWord64# arr i a s) 1234567890123 8 +#else + testWord64Array "Word64#" + (\arr i -> W64# (word64ToWord# (indexWord8ArrayAsWord64# arr i))) + (\arr i s -> case readWord8ArrayAsWord64# arr i s of (# s', a #) -> (# s', W64# (word64ToWord# a) #)) + (\arr i (W64# a) s -> writeWord8ArrayAsWord64# arr i (wordToWord64# a) s) + 1234567890123 8 +#endif testWordArray "Word#" (\arr i -> W# (indexWord8ArrayAsWord# arr i)) (\arr i s -> case readWord8ArrayAsWord# arr i s of (# s', a #) -> (# s', W# a #)) |