Two separate things hid behind "32 bit works": * tests/byte_op_test.cc could not compile at 32 bits at all (`1 << 32` in a constexpr plus an int typed mask), so the whole 32 bit build stopped there -- only `r8forge` and the core library came out. kCellMod is now clamped at 31+ bits and main() prints "skipped" above 16 bits (every sweep there is 2^W rows) and exits green. All ten targets build at 32 bits with MSVC, and the same tree builds clean on a Gentoo box with GCC 16 -- the missing <cstring> in asm_test.cc that stopped GCC first is in the previous commit. * the digit drivers hardcoded a 4 cell window, so byte_op_test's digits / digits_signed / undigits failed at every other width (16 bits wants 5 digits, 8 bits 3). drv/digits.r8asm, drv/digits_signed.r8asm and drv/undigits_byte.r8asm now derive D = _CELL_SIZE * 30103 / 100000 + 1 and space their cells by it, and the C++ side uses the same kDigits instead of a literal 4 (including the T/F cells clb_digits_signed leaves behind). With that, byte_op_test passes at 8, 11 and 16 bits (the 16 bit run takes about 450 s) and above 16 it skips. Two more width bugs fell out on the way: the divmod divisor sweep used 1000 and 2047 unconditionally (they wrap at 8 bits), and the undigits garbage guard OR'ed in bits above the cell, which at 8 bits turned '0'+digit into a value over 255. test_divmod_signed also divided by the recovered divisor without re-checking it, and at 8 bits the boundary value 1024 wraps to 0 -- that was a hard crash (divide by zero), not a failure. CMakeLists.txt now refuses -DR8FORGE_CELL_SIZE outside 1..32 at configure time; the range used to be a comment, so an out of range width was discovered as a compiler error in whichever file shifted by it first. geometry.hh and SPEC section 13 record that 32 is the ceiling because every VM stores a cell in uint32_t -- going further means widening all five VMs, the assembler's immediate type and ROT-8-viz's rot8_data. Also recorded there: the %synth cache is keyed by the truth table, not the width, so a 32 bit build hits the committed entries (0.4 s for the flagship tape of 227075 characters). A full cold rebuild takes ~500 s on a 44 thread machine, 479 s of which is the single 6 parameter full adder table.
96 lines
4.5 KiB
CMake
96 lines
4.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})
|
|
|
|
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}) |