fixed

Pure Haskell large fixed-width integers and Montgomery arithmetic.
git clone git://git.ppad.tech/fixed.git
Log | Files | Refs | README | LICENSE

commit e103f7cb117e2179a52e3415becb8d4f24aa64f5
parent 1810140a360ea7428a157175003ba734e054e70e
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 12 Dec 2025 07:46:38 +0400

wider: add shl1, shr1

Diffstat:
Mlib/Data/Word/Wider.hs | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/lib/Data/Word/Wider.hs b/lib/Data/Word/Wider.hs @@ -34,6 +34,8 @@ module Data.Word.Wider ( , select# -- * Bit manipulation + , shl1 + , shr1 , shl1_c , shr1_c , shr_limb @@ -284,6 +286,17 @@ shr1_c (Wider w) = let !(# r, c #) = shr1_c# w in (Wider r, C.decide c) +-- | Constant-time 1-bit shift-right. +-- +-- >>> shr1 2 +-- 1 +-- >>> shr1 1 +-- 0 +shr1 :: Wider -> Wider +shr1 (Wider w) = + let !(# r, _ #) = shr1_c# w + in Wider r + shl1_c# :: (# Limb, Limb, Limb, Limb #) -- ^ argument -> (# (# Limb, Limb, Limb, Limb #), C.Choice #) -- ^ result, carry @@ -313,6 +326,17 @@ shl1_c (Wider w) = let !(# r, c #) = shl1_c# w in (Wider r, C.decide c) +-- | Constant-time 1-bit shift-left. +-- +-- >>> shl1 1 +-- 2 +-- >>> shl1 (2 ^ (255 :: Word)) +-- 0 +shl1 :: Wider -> Wider +shl1 (Wider w) = + let !(# r, _ #) = shl1_c# w + in Wider r + shr_limb# :: (# Limb, Limb, Limb, Limb #) -> Int#