~/bend-docscommunity

lanes.bend source

lanes.bend on the hub · documented module

# Index arithmetic of the kernels: which items a lane runs, and which cells an item owns. Plain safe Bend (no# @unsafe), so LAWS.bend can check it; bang.bend and nn.bend compute every write position through these defs.import Base# leaf t of l runs items t, t + l, t + 2l, ...: this many of them are below ndef share(+t: U32, +n: U32, +l: U32) -> Nat:  U32.to_nat(Bool.pick(U32, U32.is_lt(t, n), U32.div(((n - t : U32) + (l - 1 : U32) : U32), l), 0))# first cell of item i, when every item owns w consecutive cellsdef cell(+i: U32, +w: U32) -> U32:  (i * w : U32)# Row segments: a row of seg * nseg cells is nseg items of seg cells, so item i is segment i % nseg of row i / nseg,# and owns cells cell(i, seg) .. cell(i, seg) + seg - 1 whatever its row.def width(+seg: U32, +nseg: U32) -> U32:  (seg * nseg : U32)def row(+i: U32, +nseg: U32) -> U32:  (i / nseg : U32)# column of item i's first cell within its rowdef col(+i: U32, +seg: U32, +nseg: U32) -> U32:  (U32.mod(i, nseg) * seg : U32)# first item of item i's row (where the row's per-segment partials start)def first(+i: U32, +nseg: U32) -> U32:  (row(i, nseg) * nseg : U32)# whether item i is its row's first segmentdef leads(+i: U32, +nseg: U32) -> Bool:  U32.is_eq(U32.mod(i, nseg), 0)