259 was never part of the machine, just the historical default, so kDefaultMemoryCells is now R8FORGE_MEMORY_CELLS (1..65536, default 259) with a range guard in CMake, the same way the cell width already worked. All five VMs read it from geometry.hh, so nothing else had to change. Measured the highest cell each tape in the tree actually touches by walking its > and < and recording the peak (no tape does a < at cell 0, so none of them depend on wrapping): calc 51, hello 49, signed_demo 34, term 27, and the asm/test.r8asm self test 155, because it lays every macro cell block out side by side. So a 64 cell ring runs every program we ship; only the self test needs the default. Verified: the full ctest suite is 8/8 at both 128 and 64 cells (11 bit); at the hardware geometry of 8 bit plus 64 cells the widthfree label is 5/5, and the calculator tape is byte for byte identical to the 259 cell build and its sessions take the same 166348 steps. The self test also produces identical output at 64 cells but 216 more steps, because its high cells fold back onto low ones -- which is why SPEC section 1.2 states the rule: ring size must be at least the highest cell a program touches plus one. Hardware payoff: at 64 cells dp is a 6 bit counter whose wrap is free, so the TTL build loses its modulo-259 comparator logic (four to five chips), the RAM needs 64 bytes, and the drum shrinks to 8 tracks by 64 cells (at 3000 rpm that is 52 s for a calculator session, so it wants to spin faster). hardware.md is updated to the 8 bit / 64 cell machine throughout.
27 lines
1.7 KiB
C++
27 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
// Machine geometry the tools use unless something says otherwise: how wide a
|
|
// cell is in bits, and how many cells the tape holds. The instruction set does
|
|
// not fix either (ROR just rotates inside a cell and the tape is a ring), so
|
|
// these are the only places the old 8 bit / 256 cell assumptions live.
|
|
inline constexpr size_t kDefaultCellSize = R8FORGE_CELL_SIZE; // build option: -DR8FORGE_CELL_SIZE=<1..32>
|
|
inline constexpr size_t kDefaultMemoryCells = R8FORGE_MEMORY_CELLS; // build option: -DR8FORGE_MEMORY_CELLS=<1..65536>
|
|
// The ring size is a *hardware* decision as much as a software one: the physical
|
|
// machine only has to hold the highest cell a program ever touches. Measured on
|
|
// every program we ship (a script walks the tape's > and < and records the peak):
|
|
// calc 51, hello 49, signed_demo 34, term 27 -- so a 64 cell ring runs all of
|
|
// them, and 259 was only ever the historical default. The one exception is
|
|
// asm/test.r8asm, the "every macro once" self test, which lays every macro's
|
|
// cell block out side by side and peaks at 155; it needs the default.
|
|
// The VMs store a cell in uint32_t, so 32 bits is the ceiling -- and `1u << 32`
|
|
// would be undefined, hence the special case instead of a plain shift. CMake
|
|
// refuses anything outside 1..32 at configure time, and the exhaustive byte
|
|
// level test prints "skipped" instead of running above 16 bits (its sweeps are
|
|
// 2^W rows). Going past 32 would mean widening the cell in all five VMs *and*
|
|
// in ROT-8-viz's rot8_data -- SPEC §13 has the checklist.
|
|
inline constexpr uint32_t kDefaultCellMask =
|
|
kDefaultCellSize >= 32 ? 0xFFFFFFFFu : (1u << kDefaultCellSize) - 1u;
|