@@ -14,6 +14,7 @@ module Streamly.Internal.Data.Unboxed
14 , getMutableByteArray#
14 , getMutableByteArray#
17+ , newUnpinnedArrayContents
19#include "MachDeps.h"
20#include "MachDeps.h"
@@ -22,7 +23,7 @@ module Streamly.Internal.Data.Unboxed
23import Data.Complex (Complex((:+)), realPart)
24import Data.Complex (Complex((:+)), realPart)
24import GHC.Base (IO(..))
25import GHC.Base (IO(..))
25−import GHC.Int (Int32(..))
26+import GHC.Int (Int32(..), Int64(..))
26import GHC.Word (Word8(..), Word64(..))
27import GHC.Word (Word8(..), Word64(..))
28import GHC.Exts
29import GHC.Exts
@@ -47,6 +48,20 @@ touch :: ArrayContents a -> IO ()
47touch (ArrayContents contents) =
48touch (ArrayContents contents) =
48 IO $ \s -> case touch# contents s of s' -> (# s', () #)
49 IO $ \s -> case touch# contents s of s' -> (# s', () #)
51+--------------------------------------------------------------------------------
53+--------------------------------------------------------------------------------
55+{-# INLINE newUnpinnedArrayContents #-}
56+newUnpinnedArrayContents :: Int -> IO (ArrayContents a)
57+newUnpinnedArrayContents nbytes | nbytes < 0 =
58+ errorWithoutStackTrace "newUnpinnedArrayContents: size must be >= 0"
59+newUnpinnedArrayContents (I# nbytes) = IO $ \s ->
60+ case newByteArray# nbytes s of
62+ let c = ArrayContents mbarr#
50-------------------------------------------------------------------------------
65-------------------------------------------------------------------------------
51-- Pinning & Unpinning
66-- Pinning & Unpinning
52-------------------------------------------------------------------------------
67-------------------------------------------------------------------------------
@@ -106,6 +121,7 @@ unpin arr@(ArrayContents marr#) =
106#define SIZEOF_WORD64_PRIMITIVE 8#
121#define SIZEOF_WORD64_PRIMITIVE 8#
107#define SIZEOF_HSDOUBLE_PRIMITIVE 8#
122#define SIZEOF_HSDOUBLE_PRIMITIVE 8#
108#define SIZEOF_INT32_PRIMITIVE 4#
123#define SIZEOF_INT32_PRIMITIVE 4#
124+#define SIZEOF_INT64_PRIMITIVE 8#
110#ifdef __GHCJS__
126#ifdef __GHCJS__
111#define WORD64TYP Word64#
127#define WORD64TYP Word64#
@@ -113,6 +129,12 @@ unpin arr@(ArrayContents marr#) =
113#define WORD64TYP Word#
129#define WORD64TYP Word#
133+#define INT64TYP Int64#
135+#define INT64TYP Int#
116{-# INLINE readWord8ArrayAsWideChar# #-}
138{-# INLINE readWord8ArrayAsWideChar# #-}
117readWord8ArrayAsWideChar# ::
139readWord8ArrayAsWideChar# ::
118 MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #)
140 MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #)
@@ -149,6 +171,18 @@ writeWord8ArrayAsInt32# ::
149writeWord8ArrayAsInt32# arr# i# a# s# =
171writeWord8ArrayAsInt32# arr# i# a# s# =
150 writeInt32Array# arr# (quotInt# i# SIZEOF_INT32_PRIMITIVE) a# s#
172 writeInt32Array# arr# (quotInt# i# SIZEOF_INT32_PRIMITIVE) a# s#
174+{-# INLINE readWord8ArrayAsInt64# #-}
175+readWord8ArrayAsInt64# ::
176+ MutableByteArray# d -> Int# -> State# d -> (# State# d, INT64TYP #)
177+readWord8ArrayAsInt64# arr# i# s# =
178+ readInt64Array# arr# (quotInt# i# SIZEOF_INT64_PRIMITIVE) s#
180+{-# INLINE writeWord8ArrayAsInt64# #-}
181+writeWord8ArrayAsInt64# ::
182+ MutableByteArray# d -> Int# -> INT64TYP -> State# d -> State# d
183+writeWord8ArrayAsInt64# arr# i# a# s# =
184+ writeInt64Array# arr# (quotInt# i# SIZEOF_INT64_PRIMITIVE) a# s#
152{-# INLINE readWord8ArrayAsWord# #-}
186{-# INLINE readWord8ArrayAsWord# #-}
153readWord8ArrayAsWord# ::
187readWord8ArrayAsWord# ::
154 MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
188 MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
@@ -269,6 +303,13 @@ DERIVE_UNBOXED( Int
269 , readWord8ArrayAsInt#
303 , readWord8ArrayAsInt#
270 , writeWord8ArrayAsInt#)
304 , writeWord8ArrayAsInt#)
306+DERIVE_UNBOXED( Int64
310+ , readWord8ArrayAsInt64#
311+ , writeWord8ArrayAsInt64#)
272DERIVE_UNBOXED( Word
313DERIVE_UNBOXED( Word
274 , SIZEOF_HSWORD
315 , SIZEOF_HSWORD