Data.Bits instances should use default shift instead of shiftL/shiftR
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
Trac metadata
Trac field | Value |
---|---|
Version | 7.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |