ppad-fixed-0.1.0: Large fixed-width words and constant-time arithmetic.
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Data.Word.Limb

Description

The primitive Limb type, as well as operations on it.

Synopsis

Limb

newtype Limb :: TYPE 'WordRep Source #

A Limb is the smallest component of a wider word.

Constructors

Limb Word# 

render :: Limb -> String Source #

Return a Limb value as a String.

Bit manipulation and representation

and# Source #

Arguments

:: Limb

a

-> Limb

b

-> Limb

a & b

Bitwise and.

or# Source #

Arguments

:: Limb

a

-> Limb

b

-> Limb

a | b

Bitwise or.

not# Source #

Arguments

:: Limb

a

-> Limb

not a

Bitwise not.

xor# Source #

Arguments

:: Limb

a

-> Limb

b

-> Limb

a ^ b

Bitwise exclusive or.

bits# Source #

Arguments

:: Limb

limb

-> Int

bits required to represent limb

Number of bits required to represent this limb.

shl# Source #

Arguments

:: Limb

limb

-> Int#

shift amount

-> Limb

result

Bit-shift left.

shl1# :: Limb -> (# Limb, Limb #) Source #

Bit-shift left by 1, returning the result and carry.

shr# Source #

Arguments

:: Limb

limb

-> Int#

shift amount

-> Limb

result

Bit-shift right.

shr1# :: Limb -> (# Limb, Limb #) Source #

Bit-shift right by 1, returning the result and carry.

Comparison

eq# :: Limb -> Limb -> Choice Source #

Equality comparison.

ne# :: Limb -> Limb -> Choice Source #

Inequality comparison.

nonzero# :: Limb -> Choice Source #

Comparison to zero.

lt# :: Limb -> Limb -> Choice Source #

Less than.

gt# :: Limb -> Limb -> Choice Source #

Greater than.

Selection

select# Source #

Arguments

:: Limb

a

-> Limb

b

-> Choice

c

-> Limb

result

Return a if c is truthy, otherwise return b.

cswap# Source #

Arguments

:: Limb

a

-> Limb

b

-> Choice

c

-> (# Limb, Limb #)

result

Return (# b, a #) if c is truthy, otherwise return (# a, b #).

Negation

neg# :: Limb -> Limb Source #

Wrapping (two's complement) negation.

Arithmetic

add_o# Source #

Arguments

:: Limb

augend

-> Limb

addend

-> (# Limb, Limb #)

(# sum, carry #)

Overflowing addition, computing augend + addend, returning the sum and carry.

add_c# Source #

Arguments

:: Limb

augend

-> Limb

addend

-> Limb

carry

-> (# Limb, Limb #)

(# sum, new carry #)

Carrying addition, computing augend + addend + carry, returning the sum and new carry.

add_w# Source #

Arguments

:: Limb

augend

-> Limb

addend

-> Limb

sum

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).

sub_b# Source #

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.

sub_w# Source #

Arguments

:: Limb

minuend

-> Limb

subtrahend

-> Limb

difference

Wrapping subtraction, computing minuend - subtrahend, returning the difference (and discarding underflow).

sub_s# Source #

Arguments

:: Limb

minuend

-> Limb

subtrahend

-> Limb

difference

Saturating subtraction, computing minuend - subtrahend, returning the difference (and clamping to zero in the case of underflow).

mul_c# Source #

Arguments

:: Limb

multiplicand

-> Limb

multiplier

-> (# Limb, Limb #)

(# low, high #) product

Widening multiplication, returning low and high words of the product.

mul_w# Source #

Arguments

:: Limb

multiplicand

-> Limb

multiplier

-> Limb

low word of product

Wrapping multiplication, returning only the low word of the product.

mul_s# Source #

Arguments

:: Limb

multiplicand

-> Limb

multiplier

-> Limb

clamped low word of product

Saturating multiplication, returning only the low word of the product, and clamping to the maximum value in the case of overflow.

mac# Source #

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.