Documentation

Examples.Ram.ArrayCopy

A compiled non-overlapping array-copy block #

This compiles the body of the reusable named function in Complexity.Computability.Ram.Array.Traversal as a preloaded block. Its code is fixed for every length, word width, and array content. The machine theorems start at the main block with preloaded arrays and the three operands already in registers; they do not claim an uncharged input loader or an execution from the machine's zero-initialized state.

The final halt is executed and counted. The destination and unchanged source are observed in the actual halted machine memory, not only in a source state. Every destination-external word in the source heap is also preserved, while the separate ABI frame relation retains the old stack.

A block entry for the function's body, without a duplicate implementation or a loader. Ordinary calls use the function declaration itself.

Equations
Instances For
    theorem Ram.Examples.ArrayCopy.block_runs {w heapLimit : ℕ} {source destination : Word w} {xs ys : List (Word w)} {s : Source.State w} {start : State w} (hw : 0 < w) (hlen : ys.length = xs.length) (hdisjoint : ArraysDisjoint source xs.length destination xs.length) (hpre : Source.Array.CopyPre heapLimit source destination xs ys s) (hmatch : Source.State.Matches heapLimit 3 s start) (hpc : start.pc = 1) (hheap : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp 3))) (hcodefit : List.length code < 2 ^ w) :
    ∃ (sourceFinal : Source.State w) (finish : State w), TerminatesWithin code (19 * xs.length + 3) start finish ∧ Source.Array.CopyPost heapLimit source destination xs s sourceFinal ∧ Source.State.Observes heapLimit 3 sourceFinal finish ∧ FramePreserved 3 heapLimit start finish

    Run the compiled block and its halt from an already matching, preloaded state at PC 1. The skipped prologue is not included in this block budget.

    theorem Ram.Examples.ArrayCopy.copies_on_machine {w heapLimit : ℕ} {source destination : Word w} {xs ys : List (Word w)} {s : Source.State w} {start : State w} (hw : 0 < w) (hlen : ys.length = xs.length) (hdisjoint : ArraysDisjoint source xs.length destination xs.length) (hpre : Source.Array.CopyPre heapLimit source destination xs ys s) (hmatch : Source.State.Matches heapLimit 3 s start) (hpc : start.pc = 1) (hheap : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp 3))) (hcodefit : List.length code < 2 ^ w) :
    ∃ (finish : State w), TerminatesWithin code (19 * xs.length + 3) start finish ∧ ArrayRep finish.mem source xs ∧ ArrayRep finish.mem destination xs ∧ (∀ (address : Word w), BitVec.toNat address < heapLimit → BitVec.toNat address < BitVec.toNat destination ∨ BitVec.toNat destination + xs.length ≤ BitVec.toNat address → finish.mem address = start.mem address) ∧ finish.regs named.mainReg.remaining = 0 ∧ finish.input = start.input ∧ finish.outputRev = start.outputRev

    The mathematical source list is present at both source and destination in the actual final RAM memory. The frame observation covers every other heap word; it does not equate private target stack words with source memory.