def W64.div.step

bend-osdev-word64@0.1.1.0 · word64.bend:255

import bend-osdev-word64@0.1.1.0/word64.bend as Word64
import Base

255# one step: the bit x comes in below r
256def W64.div.step(x: Bool, +b: W64, qr: W64 & W64) -> W64 & W64:
257  (+q, +r) = qr
258  +r2 = W64.or(W64.shl(r, 1n), W64.from_u32(W64.bit(x)))
259  +ge = Bool.or(U32.is_eq(U32.shrn(W64.hi(r), 31n), 1), W64.is_ge(r2, b))
260  (W64.or(W64.shl(q, 1n), W64.from_u32(W64.bit(ge))), W64.sel(ge, W64.sub(r2, b), r2))

Uses (15)

Used by (3)