summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Word.hs
diff options
context:
space:
mode:
authorReid Barton <rwbarton@gmail.com>2013-09-07 21:07:30 -0400
committerAustin Seipp <austin@well-typed.com>2013-09-15 13:01:12 -0500
commitacaa1c873d6d0657b8b918f8d38927d5667329ac (patch)
treed80655c0e0b7b2ec0ab8952c42d18201cdb14fcc /libraries/base/GHC/Word.hs
parentfa3440945f2519325867c8fe4dbc66aca9c6a7f7 (diff)
downloadhaskell-acaa1c873d6d0657b8b918f8d38927d5667329ac.tar.gz
byteSwap16/32: Narrow the result to 16/32 bits
According to primops.txt.pp, the BSwap16Op and BSwap32Op primops leave the higher bytes of their results undefined. We must clear those higher bytes here before storing the result in a Word16/32. Signed-off-by: Austin Seipp <austin@well-typed.com>
Diffstat (limited to 'libraries/base/GHC/Word.hs')
-rw-r--r--libraries/base/GHC/Word.hs4
1 files changed, 2 insertions, 2 deletions
diff --git a/libraries/base/GHC/Word.hs b/libraries/base/GHC/Word.hs
index 3419a24d58..47710118b5 100644
--- a/libraries/base/GHC/Word.hs
+++ b/libraries/base/GHC/Word.hs
@@ -304,7 +304,7 @@ instance FiniteBits Word16 where
finiteBitSize _ = 16
byteSwap16 :: Word16 -> Word16
-byteSwap16 (W16# w#) = W16# (byteSwap16# w#)
+byteSwap16 (W16# w#) = W16# (narrow16Word# (byteSwap16# w#))
{-# RULES
"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# x#
@@ -531,7 +531,7 @@ instance Read Word32 where
#endif
byteSwap32 :: Word32 -> Word32
-byteSwap32 (W32# w#) = W32# (byteSwap32# w#)
+byteSwap32 (W32# w#) = W32# (narrow32Word# (byteSwap32# w#))
------------------------------------------------------------------------
-- type Word64