#5339: Data.Bits instances should use default shift instead of shiftL/shiftR
---------------------------------+------------------------------------------
Reporter: liyang | Owner:
Type: feature request | Status: new
Priority: normal | Component: libraries/base
Version: 7.1 | Keywords:
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: Runtime performance bug
---------------------------------+------------------------------------------
The documentation notes that the second arg of shiftL/shiftR must be
positive, yet many definitions of "instance Bits …" rely on the class
defaults implementation of shift.
This patch defines shiftL and shiftR explicitly in terms of the
corresponding prim ops, while falling back to the class default for shift.
This produces the same output for shift, but much more readable core for
shiftL and shiftR.
For "shiftR 1 i", contrast
{{{
case i of _ { I# i# -> case >=# i# 64 of _ {
False -> uncheckedIShiftRA# 1 i#
True -> 0 } }
}}}
with
{{{
case i of _ { I# i# -> let { n# = negateInt# i# } in case >=# n# 0 of _ {
False -> let { nn# = negateInt# n# } in case >=# nn# 64 of _ {
False -> uncheckedIShiftRA# 1 nn#
True -> 0 };
True -> case >=# n# 64 of _ {
False -> uncheckedIShiftL# 1 n#
True -> 0 } } }
}}}
Cheers,
/Liyang
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5339>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs