def QSUB

bend-collections-laws-crypto@1.0.0.0 · proofs/math/typed/w64m128.bend:104

import bend-collections-laws-crypto@1.0.0.0/proofs/math/typed/w64m128.bend as W64m128
import Base
import bend-collections-laws-crypto@1.0.0.0/src/math/w64.bend as X
import bend-collections-laws-crypto@1.0.0.0/src/math/u64.bend as WU
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/word.bend as WD

104# a - b wraps: (a - b mod 2^64) + b == a + 2^64 * qs
105def QSUB(+one: Nat, +a: WU.U64, +b: WU.U64) -> Nat:
106  match a b:
107    case WU.U64{+al, +ah} WU.U64{+bl, +bh}:
108      Nat.add(WD.bo(U32.is_lt(ah, bh), one), WD.bo(U32.is_lt(U32.sub(ah, bh), X.b32(U32.is_lt(al, bl))), one))

Uses (7)

Used by (2)