[Haskell] Performance, Optimization and Code Generation

roconnor at theorem.ca roconnor at theorem.ca
Sat Sep 23 08:13:39 EDT 2006


according to <http://darcs.haskell.org/packages/base/GHC/Word.hs>, GHC's 
rotate is implemented as

     (W32# x#) `rotate` (I# i#)
         | i'# ==# 0# = W32# x#
         | otherwise  = W32# ((x# `shiftL32#` i'#) `or32#`
                              (x# `shiftRL32#` (32# -# i'#)))
         where
         i'# = word2Int# (int2Word# i# `and#` int2Word# 31#)

So you can see that it takes i modulo 32 first (by anding it with 31). 
Perhaps one needs an uncheckedRotate32# function (if it doesn't exist).

Also, shouldn't the calls to shiftL32# and shiftRL32# be calls to 
uncheckedShiftL32# and uncheckedShiftR32# since i'# and (32# -# i'#) are 
provably safe?

-- 
Russell O'Connor                                      <http://r6.ca/>
``All talk about `theft,''' the general counsel of the American Graphophone
Company wrote, ``is the merest claptrap, for there exists no property in
ideas musical, literary or artistic, except as defined by statute.''


More information about the Haskell mailing list