def parts

bend-kit-bits@0.1.0.1 · bits.bend:138

import bend-kit-bits@0.1.0.1/bits.bend as Bits
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes

138# The parts of an n-bit v that land in word k and word k + 1, as stored words.
139def parts(msb: Bool, +s: U32, +n: U32, +v: U32) -> U32 & U32:
140  match msb:
141    case True{}:
142      +t = U32.shln(v, U32.to_nat((32 - n : U32)))
143      (Bytes.bswap(U32.shrn(t, U32.to_nat(s))), Bytes.bswap(U32.shln(t, U32.to_nat((32 - s : U32)))))
144    case False{}:
145      +m = (v .&. mask(n) : U32)
146      (U32.shln(m, U32.to_nat(s)), U32.shrn(m, U32.to_nat((32 - s : U32))))

Uses (11)

Used by (1)