def add

bend-collections-laws-crypto@1.0.0.0 · spec/crypto/sha512.bend:16

import bend-collections-laws-crypto@1.0.0.0/spec/crypto/sha512.bend as Sha512
import Base
import bend-collections-laws-crypto@1.0.0.0/src/crypto/sha512/types.bend as T

16# FIPS 180-4 section 3.2: x + y mod 2^64. The low halves add modulo 2^32; the
17# high halves add the carry out of the low half, which is 1 exactly when the
18# low sum wrapped below either addend.
19def add(a: T.Lane, b: T.Lane) -> T.Lane:
20  match a b:
21    case T.W{ah, +al} T.W{bh, bl}:
22      +lo = U32.add(al, bl)
23      T.W{U32.add(U32.add(ah, bh), Bool.to_u32(U32.is_lt(lo, al))), lo}

Uses (4)

Used by (5)