Skip to content

Commit e3208a4

Browse files
authored
Merge pull request #44 from Bodigrim/master
Support big-endian architectures
2 parents 91bc991 + 7a66958 commit e3208a4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/Unicode/Internal/Bits.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
--
1010
-- Fast, static bitmap lookup utilities
1111

12+
{-# LANGUAGE CPP #-}
13+
1214
module Unicode.Internal.Bits
1315
(
1416
lookupBit64
1517
) where
1618

19+
#include "MachDeps.h"
20+
1721
import Data.Bits (finiteBitSize, popCount)
1822
import GHC.Exts
1923
(Addr#, Int(..), Word(..), indexWordOffAddr#, and#, andI#,
2024
uncheckedIShiftRL#, uncheckedShiftL#)
25+
#ifdef WORDS_BIGENDIAN
26+
import GHC.Exts (byteSwap#)
27+
#endif
2128

2229
-- | @lookup64 addr index@ looks up the bit stored at bit index @index@ using a
2330
-- bitmap starting at the address @addr@. Looks up the 64-bit word containing
@@ -35,6 +42,10 @@ lookupBit64 addr# (I# index#) = W# (word## `and#` bitMask##) /= 0
3542
_ -> popCount fbs -- this is a really weird architecture
3643

3744
wordIndex# = index# `uncheckedIShiftRL#` logFbs#
45+
#ifdef WORDS_BIGENDIAN
46+
word## = byteSwap# (indexWordOffAddr# addr# wordIndex#)
47+
#else
3848
word## = indexWordOffAddr# addr# wordIndex#
49+
#endif
3950
bitIndex# = index# `andI#` fbs#
4051
bitMask## = 1## `uncheckedShiftL#` bitIndex#

0 commit comments

Comments
 (0)