, sizeofInt32
, sizeofInt64
-#ifndef __PARALLEL_HASKELL__
-- The "official" place to get these from is Foreign
+#ifndef __PARALLEL_HASKELL__
, indexInt8OffForeignObj
, indexInt16OffForeignObj
, indexInt32OffForeignObj
, indexInt64OffForeignObj
+
, readInt8OffForeignObj
, readInt16OffForeignObj
, readInt32OffForeignObj
, readInt64OffForeignObj
+
, writeInt8OffForeignObj
, writeInt16OffForeignObj
, writeInt32OffForeignObj
#endif
#ifndef __PARALLEL_HASKELL__
+
indexInt8OffForeignObj :: ForeignObj -> Int -> Int8
indexInt8OffForeignObj (ForeignObj fo#) (I# i#) = intToInt8 (I# (ord# (indexCharOffForeignObj# fo# i#)))
indexInt16OffForeignObj :: ForeignObj -> Int -> Int16
indexInt16OffForeignObj fo i =
-#ifdef WORDS_BIGENDIAN
+# ifdef WORDS_BIGENDIAN
intToInt16 ( int8ToInt l + (int8ToInt maxBound) * int8ToInt h)
-#else
+# else
intToInt16 ( int8ToInt h + (int8ToInt maxBound) * int8ToInt l)
-#endif
+# endif
where
byte_idx = i * 2
l = indexInt8OffForeignObj fo byte_idx
where
-- adjust index to be in Int units, not Int32 ones.
(I# i'#)
-#if WORD_SIZE_IN_BYTES==8
+# if WORD_SIZE_IN_BYTES==8
= i `div` 2
-#else
+# else
= i
-#endif
+# endif
indexInt64OffForeignObj :: ForeignObj -> Int -> Int64
indexInt64OffForeignObj (ForeignObj fo#) (I# i#)
-#if WORD_SIZE_IN_BYTES==8
+# if WORD_SIZE_IN_BYTES==8
= I64# (indexIntOffForeignObj# fo# i#)
-#else
+# else
= I64# (indexInt64OffForeignObj# fo# i#)
-#endif
+# endif
#endif /* __PARALLEL_HASKELL__ */
\end{code}
#endif
#ifndef __PARALLEL_HASKELL__
+
readInt8OffForeignObj :: ForeignObj -> Int -> IO Int8
readInt8OffForeignObj fo i = _casm_ `` %r=(StgInt8)(((StgInt8*)%0)[(StgInt)%1]); '' fo i
readInt32OffForeignObj fo i = _casm_ `` %r=(StgInt32)(((StgInt32*)%0)[(StgInt)%1]); '' fo i
readInt64OffForeignObj :: ForeignObj -> Int -> IO Int64
-#if WORD_SIZE_IN_BYTES==8
+# if WORD_SIZE_IN_BYTES==8
readInt64OffForeignObj fo i = _casm_ `` %r=(StgInt)(((StgInt*)%0)[(StgInt)%1]); '' fo i
-#else
+# else
readInt64OffForeignObj fo i = _casm_ `` %r=(StgInt64)(((StgInt64*)%0)[(StgInt)%1]); '' fo i
-#endif
+# endif
+
#endif /* __PARALLEL_HASKELL__ */
\end{code}
#endif
#ifndef __PARALLEL_HASKELL__
+
writeInt8OffForeignObj :: ForeignObj -> Int -> Int8 -> IO ()
writeInt8OffForeignObj fo i e = _casm_ `` (((StgInt8*)%0)[(StgInt)%1])=(StgInt8)%2; '' fo i e
writeInt32OffForeignObj fo i e = _casm_ `` (((StgInt32*)%0)[(StgInt)%1])=(StgInt32)%2; '' fo i e
writeInt64OffForeignObj :: ForeignObj -> Int -> Int64 -> IO ()
-#if WORD_SIZE_IN_BYTES==8
+# if WORD_SIZE_IN_BYTES==8
writeInt64OffForeignObj fo i e = _casm_ `` (((StgInt*)%0)[(StgInt)%1])=(StgInt)%2; '' fo i e
-#else
+# else
writeInt64OffForeignObj fo i e = _casm_ `` (((StgInt64*)%0)[(StgInt)%1])=(StgInt64)%2; '' fo i e
-#endif
+# endif
+
#endif /* __PARALLEL_HASKELL__ */
+
\end{code}
, sizeofWord64
-- The "official" place to get these from is Foreign
+#ifndef __PARALLEL_HASKELL__
, indexWord8OffForeignObj
, indexWord16OffForeignObj
, indexWord32OffForeignObj
, writeWord16OffForeignObj
, writeWord32OffForeignObj
, writeWord64OffForeignObj
+#endif
-- non-standard, GHC specific
, wordToInt
indexWord8OffAddr :: Addr -> Int -> Word8
indexWord8OffAddr (A# a#) (I# i#) = intToWord8 (I# (ord# (indexCharOffAddr# a# i#)))
-indexWord8OffForeignObj :: ForeignObj -> Int -> Word8
-indexWord8OffForeignObj (ForeignObj fo#) (I# i#) = intToWord8 (I# (ord# (indexCharOffForeignObj# fo# i#)))
-
indexWord16OffAddr :: Addr -> Int -> Word16
indexWord16OffAddr a i =
#ifdef WORDS_BIGENDIAN
l = indexWord8OffAddr a byte_idx
h = indexWord8OffAddr a (byte_idx+1)
+indexWord32OffAddr :: Addr -> Int -> Word32
+indexWord32OffAddr (A# a#) i = wordToWord32 (W# (indexWordOffAddr# a# i'#))
+ where
+ -- adjust index to be in Word units, not Word32 ones.
+ (I# i'#)
+#if WORD_SIZE_IN_BYTES==8
+ = i `div` 2
+#else
+ = i
+#endif
+
+indexWord64OffAddr :: Addr -> Int -> Word64
+indexWord64OffAddr (A# a#) (I# i#)
+#if WORD_SIZE_IN_BYTES==8
+ = W64# (indexWordOffAddr# a# i#)
+#else
+ = W64# (indexWord64OffAddr# a# i#)
+#endif
+
+#ifndef __PARALLEL_HASKELL__
+
+indexWord8OffForeignObj :: ForeignObj -> Int -> Word8
+indexWord8OffForeignObj (ForeignObj fo#) (I# i#) = intToWord8 (I# (ord# (indexCharOffForeignObj# fo# i#)))
+
indexWord16OffForeignObj :: ForeignObj -> Int -> Word16
indexWord16OffForeignObj fo i =
#ifdef WORDS_BIGENDIAN
l = indexWord8OffForeignObj fo byte_idx
h = indexWord8OffForeignObj fo (byte_idx+1)
-indexWord32OffAddr :: Addr -> Int -> Word32
-indexWord32OffAddr (A# a#) i = wordToWord32 (W# (indexWordOffAddr# a# i'#))
- where
- -- adjust index to be in Word units, not Word32 ones.
- (I# i'#)
-#if WORD_SIZE_IN_BYTES==8
- = i `div` 2
-#else
- = i
-#endif
-
indexWord32OffForeignObj :: ForeignObj -> Int -> Word32
indexWord32OffForeignObj (ForeignObj fo#) i = wordToWord32 (W# (indexWordOffForeignObj# fo# i'#))
where
= i
#endif
-indexWord64OffAddr :: Addr -> Int -> Word64
-indexWord64OffAddr (A# a#) (I# i#)
-#if WORD_SIZE_IN_BYTES==8
- = W64# (indexWordOffAddr# a# i#)
-#else
- = W64# (indexWord64OffAddr# a# i#)
-#endif
-
indexWord64OffForeignObj :: ForeignObj -> Int -> Word64
indexWord64OffForeignObj (ForeignObj fo#) (I# i#)
#if WORD_SIZE_IN_BYTES==8
#else
= W64# (indexWord64OffForeignObj# fo# i#)
#endif
+#endif
\end{code}
readWord8OffAddr :: Addr -> Int -> IO Word8
readWord8OffAddr a i = _casm_ `` %r=(StgWord8)(((StgWord8*)%0)[(StgInt)%1]); '' a i
-readWord8OffForeignObj :: ForeignObj -> Int -> IO Word8
-readWord8OffForeignObj fo i = _casm_ `` %r=(StgWord8)(((StgWord8*)%0)[(StgInt)%1]); '' fo i
-
readWord16OffAddr :: Addr -> Int -> IO Word16
readWord16OffAddr a i = _casm_ `` %r=(StgWord16)(((StgWord16*)%0)[(StgInt)%1]); '' a i
-readWord16OffForeignObj :: ForeignObj -> Int -> IO Word16
-readWord16OffForeignObj fo i = _casm_ `` %r=(StgWord16)(((StgWord16*)%0)[(StgInt)%1]); '' fo i
-
readWord32OffAddr :: Addr -> Int -> IO Word32
readWord32OffAddr a i = _casm_ `` %r=(StgWord32)(((StgWord32*)%0)[(StgInt)%1]); '' a i
-readWord32OffForeignObj :: ForeignObj -> Int -> IO Word32
-readWord32OffForeignObj fo i = _casm_ `` %r=(StgWord32)(((StgWord32*)%0)[(StgInt)%1]); '' fo i
-
readWord64OffAddr :: Addr -> Int -> IO Word64
#if WORD_SIZE_IN_BYTES==8
readWord64OffAddr a i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' a i
readWord64OffAddr a i = _casm_ `` %r=(StgWord64)(((StgWord64*)%0)[(StgInt)%1]); '' a i
#endif
+#ifndef __PARALLEL_HASKELL__
+readWord8OffForeignObj :: ForeignObj -> Int -> IO Word8
+readWord8OffForeignObj fo i = _casm_ `` %r=(StgWord8)(((StgWord8*)%0)[(StgInt)%1]); '' fo i
+
+readWord16OffForeignObj :: ForeignObj -> Int -> IO Word16
+readWord16OffForeignObj fo i = _casm_ `` %r=(StgWord16)(((StgWord16*)%0)[(StgInt)%1]); '' fo i
+
+readWord32OffForeignObj :: ForeignObj -> Int -> IO Word32
+readWord32OffForeignObj fo i = _casm_ `` %r=(StgWord32)(((StgWord32*)%0)[(StgInt)%1]); '' fo i
+
readWord64OffForeignObj :: ForeignObj -> Int -> IO Word64
#if WORD_SIZE_IN_BYTES==8
readWord64OffForeignObj fo i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' fo i
#else
readWord64OffForeignObj fo i = _casm_ `` %r=(StgWord64)(((StgWord64*)%0)[(StgInt)%1]); '' fo i
#endif
+
+#endif
+
\end{code}
Note: we provide primops for the writing via Addrs since that's used
case (writeWord64OffAddr# a# i# w# s#) of s2# -> IOok s2# ()
#endif
+#ifndef __PARALLEL_HASKELL__
+
writeWord8OffForeignObj :: ForeignObj -> Int -> Word8 -> IO ()
writeWord8OffForeignObj fo i w = _casm_ `` (((StgWord16*)%0)[(StgInt)%1])=(StgWord16)%2; '' fo i w
writeWord64OffForeignObj fo i e = _casm_ `` (((StgWord64*)%0)[(StgInt)%1])=(StgWord64)%2; '' fo i e
#endif
+#endif
\end{code}