fixed

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

commit 332c5afeb524ce51da6decde6b1d7609f3e06781
parent c701ecb51224ffc087ce43c11f5d97cc3f11b22e
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 21 Nov 2025 17:27:11 +0400

lib: add 'decide' for Choice

Diffstat:
Mlib/Data/Choice.hs | 7+++++++
Mlib/Data/Word/Wider.hs | 6------
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/Data/Choice.hs b/lib/Data/Choice.hs @@ -9,6 +9,7 @@ module Data.Choice ( Choice , true# , false# + , decide -- * MaybeWord# , MaybeWord#(..) @@ -127,6 +128,10 @@ true# _ = case maxBound :: Word of W# w -> Choice w {-# INLINE true# #-} +decide :: Choice -> Bool +decide (Choice c) = isTrue# (neWord# c 0##) +{-# INLINE decide #-} + -- constant time 'Maybe Word#' newtype MaybeWord# = MaybeWord# (# Word#, Choice #) @@ -274,6 +279,8 @@ ct_select_wide# a b (Choice w) = in xor_w# a (and_w# mask (xor_w# a b)) {-# INLINE ct_select_wide# #-} +-- constant-time equality ----------------------------------------------------- + ct_eq_word# :: Word# -> Word# -> Choice ct_eq_word# a b = let !s = case B.finiteBitSize (0 :: Word) of I# m -> m -# 1# diff --git a/lib/Data/Word/Wider.hs b/lib/Data/Word/Wider.hs @@ -36,12 +36,6 @@ instance Show Wider where "(" <> show (W# a) <> ", " <> show (W# b) <> ", " <> show (W# c) <> ", " <> show (W# d) <> ")" -instance Eq Wider where - Wider (# a0, b0, c0, d0 #) == Wider (# a1, b1, c1, d1 #) = - isTrue# (andI# - ((andI# (eqWord# a0 a1) (eqWord# b0 b1))) - ((andI# (eqWord# c0 c1) (eqWord# d0 d1)))) - instance NFData Wider where rnf (Wider a) = case a of (# _, _, _, _ #) -> ()