Charged native modular-counter matrix accesses #
The Morton block reads two actual words from the previously computed spread table. The residue block computes the actual row-major address, transposing BC when requested. These are internal stage contracts; the composed counter supplies the table through its proved construction and the residues through the existing native signed-remainder loop.
theorem Cslib.Algorithms.WordRAM.ExactTriangle.CountPrime.exec_morton {w k : ℕ} (x : WordRAM.Data 128) (h2 : x.regs Reg.two = 2) (hr : x.regs Reg.row < 2 ^ k) (hc : x.regs Reg.column < 2 ^ k) (htable : ∀ j < 2 ^ k, x.mem (x.regs Reg.spread + j) = Nat.Morton.spread j) (hw : WordRAM.Fits w (x.regs Reg.spread + 4 ^ k + 2 ^ k)) :
∃ (y : WordRAM.Data 128),
WordRAM.ExecWithin w morton x y 6 ∧ y.mem = x.mem ∧ y.regs Reg.position = Nat.Morton.index (x.regs Reg.row) (x.regs Reg.column) ∧ ∀ (i : Fin 128),
i ≠ Reg.address → i ≠ Reg.rowSpread → i ≠ Reg.columnSpread → i ≠ Reg.position → y.regs i = x.regs i
Six actual instructions read the table and compute the Morton index. The input row and column and the original table pointer are preserved.
theorem Cslib.Algorithms.WordRAM.ExactTriangle.CountPrime.exec_readResidue {w : ℕ} (transpose : Bool) (x : WordRAM.Data 128) (hr : x.regs Reg.row < x.regs Reg.side) (hc : x.regs Reg.column < x.regs Reg.side) (hw : WordRAM.Fits w (x.regs Reg.residueSource + x.regs Reg.side * x.regs Reg.side)) :
∃ (y : WordRAM.Data 128),
WordRAM.ExecWithin w (readResidue transpose) x y 4 ∧ y.mem = x.mem ∧ y.regs Reg.residue = x.mem
(x.regs Reg.residueSource + if transpose = true then x.regs Reg.column * x.regs Reg.side + x.regs Reg.row
else x.regs Reg.row * x.regs Reg.side + x.regs Reg.column) ∧ ∀ (i : Fin 128), i ≠ Reg.address → i ≠ Reg.temporary → i ≠ Reg.residue → y.regs i = x.regs i
Four actual instructions perform an admitted original-matrix residue read. The transpose is fixed code selection, while both coordinates and the pointer are runtime data.