[commit: packages/base] master: byteSwap16/32: Narrow the result to 16/32 bits (bb41dbf)

git at git.haskell.org git at git.haskell.org
Sun Sep 15 22:17:06 CEST 2013


Repository : ssh://git@git.haskell.org/base

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/bb41dbf7e25d9987ae31fb5fe2ecbb25566dc5f2/base

>---------------------------------------------------------------

commit bb41dbf7e25d9987ae31fb5fe2ecbb25566dc5f2
Author: Reid Barton <rwbarton at gmail.com>
Date:   Sat Sep 7 21:07:30 2013 -0400

    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 at well-typed.com>


>---------------------------------------------------------------

bb41dbf7e25d9987ae31fb5fe2ecbb25566dc5f2
 GHC/Word.hs |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/GHC/Word.hs b/GHC/Word.hs
index 3419a24..4771011 100644
--- a/GHC/Word.hs
+++ b/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




More information about the ghc-commits mailing list