Opened 4 years ago

Closed 4 years ago

#5339 closed feature request (fixed)

Data.Bits instances should use default shift instead of shiftL/shiftR

Reported by: liyang Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 7.1
Keywords: Cc: hackage.haskell.org@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

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

Attachments (1)

0001-Data.Bits-specialise-shift-LR-for-instance-Bits.patch (6.9 KB) - added by liyang 4 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 4 years ago by liyang

  • Cc hackage.haskell.org@… added
  • Status changed from new to patch

comment:2 Changed 4 years ago by igloo

  • Resolution set to fixed
  • Status changed from patch to closed
Note: See TracTickets for help on using tickets.