Documentation

Examples.Ram.LocalCalls

A small callee in a program with a large unrelated frame #

The fixed main program reads a word into register 0, keeps 99 in register 1, calls a one-local increment function into register 2, and writes all three registers. The callee overwrites register 0: its restoration is observable in the first output. Register 1 lies above the callee's local bound: its preservation is observable in the second output.

A second, uncalled function has an arbitrary local bound. Enlarging that function or the reserved-register boundary changes neither the executed source program nor its 36 actual RAM transitions. The linked code includes the uncalled function once, so its static size does grow. Counts below are derived from the generated instruction lists and closed compiler simulation. The increment is word arithmetic, including modular wraparound.

Equations
Instances For

    Neither the input word nor either register bound occurs in this AST.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          Equations
          Instances For

            The callee actually changes its parameter; this is not a no-op call.

            The number comes from actual save/initialize/restore instruction lists, the compiled assignment, and both control transfers.

            theorem Ram.Examples.LocalCalls.call_measured {w : Nat} (control spareLocals H : Nat) (n : Word w) :
            Source.LocalMeasuredExec control (program spareLocals) H 1 (Stmt.call [2] 0 [Expr.var 0]) 25 (beforeCall n) (afterCall n)
            theorem Ram.Examples.LocalCalls.main_measured {w : Nat} (control spareLocals H : Nat) (n : Word w) :

            Source execution is constructed from ordinary read, assignment, call, and write rules, not by evaluating a bounded machine runner.

            theorem Ram.Examples.LocalCalls.valid {control spareLocals : Nat} (hcontrol : 3 ≤ control) (hspare : spareLocals ≤ control) :
            LocalCompiler.Valid control (program spareLocals) main
            def Ram.Examples.LocalCalls.code (control spareLocals : Nat) :

            This code is fixed before the input word is supplied.

            Equations
            Instances For
              theorem Ram.Examples.LocalCalls.compile_checked {control spareLocals : Nat} (hcontrol : 3 ≤ control) (hspare : spareLocals ≤ control) :
              LocalCompiler.compileChecked control (program spareLocals) main = some (code control spareLocals)
              theorem Ram.Examples.LocalCalls.code_length (control spareLocals : Nat) :
              List.length (code control spareLocals) = 3 * spareLocals + 42

              Uncalled functions still occupy code memory, even though they contribute no runtime frame work. The two quantities are deliberately kept separate.

              theorem Ram.Examples.LocalCalls.runs {w : Nat} (control spareLocals H : Nat) (n : Word w) (hcontrol : 3 ≤ control) (hspare : spareLocals ≤ control) (hcodefit : 3 * spareLocals + 42 < 2 ^ w) (hstackfit : H + (control + 1) < 2 ^ w) :
              ∃ (finish : State w), Exec (code control spareLocals) 36 (State.initial [BitVec.ofNat w H, n]) finish ∧ finish.status = Status.halted ∧ finish.output = [n, 99#w, n + 1] ∧ finish.input = []

              Exact full execution for arbitrary word input and arbitrary unrelated function size. The first input word is the ordinary counted ABI heap header. Only the sufficient address-space conditions depend on the reserved bound.

              theorem Ram.Examples.LocalCalls.runs_with_large_unused {w : Nat} (control H : Nat) (n : Word w) (hcontrol : 200 ≤ control) (hcodefit : 642 < 2 ^ w) (hstackfit : H + (control + 1) < 2 ^ w) :
              ∃ (finish : State w), Exec (code control 200) 36 (State.initial [BitVec.ofNat w H, n]) finish ∧ finish.status = Status.halted ∧ finish.output = [n, 99#w, n + 1] ∧ finish.input = []

              In particular, reserving at least 200 registers because of an unrelated function does not make the one-local call save or restore 200 registers.