Skip to content

Commit

Permalink
Use byteSwapX# in WORDS_BIGENDIAN
Browse files Browse the repository at this point in the history
  • Loading branch information
sgraf812 committed Jun 26, 2024
1 parent f8fe5f0 commit 174920e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
44 changes: 20 additions & 24 deletions data/AlexTemplate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ data AlexAddr = AlexA# Addr#
{-# INLINE alexIndexInt16OffAddr #-}
alexIndexInt16OffAddr :: AlexAddr -> Int# -> Int#
alexIndexInt16OffAddr (AlexA# arr) off =
#ifdef WORDS_BIGENDIAN
narrow16Int# i
where
i = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
low = int2Word# (ord# (indexCharOffAddr# arr off'))
off' = off *# 2#
#else
#if __GLASGOW_HASKELL__ >= 901
GHC.Exts.int16ToInt#
(int16ToInt#
#endif
#ifdef WORDS_BIGENDIAN
(word16ToInt16# (byteSwap16# (int16ToWord16#
#endif
(indexInt16OffAddr# arr off)
#ifdef WORDS_BIGENDIAN
)))
#endif
(indexInt16OffAddr# arr off)
#if __GLASGOW_HASKELL__ >= 901
)
#endif
#else
alexIndexInt16OffAddr = (Data.Array.!)
Expand All @@ -65,22 +65,18 @@ alexIndexInt16OffAddr = (Data.Array.!)
{-# INLINE alexIndexInt32OffAddr #-}
alexIndexInt32OffAddr :: AlexAddr -> Int# -> Int#
alexIndexInt32OffAddr (AlexA# arr) off =
#ifdef WORDS_BIGENDIAN
narrow32Int# i
where
i = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#`
(b2 `uncheckedShiftL#` 16#) `or#`
(b1 `uncheckedShiftL#` 8#) `or#` b0)
b3 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#)))
b2 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#)))
b1 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
b0 = int2Word# (ord# (indexCharOffAddr# arr off'))
off' = off *# 4#
#else
#if __GLASGOW_HASKELL__ >= 901
GHC.Exts.int32ToInt#
(int32ToInt#
#endif
#ifdef WORDS_BIGENDIAN
(word32ToInt32# (byteSwap32# (int32ToWord32#
#endif
(indexInt32OffAddr# arr off)
#ifdef WORDS_BIGENDIAN
)))
#endif
(indexInt32OffAddr# arr off)
#if __GLASGOW_HASKELL__ >= 901
)
#endif
#else
alexIndexInt32OffAddr = (Data.Array.!)
Expand Down
8 changes: 8 additions & 0 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,22 @@ import_glaexts =
, "indexCharOffAddr#"
, "indexInt16OffAddr#"
, "indexInt32OffAddr#"
, "int16ToInt#"
, "int32ToInt#"
, "int2Word#"
, "int16ToWord16#"
, "int32ToWord32#"
, "narrow16Int#"
, "narrow32Int#"
, "negateInt#"
, "or#"
, "ord#"
, "uncheckedShiftL#"
, "word2Int#"
, "word16ToInt16#"
, "word32ToInt32#"
, "byteSwap16#"
, "byteSwap32#"
]

import_debug :: [String]
Expand Down

0 comments on commit 174920e

Please sign in to comment.