summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Storable.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-10-20 11:39:16 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-06 07:53:42 -0400
commit20956e5784fe43781d156dd7ab02f0bff4ab41fb (patch)
treede4776b5223cc3e6c983bd4eec28cbef4f973a8f /libraries/base/GHC/Storable.hs
parent646c3e21dd30a2eaae46aafb8678d29f8e06054d (diff)
downloadhaskell-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 'libraries/base/GHC/Storable.hs')
-rw-r--r--libraries/base/GHC/Storable.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/libraries/base/GHC/Storable.hs b/libraries/base/GHC/Storable.hs
index d9b9382211..548430eb59 100644
--- a/libraries/base/GHC/Storable.hs
+++ b/libraries/base/GHC/Storable.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK not-home #-}
@@ -51,6 +52,8 @@ module GHC.Storable
, writeWord64OffPtr
) where
+#include "MachDeps.h"
+
import GHC.Stable ( StablePtr(..) )
import GHC.Int
import GHC.Word
@@ -102,10 +105,17 @@ readInt32OffPtr (Ptr a) (I# i)
= IO $ \s -> case readInt32OffAddr# a i s of (# s2, x #) -> (# s2, I32# x #)
readWord32OffPtr (Ptr a) (I# i)
= IO $ \s -> case readWord32OffAddr# a i s of (# s2, x #) -> (# s2, W32# x #)
+#if WORD_SIZE_IN_BITS < 64
readInt64OffPtr (Ptr a) (I# i)
= IO $ \s -> case readInt64OffAddr# a i s of (# s2, x #) -> (# s2, I64# x #)
readWord64OffPtr (Ptr a) (I# i)
= IO $ \s -> case readWord64OffAddr# a i s of (# s2, x #) -> (# s2, W64# x #)
+#else
+readInt64OffPtr (Ptr a) (I# i)
+ = IO $ \s -> case readInt64OffAddr# a i s of (# s2, x #) -> (# s2, I64# (int64ToInt# x) #)
+readWord64OffPtr (Ptr a) (I# i)
+ = IO $ \s -> case readWord64OffAddr# a i s of (# s2, x #) -> (# s2, W64# (word64ToWord# x) #)
+#endif
writeWideCharOffPtr :: Ptr Char -> Int -> Char -> IO ()
writeIntOffPtr :: Ptr Int -> Int -> Int -> IO ()
@@ -152,7 +162,14 @@ writeInt32OffPtr (Ptr a) (I# i) (I32# x)
= IO $ \s -> case writeInt32OffAddr# a i x s of s2 -> (# s2, () #)
writeWord32OffPtr (Ptr a) (I# i) (W32# x)
= IO $ \s -> case writeWord32OffAddr# a i x s of s2 -> (# s2, () #)
+#if WORD_SIZE_IN_BITS < 64
writeInt64OffPtr (Ptr a) (I# i) (I64# x)
= IO $ \s -> case writeInt64OffAddr# a i x s of s2 -> (# s2, () #)
writeWord64OffPtr (Ptr a) (I# i) (W64# x)
= IO $ \s -> case writeWord64OffAddr# a i x s of s2 -> (# s2, () #)
+#else
+writeInt64OffPtr (Ptr a) (I# i) (I64# x)
+ = IO $ \s -> case writeInt64OffAddr# a i (intToInt64# x) s of s2 -> (# s2, () #)
+writeWord64OffPtr (Ptr a) (I# i) (W64# x)
+ = IO $ \s -> case writeWord64OffAddr# a i (wordToWord64# x) s of s2 -> (# s2, () #)
+#endif