Memory allocation and arrays on the word RAM #
Algorithms on the word RAM keep their arrays in memory. This file provides, as ordinary structured programs with exact instruction counts:
Cslib.WordRAM.zeroFill: zeroing a range of cells, in4 k + 2instructions forkcells;Cslib.WordRAM.alloc: allocating a zeroed block ofkcells at a frontier that only grows, in4 k + 7instructions. Addresses are never reused, so blocks allocated at different times are disjoint (Cslib.WordRAM.Block.disjoint_of_le); the frontier is the high-water mark of the memory used;Cslib.WordRAM.readAt,Cslib.WordRAM.writeAt: reading and writing the cell at a pointer plus an index, in two instructions each.
None of them adds an instruction to the machine: allocation is a loop of stores, and an indexed
access is an addition followed by a load or a store. The registers they use are parameters, and
Cslib.WordRAM.Block.Realizes relates the contents of a block to a function on its indices.
Main definitions #
Cslib.WordRAM.Block: a block of consecutive cells;Cslib.WordRAM.clear: memory with a range of cells set to0.Cslib.WordRAM.zeroFill,Cslib.WordRAM.alloc,Cslib.WordRAM.readAt,Cslib.WordRAM.writeAt: the programs.
Main results #
Cslib.WordRAM.zeroFill_exec,Cslib.WordRAM.alloc_exec,Cslib.WordRAM.readAt_exec,Cslib.WordRAM.writeAt_exec: their executions, with exact instruction counts.
References #
- MIT–ULB CompGeom Group, Undecidability of tiling with a tromino; allocation by a frontier, the zeroing loop and indexed access are adapted from its accompanying Lean formalization.
Blocks of memory #
Instances For
The block contains the cell at address a.
Instances For
Zeroing a range of cells #
Zero the cells from the address in register cur up to the address in register stop,
counting cur up to stop; registers zero and one hold 0 and 1.
Instances For
Zeroing k cells takes 4 k + 2 instructions: a store, an addition, a branch and a jump per
cell, and a branch and a jump to leave the loop.
Allocation #
Allocation. Allocating a zeroed block of k cells at frontier f takes 4 k + 7
instructions. It sets result to f and frontier and cur to f + k, zero and one to
0 and 1, zeroes the cells f, …, f + k - 1, and leaves all other registers and cells
unchanged.
Arrays #
dst ← (ptr)[idx]: load the cell at the address in ptr plus the index in idx, through the
scratch register tmp.
Instances For
(ptr)[idx] ← src: store register src to the cell at the address in ptr plus the index in
idx, through the scratch register tmp.
Instances For
Additive-basis primitives #
addAdditive d i j sets register d to register i plus register j over
Basis.additive.
Instances For
Zero the cells from the address in register cur up to the address in register stop over
Basis.additive.
Instances For
Allocate a zeroed block of count cells at frontier over Basis.additive.
Instances For
dst ← (ptr)[idx] over Basis.additive.
Instances For
(ptr)[idx] ← src over Basis.additive.