1{-# LANGUAGE MagicHash #-}
4-- Module : Data.Text.UnsafeShift
5-- Copyright : (c) Bryan O'Sullivan 2009
8-- Maintainer : bos@serpentine.com, rtomharper@googlemail.com,
10-- Stability : experimental
13-- Fast, unchecked bit shifting functions.
15module Data.Text.UnsafeShift
20-- import qualified Data.Bits as Bits
24-- | This is a workaround for poor optimisation in GHC 6.8.2. It
25-- fails to notice constant-width shifts, and adds a test and branch
26-- to every shift. This imposes about a 10% performance hit.
28-- These functions are undefined when the amount being shifted by is
29-- greater than the size in bits of a machine Int#.
30class UnsafeShift a where
31 shiftL :: a -> Int -> a
32 shiftR :: a -> Int -> a
34instance UnsafeShift Word16 where
36 shiftL (W16# x#) (I# i#) = W16# (narrow16Word# (x# `uncheckedShiftL#` i#))
39 shiftR (W16# x#) (I# i#) = W16# (x# `uncheckedShiftRL#` i#)
41instance UnsafeShift Word32 where
43 shiftL (W32# x#) (I# i#) = W32# (narrow32Word# (x# `uncheckedShiftL#` i#))
46 shiftR (W32# x#) (I# i#) = W32# (x# `uncheckedShiftRL#` i#)
48instance UnsafeShift Word64 where
50 shiftL (W64# x#) (I# i#) = W64# (x# `uncheckedShiftL64#` i#)
53 shiftR (W64# x#) (I# i#) = W64# (x# `uncheckedShiftRL64#` i#)
55instance UnsafeShift Int where
57 shiftL (I# x#) (I# i#) = I# (x# `iShiftL#` i#)
60 shiftR (I# x#) (I# i#) = I# (x# `iShiftRA#` i#)
63instance UnsafeShift Integer where
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list