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.
113 lines
5.5 KiB
CMake
113 lines
5.5 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
project(R8Forge)
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
include_directories(include)
|
|
|
|
# The width of a cell. 11 is the project default; the tests and the VMs follow
|
|
# it, so `-DR8FORGE_CELL_SIZE=16` builds an entirely 16 bit toolchain.
|
|
# 32 is the ceiling: the VMs (and ROT-8-viz) store a cell in uint32_t, and the
|
|
# assembler's immediate type is narrower than that anyway. Refuse anything else
|
|
# here so a wrong -DR8FORGE_CELL_SIZE fails at configure time instead of as a
|
|
# C++ error in whichever file happens to shift by the width first.
|
|
set(R8FORGE_CELL_SIZE 11 CACHE STRING "bits per cell (1..32)")
|
|
if(R8FORGE_CELL_SIZE LESS 1 OR R8FORGE_CELL_SIZE GREATER 32)
|
|
message(FATAL_ERROR
|
|
"R8FORGE_CELL_SIZE=${R8FORGE_CELL_SIZE} is out of range: a cell is stored in "
|
|
"uint32_t in every VM, so the supported range is 1..32")
|
|
endif()
|
|
add_compile_definitions(R8FORGE_CELL_SIZE=${R8FORGE_CELL_SIZE})
|
|
|
|
# How many cells the tape holds. 259 is the historical default (a prime ring, so
|
|
# a walked-off-end bug cannot alias onto a power of two); it is a *hardware*
|
|
# knob as much as a software one. Every program we ship peaks well below 64
|
|
# cells (calc 51, hello 49, signed_demo 34, term 27 -- geometry.hh lists the
|
|
# measurements), so `-DR8FORGE_MEMORY_CELLS=64` runs all of them; only the
|
|
# asm/test.r8asm self test, which lays every macro's cell block out side by side,
|
|
# needs the default. The ring is a modulo counter either way, so any size is
|
|
# legal; 1..65536 keeps the VMs' bookkeeping sane.
|
|
set(R8FORGE_MEMORY_CELLS 259 CACHE STRING "cells on the tape (1..65536)")
|
|
if(R8FORGE_MEMORY_CELLS LESS 1 OR R8FORGE_MEMORY_CELLS GREATER 65536)
|
|
message(FATAL_ERROR
|
|
"R8FORGE_MEMORY_CELLS=${R8FORGE_MEMORY_CELLS} is out of range: the ring is "
|
|
"addressed by a 16 bit counter in the physical machine, so the supported "
|
|
"range is 1..65536")
|
|
endif()
|
|
add_compile_definitions(R8FORGE_MEMORY_CELLS=${R8FORGE_MEMORY_CELLS})
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
add_library(r8forge_core src/r8asm.cc src/synth.cc src/tape_opt.cc)
|
|
target_link_libraries(r8forge_core PUBLIC Threads::Threads)
|
|
|
|
# 别再 set(CMAKE_CXX_FLAGS ...) 了:那会把默认 flag 整个换掉,MSVC 下丢 /EHsc、
|
|
# 还会把 -O3 塞进 Debug 和 /RTC1 打架。Release 配置本来就带 -O3 / /O2 和 NDEBUG。
|
|
if(NOT MSVC)
|
|
add_compile_options($<$<CONFIG:Release>:-march=native>)
|
|
endif()
|
|
|
|
add_executable(r8forge tests/asm_test.cc)
|
|
target_link_libraries(r8forge r8forge_core)
|
|
|
|
add_executable(r8forge_synth_test tests/synth_test.cc)
|
|
target_link_libraries(r8forge_synth_test r8forge_core)
|
|
|
|
add_executable(r8forge_derive src/derive.cc)
|
|
target_link_libraries(r8forge_derive r8forge_core)
|
|
|
|
# A second, independent ROT-8 interpreter: runs a .rot8 file with no assembler
|
|
# and no macros involved, so its verdict can be checked against r8forge_derive.
|
|
add_executable(r8forge_tape_run tests/tape_run.cc)
|
|
|
|
# Runs the byte level library macros (raw_add / raw_and / raw_or / raw_xor /
|
|
# raw_inc) over every input combination.
|
|
add_executable(r8forge_byte_op_test tests/byte_op_test.cc)
|
|
target_link_libraries(r8forge_byte_op_test r8forge_core)
|
|
|
|
# Checks that every %macro in asm/ carries a doc comment in the house format.
|
|
add_executable(r8forge_macro_docs_test tests/macro_docs_test.cc)
|
|
|
|
# Runs every examples/*.r8asm as a stand alone program and compares its OUT
|
|
# stream with the `; out ...` line in the file header.
|
|
add_executable(r8forge_examples_test tests/examples_test.cc)
|
|
target_link_libraries(r8forge_examples_test r8forge_core)
|
|
|
|
# The tape level peephole pass: three run-local rules, no bracket bookkeeping.
|
|
add_executable(r8forge_tape_opt tests/tape_opt.cc)
|
|
target_link_libraries(r8forge_tape_opt r8forge_core)
|
|
|
|
add_executable(r8forge_cost_par tests/cost_par.cc)
|
|
target_link_libraries(r8forge_cost_par r8forge_core)
|
|
|
|
add_executable(r8forge_cost_search tests/cost_search.cc)
|
|
target_link_libraries(r8forge_cost_search r8forge_core)
|
|
# ---- tests ------------------------------------------------------------------
|
|
# `ctest --test-dir build -j` runs the whole baseline. Every entry is a program
|
|
# under tests/ that exits non zero on failure; the working directory is the repo
|
|
# root because the drivers use relative paths.
|
|
#
|
|
# Labels: `widthfree` means "true at any cell width" (bit level slices, the
|
|
# synthesizer, the looping demo, the macro comment format). Everything else
|
|
# assumes the default 11 bit geometry -- examples/ fixes 2047 style values and
|
|
# byte_op_test drives the 8/11 bit word macros -- so a CI matrix over
|
|
# -DR8FORGE_CELL_SIZE runs only the widthfree set.
|
|
enable_testing()
|
|
set(R8FORGE_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
add_test(NAME flagship COMMAND r8forge asm/test.r8asm)
|
|
add_test(NAME byte_ops COMMAND r8forge_byte_op_test)
|
|
add_test(NAME examples COMMAND r8forge_examples_test examples)
|
|
add_test(NAME synth_full_add COMMAND r8forge_synth_test examples/full_add.r8asm)
|
|
add_test(NAME bit_add_slice COMMAND r8forge verify_clb_bit_add_nc.r8asm)
|
|
add_test(NAME bit_inc_slice COMMAND r8forge verify_clb_bit_inc_nc.r8asm)
|
|
add_test(NAME loop_derive COMMAND r8forge_derive verify_loop.r8asm -1 0=5)
|
|
add_test(NAME macro_docs COMMAND r8forge_macro_docs_test)
|
|
|
|
set_tests_properties(flagship byte_ops examples PROPERTIES LABELS "default-width")
|
|
set_tests_properties(synth_full_add bit_add_slice bit_inc_slice loop_derive
|
|
macro_docs PROPERTIES LABELS "widthfree")
|
|
set_tests_properties(flagship byte_ops examples synth_full_add bit_add_slice
|
|
bit_inc_slice loop_derive macro_docs
|
|
PROPERTIES WORKING_DIRECTORY ${R8FORGE_TEST_DIR}) |