A fast compiled interpreter for structured word-RAM programs #
Cslib.WordRAM.Code.eval keeps the registers and memory as functions, and each write wraps the
previous function in a Function.update. That shape suits proofs. In compiled code, though, a
read walks back through every earlier write, so a run of n instructions takes Θ(n²) time.
Cslib.WordRAM.Code.evalFast is the same interpreter on Cslib.WordRAM.FastData, which keeps
the registers in a Vector and the written memory cells in a Std.HashMap over the initial
memory. Cslib.WordRAM.Code.evalFast_toData proves that it computes Code.eval, and the
@[csimp] theorem Cslib.WordRAM.Code.eval_eq_evalImpl makes the compiler use it for
Code.eval. This changes only compiled evaluation, such as #eval and #guard regressions over
concrete runs. Code.eval, its lemmas and kernel reduction (decide, rfl) are unchanged.
Import this module where compiled code evaluates long runs. The replacement applies only to callers compiled with this module imported, not to callers compiled before. This module does not certify a runtime bound.
Main definitions #
Cslib.WordRAM.FastData,Cslib.WordRAM.FastData.toData: array-backed machine data and theCslib.WordRAM.Datait represents.Cslib.WordRAM.Code.evalFast: the interpreter onFastData.Cslib.WordRAM.Code.evalImpl:Code.evalcomputed withCode.evalFast.Cslib.WordRAM.Program.runFast,Cslib.WordRAM.Program.runFastList: fast compiled interpreters for flatPrograms onFastData, returning scalar or length-prefixed list outputs.
Main results #
Cslib.WordRAM.Code.evalFast_toData:Code.evalFastcomputesCode.eval.Cslib.WordRAM.Code.eval_eq_evalImpl: proved compiler replacement ofCode.evalbyCode.evalImpl.Cslib.WordRAM.Program.runFast_eq_run:Program.runFastagrees identically withCslib.WordRAM.run.Cslib.WordRAM.Program.runFastList_sound: a haltingProgram.runFastListresult yields a correspondingRuns/step = .haltexecution with the returned length-prefixed array.
Machine data for compiled execution: the registers as a vector, and memory as the cells
written so far over the initial memory base.
The contents of the registers.
The memory cells written so far.
The memory before any write.
Fast data for x, with nothing written yet.
FastData.put agrees with Data.put on the data represented.
Op.evalFast computes Op.eval on the data represented.
The fast loop computes Code.evalLoop when its body does.
Code.evalFast computes Code.eval.
Compiled code evaluates Code.eval with the fast interpreter.
Fast compiled interpreter for flat Programs #
Program.runFast agrees identically with Cslib.WordRAM.run.
A halting Program.runFastList result yields a corresponding halting execution of p from
State.init input whose pre-halt memory holds l as a length-prefixed array at the returned
address v.