The rotation based byte layer never ran. Measured with r8forge_derive -2:
raw_add A=0,B=0 / 1+1 / 3+5 / 1+0 out empty (step limit hit)
raw_add A=127,B=130 out 0 0 0 0 0, everything destroyed
raw_and 0xF0 and 0xCC, 1 and 1, 0 and 5 out empty
copy A=5 out empty (A=0 returns fine)
Not "only operand preservation is missing": set_0 (= [-]) cannot clear a cell
that holds more than one bit, and biz only answers "is this whole cell zero",
because ror does not change zero-ness. So the bits of a packed byte are
unreadable, and the whole ror + set_0 layer has no future. The docs now say
that instead of blaming operand preservation.
What replaces it is one bit per cell:
asm/byte_add.r8asm 8 bit adder. Bit i owns four adjacent cells at base+4i:
A, B, carry (in -> out), scratch. The synthesised four
cell slice bit_raw_add_nc does the bit, clb_bit_mov moves
the carry into the next quartet. A doubles as the
accumulator, so calling byte_add again continues the sum.
asm/pack_byte.r8asm eight flags -> one byte, the only direction that works.
bit_raw_flip_if consumes a flag into flipping bit 0 of an
accumulator that may already hold bits (no set_0 there).
examples/add8.r8asm a+b, 1308 characters. A shared carry cell layout needs
only 25 cells but was measured at 2517: paying .tp travel
eight times beats saving seven carry cells.
examples/add8_inc.r8asm add 1 three times, proving the block composes.
tests/byte_add_test.cc r8forge_byte_add_test: runs the tapes on the ROT-8
machine over every input pair, 0.3 s.
Also: AGENTS.md gains the measurement table, the third instruction set
constraint (packed bytes are unreadable), the new files, and the note that
build/ has to be rebuilt with the VS bundled cmake -- scoop's 4.4 reconfigures
it and dies with "No preprocessor test for PellesC".
38 lines
1.2 KiB
CMake
38 lines
1.2 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
project(R8Forge)
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
include_directories(include)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
add_library(r8forge_core src/r8asm.cc src/synth.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)
|
|
|
|
# Runs the byte level adders over every input combination.
|
|
add_executable(r8forge_byte_add_test tests/byte_add_test.cc)
|
|
target_link_libraries(r8forge_byte_add_test 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)
|