Compiling pointer-machine instructions to word RAM #
Nodes occupy fixed blocks of memory, with zero reserved for null. The compiler implements
pointer access and allocation using ordinary word-RAM instructions. Scalar operations and tests
come with their own word-RAM implementations and costs; no heap operation is assumed implemented.
Field accesses reuse Cslib.WordRAM.readAt and Cslib.WordRAM.writeAt. Allocation uses a
layout-specific initializer: Cslib.WordRAM.alloc zeroes every field, whereas scalar fields
require encode M.undefined, which need not be zero. It also takes six distinct register
parameters, whereas this initializer uses the base and two scratch registers, leaving the
next-free and zero registers unchanged until the final frontier update.
The fixed field list is unrolled, giving the stated layout-dependent constant cost.
Source instructions compile into equally sized code blocks, with jumps directly relocated to the corresponding block. Padding is never executed by a simulated successful run.
A scalar routine returns one value and preserves memory and all other source/administrative registers. Temporary registers may change.
Returned word.
Scalar computation does not change the heap.
Source registers, allocation pointer and null register are preserved except for
dst.
Writing the destination register alone meets the scalar routine's frame contract.
Implementations of the scalar basis in the standard word RAM. The admissibility predicates state any additional headroom needed by scalar routines. They concern scalar operands only; all pointer operations are implemented by the compiler below.
Faithful single-word representation of scalar values.
- op : M.Op → Fin (regCount L) → Fin (regCount L) → Fin (regCount L) → WordRAM.Code WordRAM.Basis.standard (regCount L)
Code for a binary operation, with destination and two operand registers.
- test : M.Test → Fin (regCount L) → Fin (regCount L) → Fin (regCount L) → WordRAM.Code WordRAM.Basis.standard (regCount L)
Code for a predicate, returning zero or one.
Uniform instruction bound for each scalar operation.
Uniform instruction bound for each scalar predicate.
Scalar-operation headroom at a given width.
Scalar-predicate headroom at a given width.
- op_spec (w : ℕ) (o : M.Op) (d a b : Fin (regCount L)) (x : WordRAM.Data (regCount L)) (u v : M.Value) : x.regs a = self.encode u → x.regs b = self.encode v → self.OpSafe w o u v → Cslib.WordRAM.Fits w (self.encode (M.evalOp o u v)) → ∃ (y : WordRAM.Data (regCount L)), WordRAM.ExecWithin w (self.op o d a b) x y (self.opTime o) ∧ ScalarResult d (self.encode (M.evalOp o u v)) x y
Correctness and frame of operation code, including its cost.
- test_spec (w : ℕ) (p : M.Test) (d a b : Fin (regCount L)) (x : WordRAM.Data (regCount L)) (u v : M.Value) : x.regs a = self.encode u → x.regs b = self.encode v → self.TestSafe w p u v → 1 < 2 ^ w → ∃ (y : WordRAM.Data (regCount L)), WordRAM.ExecWithin w (self.test p d a b) x y (self.testTime p) ∧ ScalarResult d (if M.evalTest p u v = true then 1 else 0) x y
Correctness and frame of predicate code, including its cost.
Fill the listed offsets of a fresh record with their initial values. The list is fixed by the source layout, not supplied by the running program.
A null access does nothing; a nonnull access loads the fixed offset before body.
The register/memory part of one source instruction. A test also computes its Boolean answer in a temporary register for the terminal branch.