@@ -23,15 +23,21 @@ module Crypto.Internal.CompatPrim
23
23
, convert4To32
24
24
) where
25
25
26
- import GHC.Prim
27
26
#if !defined(ARCH_IS_LITTLE_ENDIAN) && !defined(ARCH_IS_BIG_ENDIAN)
28
27
import Data.Memory.Endian (getSystemEndianness , Endianness (.. ))
29
28
#endif
30
29
30
+ #if __GLASGOW_HASKELL__ >= 902
31
+ import GHC.Prim
32
+ #else
33
+ import GHC.Prim hiding (Word32 #)
34
+ type Word32 # = Word #
35
+ #endif
36
+
31
37
-- | Byteswap Word# to or from Big Endian
32
38
--
33
39
-- On a big endian machine, this function is a nop.
34
- be32Prim :: Word # -> Word #
40
+ be32Prim :: Word32 # -> Word32 #
35
41
#ifdef ARCH_IS_LITTLE_ENDIAN
36
42
be32Prim = byteswap32Prim
37
43
#elif defined(ARCH_IS_BIG_ENDIAN)
@@ -43,7 +49,7 @@ be32Prim w = if getSystemEndianness == LittleEndian then byteswap32Prim w else w
43
49
-- | Byteswap Word# to or from Little Endian
44
50
--
45
51
-- On a little endian machine, this function is a nop.
46
- le32Prim :: Word # -> Word #
52
+ le32Prim :: Word32 # -> Word32 #
47
53
#ifdef ARCH_IS_LITTLE_ENDIAN
48
54
le32Prim w = w
49
55
#elif defined(ARCH_IS_BIG_ENDIAN)
@@ -54,16 +60,11 @@ le32Prim w = if getSystemEndianness == LittleEndian then w else byteswap32Prim w
54
60
55
61
-- | Simple compatibility for byteswap the lower 32 bits of a Word#
56
62
-- at the primitive level
57
- byteswap32Prim :: Word # -> Word #
58
- #if __GLASGOW_HASKELL__ >= 708
59
- byteswap32Prim w = byteSwap32# w
63
+ byteswap32Prim :: Word32 # -> Word32 #
64
+ #if __GLASGOW_HASKELL__ >= 902
65
+ byteswap32Prim w = wordToWord32 # ( byteSwap32# (word32ToWord # w))
60
66
#else
61
- byteswap32Prim w =
62
- let ! a = uncheckedShiftL# w 24 #
63
- ! b = and # (uncheckedShiftL# w 8 # ) 0x00ff0000 ##
64
- ! c = and # (uncheckedShiftRL# w 8 # ) 0x0000ff00 ##
65
- ! d = and # (uncheckedShiftRL# w 24 # ) 0x000000ff ##
66
- in or # a (or # b (or # c d))
67
+ byteswap32Prim w = byteSwap32# w
67
68
#endif
68
69
69
70
-- | Combine 4 word8 [a,b,c,d] to a word32 representing [a,b,c,d]
0 commit comments