| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Word.Limb
Description
The primitive Limb type, as well as operations on it.
All operations run in constant time with respect to inputs, unless specifically indicated otherwise.
Synopsis
- newtype Limb :: TYPE 'WordRep = Limb Word#
- render :: Limb -> String
- and# :: Limb -> Limb -> Limb
- or# :: Limb -> Limb -> Limb
- not# :: Limb -> Limb
- xor# :: Limb -> Limb -> Limb
- bits# :: Limb -> Int
- shl# :: Limb -> Int# -> Limb
- shl1# :: Limb -> (# Limb, Limb #)
- shr# :: Limb -> Int# -> Limb
- shr1# :: Limb -> (# Limb, Limb #)
- eq# :: Limb -> Limb -> Choice
- ne# :: Limb -> Limb -> Choice
- eq_vartime# :: Limb -> Limb -> Bool
- ne_vartime# :: Limb -> Limb -> Bool
- nonzero# :: Limb -> Choice
- lt# :: Limb -> Limb -> Choice
- gt# :: Limb -> Limb -> Choice
- select# :: Limb -> Limb -> Choice -> Limb
- cswap# :: Limb -> Limb -> Choice -> (# Limb, Limb #)
- neg# :: Limb -> Limb
- add_o# :: Limb -> Limb -> (# Limb, Limb #)
- add_c# :: Limb -> Limb -> Limb -> (# Limb, Limb #)
- add_w# :: Limb -> Limb -> Limb
- add_s# :: Limb -> Limb -> Limb
- sub_b# :: Limb -> Limb -> Limb -> (# Limb, Limb #)
- sub_w# :: Limb -> Limb -> Limb
- sub_s# :: Limb -> Limb -> Limb
- mul_c# :: Limb -> Limb -> (# Limb, Limb #)
- mul_w# :: Limb -> Limb -> Limb
- mul_s# :: Limb -> Limb -> Limb
- mac# :: Limb -> Limb -> Limb -> Limb -> (# Limb, Limb #)
- data Word = W# Word#
Limb
Bit manipulation and representation
Number of bits required to represent this limb.
shl1# :: Limb -> (# Limb, Limb #) Source #
Unchecked bit-shift left by 1, returning the result and carry.
shr1# :: Limb -> (# Limb, Limb #) Source #
Unchecked logical bit-shift right by 1, returning the result and carry.
Comparison
Selection
Return a if c is truthy, otherwise return b.
Return (# b, a #) if c is truthy, otherwise return (# a, b #).
Negation
Arithmetic
Overflowing addition, computing augend + addend, returning the sum and carry.
Carrying addition, computing augend + addend + carry, returning the sum and new carry.
Wrapping addition, computing augend + addend, returning the sum (discarding overflow).
add_s# :: Limb -> Limb -> Limb Source #
Saturating addition, computing augend + addend, returning the sum (clamping to the maximum representable value in the case of overflow).
Arguments
| :: Limb | minuend |
| -> Limb | subtrahend |
| -> Limb | borrow |
| -> (# Limb, Limb #) | (# difference, new borrow #) |
Borrowing subtraction, computing minuend - (subtrahend + borrow), returning the difference and new borrow mask.
Wrapping subtraction, computing minuend - subtrahend, returning the difference (and discarding underflow).
Saturating subtraction, computing minuend - subtrahend, returning the difference (and clamping to zero in the case of underflow).
Widening multiplication, returning low and high words of the product.
Wrapping multiplication, returning only the low word of the product.
Saturating multiplication, returning only the low word of the product, and clamping to the maximum value in the case of overflow.
Arguments
| :: Limb | a (multiplicand) |
| -> Limb | b (multiplier) |
| -> Limb | m (addend) |
| -> Limb | c (carry) |
| -> (# Limb, Limb #) | a * b + m + c |
Multiply-add-carry, computing a * b + m + c, returning the result along with the new carry.
Re-exported
Instances
| Data Word | Since: base-4.0.0.0 | ||||
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word -> c Word # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word # dataTypeOf :: Word -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word) # gmapT :: (forall b. Data b => b -> b) -> Word -> Word # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word -> r # gmapQ :: (forall d. Data d => d -> u) -> Word -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word -> m Word # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word -> m Word # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word -> m Word # | |||||
| Storable Word | Since: base-2.1 | ||||
Defined in Foreign.Storable | |||||
| Bits Word | Since: base-2.1 | ||||
Defined in GHC.Bits Methods (.&.) :: Word -> Word -> Word # (.|.) :: Word -> Word -> Word # complement :: Word -> Word # shift :: Word -> Int -> Word # rotate :: Word -> Int -> Word # setBit :: Word -> Int -> Word # clearBit :: Word -> Int -> Word # complementBit :: Word -> Int -> Word # testBit :: Word -> Int -> Bool # bitSizeMaybe :: Word -> Maybe Int # shiftL :: Word -> Int -> Word # unsafeShiftL :: Word -> Int -> Word # shiftR :: Word -> Int -> Word # unsafeShiftR :: Word -> Int -> Word # rotateL :: Word -> Int -> Word # | |||||
| FiniteBits Word | Since: base-4.6.0.0 | ||||
Defined in GHC.Bits Methods finiteBitSize :: Word -> Int # countLeadingZeros :: Word -> Int # countTrailingZeros :: Word -> Int # | |||||
| Bounded Word | Since: base-2.1 | ||||
| Enum Word | Since: base-2.1 | ||||
| Ix Word | Since: base-4.6.0.0 | ||||
| Num Word | Since: base-2.1 | ||||
| Read Word | Since: base-4.5.0.0 | ||||
| Integral Word | Since: base-2.1 | ||||
| Real Word | Since: base-2.1 | ||||
Defined in GHC.Real Methods toRational :: Word -> Rational # | |||||
| Show Word | Since: base-2.1 | ||||
| PrintfArg Word | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
| NFData Word | |||||
Defined in Control.DeepSeq | |||||
| Eq Word | |||||
| Ord Word | |||||
| Generic1 (URec Word :: k -> Type) | |||||
Defined in GHC.Generics Associated Types
| |||||
| Foldable (UWord :: Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in Data.Foldable Methods fold :: Monoid m => UWord m -> m # foldMap :: Monoid m => (a -> m) -> UWord a -> m # foldMap' :: Monoid m => (a -> m) -> UWord a -> m # foldr :: (a -> b -> b) -> b -> UWord a -> b # foldr' :: (a -> b -> b) -> b -> UWord a -> b # foldl :: (b -> a -> b) -> b -> UWord a -> b # foldl' :: (b -> a -> b) -> b -> UWord a -> b # foldr1 :: (a -> a -> a) -> UWord a -> a # foldl1 :: (a -> a -> a) -> UWord a -> a # elem :: Eq a => a -> UWord a -> Bool # maximum :: Ord a => UWord a -> a # minimum :: Ord a => UWord a -> a # | |||||
| Traversable (UWord :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Functor (URec Word :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Generic (URec Word p) | |||||
Defined in GHC.Generics Associated Types
| |||||
| Show (URec Word p) | Since: base-4.9.0.0 | ||||
| Eq (URec Word p) | Since: base-4.9.0.0 | ||||
| Ord (URec Word p) | Since: base-4.9.0.0 | ||||
Defined in GHC.Generics | |||||
| data URec Word (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 | ||||
| type Rep1 (URec Word :: k -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Generics | |||||
| type Rep (URec Word p) | Since: base-4.9.0.0 | ||||
Defined in GHC.Generics | |||||