File: Mach.hs

package info (click to toggle)
haskell-primitive-unaligned 0.1.1.2-5
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116 kB
  • sloc: haskell: 382; makefile: 7
file content (86 lines) | stat: -rw-r--r-- 1,924 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{-# language CPP #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}

module Data.Primitive.Unaligned.Mach
  ( indexUnalignedInt64Array#
  , indexUnalignedWord64Array#
  , readUnalignedInt64Array#
  , readUnalignedWord64Array#
  , writeUnalignedInt64Array#
  , writeUnalignedWord64Array#
  ) where

import GHC.Exts (Int#,ByteArray#,MutableByteArray#,State#)
import GHC.Word (Word64(W64#))
import GHC.Int (Int64(I64#))
import qualified GHC.Exts as E

indexUnalignedWord64Array# :: ByteArray# -> Int# -> Word64
indexUnalignedWord64Array# a i =
  W64# (
#if MIN_VERSION_base(4,17,0)
    E.wordToWord64#
#endif
    (E.indexWord8ArrayAsWord# a i))

indexUnalignedInt64Array# :: ByteArray# -> Int# -> Int64
indexUnalignedInt64Array# a i =
  I64# (
#if MIN_VERSION_base(4,17,0)
    E.intToInt64#
#endif
    (E.indexWord8ArrayAsInt# a i))

readUnalignedWord64Array# ::
     MutableByteArray# s
  -> Int#
  -> State# s
  -> (# State# s, Word64 #)
readUnalignedWord64Array# a i s0 =
  case E.readWord8ArrayAsWord# a i s0 of
    (# s1, r #) -> (# s1, W64# (
#if MIN_VERSION_base(4,17,0)
        E.wordToWord64#
#endif
        r)
        #)

readUnalignedInt64Array# ::
     MutableByteArray# s
  -> Int#
  -> State# s
  -> (# State# s, Int64 #)
readUnalignedInt64Array# a i s0 =
  case E.readWord8ArrayAsInt# a i s0 of
    (# s1, r #) -> (# s1, I64# (
#if MIN_VERSION_base(4,17,0)
       E.intToInt64#
#endif
        r) #)

writeUnalignedWord64Array# ::
       MutableByteArray# s
    -> Int#
    -> Word64
    -> State# s
    -> State# s
writeUnalignedWord64Array# a i (W64# w) =
  E.writeWord8ArrayAsWord# a i (
#if MIN_VERSION_base(4,17,0)
    E.word64ToWord#
#endif
    w)

writeUnalignedInt64Array# ::
       MutableByteArray# s
    -> Int#
    -> Int64
    -> State# s
    -> State# s
writeUnalignedInt64Array# a i (I64# w) =
  E.writeWord8ArrayAsInt# a i (
#if MIN_VERSION_base(4,17,0)
    E.int64ToInt#
#endif
    w)