Reflected register-preservation and width-read checks for word-RAM code #
Proving ∀ i : Fin r, P i → c.Preserves i by decide runs Nat.decidableForallFin r times
across c, taking O(r · |c|) reductions and exceeding the default maxRecDepth once r
reaches a few hundred registers. Likewise, synthesizing Decidable c.ReadsWidth walks the full
syntax tree of c in the elaborator before kernel reduction can run.
This module provides single-pass O(|c|) structural reflections:
Cslib.WordRAM.Code.preservesAll : (Fin r → Bool) → Code B r → Bool: single-passBoolcheck evaluating a predicate only on the destination registers written insidec.Cslib.WordRAM.Code.writeStart/Cslib.WordRAM.Code.writeEnd: minimum and strict upper bound (max + 1) of written register indices using small-ℕminandmax.Cslib.WordRAM.Code.readsWidthBool : Code B r → Bool: reflectedBoolcheck equivalent toCode.ReadsWidth.
Main definitions #
Cslib.WordRAM.Op.preservesAll,Cslib.WordRAM.Code.preservesAll: single-passBoolregister-preservation check.Cslib.WordRAM.Op.writeStart,Cslib.WordRAM.Op.writeEnd,Cslib.WordRAM.Code.writeStart,Cslib.WordRAM.Code.writeEnd: contiguous register-write interval bounds.Cslib.WordRAM.Op.readsWidthBool,Cslib.WordRAM.Code.readsWidthBool: reflected width-read check.
Main results #
Cslib.WordRAM.Code.preservesAll_eq_true_iff,Cslib.WordRAM.Code.preserves_of_preservesAllPred,Cslib.WordRAM.Code.preservesAll_rename_of_false: soundness, completeness, and renamed-bank elimination forpreservesAll.Cslib.WordRAM.Code.preserves_of_writeStart,Cslib.WordRAM.Code.preserves_of_writeEnd: interval register-preservation bounds.Cslib.WordRAM.Code.readsWidthBool_eq_true_iff,Cslib.WordRAM.Code.not_readsWidth_of_readsWidthBool: reflected width-independence rules.
o.readsWidthBool = true holds iff o.ReadsWidth.
Single-pass Bool preservation predicate (preservesAll) #
Single-pass Bool check over Fin r: returns true iff no instruction of c writes a
register d with keep d = true. Unlike Nat.decidableForallFin, this visits c once and
evaluates keep only on written destinations (O(|c|) instead of O(r · |c|)).
Drop-in replacement for ∀ i : Fin r, P i → c.Preserves i := by decide: evaluates P only on
the destination registers written inside c, never iterating over all r elements of Fin r.
preservesAll on a renamed subprogram is true without unfolding the callee whenever the
register bank f is disjoint from keep.
Interval bounds (writeStart / writeEnd) #
Every register strictly below lo is preserved when lo ≤ c.writeStart.
Reflected readsWidthBool and compositional rules #
c.readsWidthBool = true holds iff c.ReadsWidth.
Soundness for the reflected width check.
Register renaming preserves readsWidthBool without unfolding c.