@@ -14,6 +14,7 @@ module Streamly.Internal.Data.Unboxed
1414 , getMutableByteArray#
1515 , pin
1616 , unpin
17+ , newUnpinnedArrayContents
1718 ) where
1819
1920#include "MachDeps.h"
@@ -22,7 +23,7 @@ module Streamly.Internal.Data.Unboxed
2223
2324import Data.Complex (Complex((:+)), realPart)
2425import GHC.Base (IO(..))
25−import GHC.Int (Int32(..))
26+import GHC.Int (Int32(..), Int64(..))
2627import GHC.Word (Word8(..), Word64(..))
2728
2829import GHC.Exts
@@ -47,6 +48,20 @@ touch :: ArrayContents a -> IO ()
4748touch (ArrayContents contents) =
4849 IO $ \s -> case touch# contents s of s' -> (# s', () #)
4950
51+--------------------------------------------------------------------------------
52+-- Creation
53+--------------------------------------------------------------------------------
54+
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
61+ (# s', mbarr# #) ->
62+ let c = ArrayContents mbarr#
63+ in (# s', c #)
64+
5065-------------------------------------------------------------------------------
5166-- Pinning & Unpinning
5267-------------------------------------------------------------------------------
@@ -106,6 +121,7 @@ unpin arr@(ArrayContents marr#) =
106121#define SIZEOF_WORD64_PRIMITIVE 8#
107122#define SIZEOF_HSDOUBLE_PRIMITIVE 8#
108123#define SIZEOF_INT32_PRIMITIVE 4#
124+#define SIZEOF_INT64_PRIMITIVE 8#
109125
110126#ifdef __GHCJS__
111127#define WORD64TYP Word64#
@@ -113,6 +129,12 @@ unpin arr@(ArrayContents marr#) =
113129#define WORD64TYP Word#
114130#endif
115131
132+#ifdef __GHCJS__
133+#define INT64TYP Int64#
134+#else
135+#define INT64TYP Int#
136+#endif
137+
116138{-# INLINE readWord8ArrayAsWideChar# #-}
117139readWord8ArrayAsWideChar# ::
118140 MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #)
@@ -149,6 +171,18 @@ writeWord8ArrayAsInt32# ::
149171writeWord8ArrayAsInt32# arr# i# a# s# =
150172 writeInt32Array# arr# (quotInt# i# SIZEOF_INT32_PRIMITIVE) a# s#
151173
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#
179+
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#
185+
152186{-# INLINE readWord8ArrayAsWord# #-}
153187readWord8ArrayAsWord# ::
154188 MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
@@ -269,6 +303,13 @@ DERIVE_UNBOXED( Int
269303 , readWord8ArrayAsInt#
270304 , writeWord8ArrayAsInt#)
271305
306+DERIVE_UNBOXED( Int64
307+ , I64#
308+ , SIZEOF_INT64
309+ , ALIGNMENT_INT64
310+ , readWord8ArrayAsInt64#
311+ , writeWord8ArrayAsInt64#)
312+
272313DERIVE_UNBOXED( Word
273314 , W#
274315 , SIZEOF_HSWORD