Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#5414 closed feature request (fixed)

Add unsafeShift to Data.Bits

Reported by: tibbe Owned by: simonmar
Priority: normal Milestone: 7.4.1
Component: libraries/base Version: 7.2.1
Keywords: report-impact Cc: hvr, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


shiftL and shiftR introduce an extra branch to check for overflows (i.e. shifts with an amount larger than 32/64). This branch gets removed if the shift amount is statically known, but otherwise leaves a branch in the optimized code, slowing down bit manipulation code.

unsafeShiftL and unsafeShiftR translate directly to the underlying hardware operation (which is undefined for shift amount larger than the architectures word size).

Attachments (1)

0001-Add-unsafeShift-to-Data.Bits.patch (11.0 KB) - added by tibbe 8 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 8 years ago by tibbe

Status: newpatch

Changed 8 years ago by tibbe

comment:2 Changed 8 years ago by igloo

Milestone: 7.6.1

comment:4 Changed 8 years ago by tibbe

Resolution: fixed
Status: patchclosed

commit de91de0fec8e5a5adda7e3005ad567821059e047

Author: Johan Tibell <>
Date:   Sun Aug 14 11:45:27 2011 +0100

    Add unsafeShift to Data.Bits
    This allows shifting by a non-statically known amount without
    introducing a branch (to check for "overflow").

comment:5 Changed 8 years ago by simonmar


comment:6 Changed 5 years ago by hvr

Cc: hvr ekmett added
Keywords: report-impact added
Note: See TracTickets for help on using tickets.