summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Schulze Frielinghaus <stefansf@linux.ibm.com>2021-01-16 10:20:33 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-22 15:05:21 -0500
commit637ae302bf89bd601da0afb62b31ef1f79a38d71 (patch)
treec82ca260bd7df9bdf868642f493c56bd46f2bd0a
parent4bb9a349b5d002463b9fc4e9a3b6dbf77ea7c085 (diff)
downloadhaskell-637ae302bf89bd601da0afb62b31ef1f79a38d71.tar.gz
CmmToC: Fix translation of Cmm literals to word sized literals
For big-endian machines remove the byte swap in the non-recursive call of goSubWord since the integer is already in proper format.
-rw-r--r--compiler/GHC/CmmToC.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs
index 0733369679..d7596f0aac 100644
--- a/compiler/GHC/CmmToC.hs
+++ b/compiler/GHC/CmmToC.hs
@@ -525,13 +525,15 @@ staticLitsToWords platform = go . foldMap decomposeMultiWord
goSubWord rem_bytes accum (lit : rest)
| Just (bytes, w) <- isSubWordLit lit
, rem_bytes >= widthInBytes w
- = let accum' =
- case platformByteOrder platform of
- BigEndian -> (accum `shiftL` widthInBits w) .|. bytes
- LittleEndian -> (accum `shiftL` widthInBits w) .|. byteSwap w bytes
+ = let accum' = (accum `shiftL` widthInBits w) .|. fixEndian w bytes
in goSubWord (rem_bytes - widthInBytes w) accum' rest
goSubWord rem_bytes accum rest
- = pprWord (byteSwap (wordWidth platform) $ accum `shiftL` (8*rem_bytes)) : go rest
+ = pprWord (fixEndian (wordWidth platform) $ accum `shiftL` (8*rem_bytes)) : go rest
+
+ fixEndian :: Width -> Integer -> Integer
+ fixEndian w = case platformByteOrder platform of
+ BigEndian -> id
+ LittleEndian -> byteSwap w
-- Decompose multi-word or floating-point literals into multiple
-- single-word (or smaller) literals.