Name the two geometry numbers the same way everywhere: cell_size, cell_argc

The cell width was CELL_SIZE on the C++ side, and the searcher's CellBit count
was CELL_ARGC.  Both now match what the code and the docs around them already
called them:

  * include/r8forge/r8asm.hh + src/r8asm.cc: CELL_SIZE -> cell_size
    (set_cell_size assigns this->cell_size, its parameter already had that
    name);
  * include/r8forge/r8veritas.hh: the template parameter CELL_ARGC ->
    cell_argc, 34 uses, so the searcher reads r8veritas<cell_argc>;
  * AGENTS.md says which name means what, and why the name .r8asm programs
    see is still _CELL_SIZE: that one belongs to the macro library, not to
    the C++ side, and changing it would rewrite every macro in asm/;
  * the cross check entry now says which ROT-8-viz is which: the author's fork
    with --cell/--mem, and the upstream starcells/ROT-8 tree in the workspace,
    whose geometry is compile time cell_size/mem_size -- it is 11 / 259 too
    now, and `rot8_test <tape>` against `r8forge_derive ... -1` still gives
    1322 1786 1600 5 94 127 on the hash tape.

All six self checks pass unchanged: 28729 character hash tape, synth_test 8/8,
both verify_ tapes, byte_op_test 65536/65536 for clb_mul and the rest of the
library, macro docs test green.
This commit is contained in:
dsh committed 2026-11-07 12:23:42 +08:00
1 parent 6e67eb4678
commit 94868be24f
5 files changed
+57 -48

No files matched your search

+13 -4
View File
@@ -132,7 +132,12 @@ void rot8_rnz(rot8_iter *iter) { if ((*(iter->mem_now) & 1) == 1) { ... } }
曾经这里还写过第三条("多字节 cell 的位读不出来")—— 那是把 `biz` 当成 Brainfuck 的
整格零判断推出来的,**错的**,已删。
## CELL_SIZE 与纸带长度是怎么用的
## cell_size 与纸带长度是怎么用的
位宽叫 **`cell_size`**(一个 cell 多少 bit),纸带长度叫 `kDefaultMemoryCells`;
搜索器里"有多少个 CellBit 形参"叫 **`cell_argc`**(`r8veritas<cell_argc>`)。这三个名字
在两边的仓库里是统一的:C/C++ 侧 `cell_size`、搜索器侧 `cell_argc`、`.r8asm` 程序里看到的
常量仍是 `_CELL_SIZE`(那是源语言的常量,属于宏库的公开词汇,不要跟着改)。
两个默认值集中在 **`include/r8forge/geometry.hh`**,现在是 **11 位 / 259 格**:
@@ -167,9 +172,13 @@ inline constexpr uint32_t kDefaultCellMask = (1u << kDefaultCellBits) - 1u;
`fibonacci` 8761 → **11959**。写死的长度断言要跟着改。
* **`output` 打印整个 cell 的值**,不再是一个字节;`out` 里出现 257、1088 这种数是对的
(`127+130 = 257`、`200*200 = 19*2048 + 1088`)。
* **交叉验证要先对齐几何**:`ROT-8-viz` 现在默认也是 **11 位 / 259 格**(`--cell` / `--mem`
可改)。几何一致时同一条纸带输出完全相同(`asm/test.r8asm` 两边都是
`1322 1786 1600 5 94 127`);不一致时不是谁错了,是两台不同的机器。
* **交叉验证要先对齐几何**:几何一致时同一条纸带输出完全相同(`asm/test.r8asm` 两边都是
`1322 1786 1600 5 94 127`);不一致时不是谁错了,是两台不同的机器。作者那份 `ROT-8-viz`
(`C:\Users\peng0\git\ROT-8-viz`)默认 11 位 / 259 格,`--cell` / `--mem` 可改;
**workspace 里另有一份 `ROT-8-viz/`,那是 upstream `starcells/ROT-8` 的 `feat/memory-viz`
分支**,几何是编译期常量(`cell_size` / `mem_size`,在 `include/rot8/rot8.h`),现在也是
**11 位 / 259 格**。对答案的办法:`ROT-8-viz/build/Release/rot8_test.exe <tape.rot8>` 把每个
`OUT` 按行打出来,和 `r8forge_derive <src.r8asm> -1` 的 `out` 逐位比即可。
* 位宽变大还有个正面效果:`fibonacci` 不再在 256 处回绕,现在跑出 **13 项**(到 233)。
* **旧 tape 换到新位宽上不只是算错,还可能永远跑不完**:按 8 位写死的程序里
`%rep 8` 只转了 8 圈,在 11 位下 cell 没转回原位,"循环到某位清零"的条件于是永远不成立。
+2 -2
View File
@@ -104,8 +104,8 @@ private:
class ast {
public:
ast_node root = {r8asm::ast_node_t::CODEBLOCK, "", {}};
size_t CELL_SIZE;
// I know template class is the most elegant solution of CELL_SIZE
size_t cell_size;
// I know template class is the most elegant solution of cell_size
// but I can't be bother to add that.
// The assembler has no exceptions: anything that cannot be assembled
+34 -34
View File
@@ -23,7 +23,7 @@
// Search strategy:
// * only the input bits that influence the answer survive (the old
// compress_stat_space), so a plane is a 2^K bit truth table instead of
// 2^CELL_ARGC, and the whole state is CELL_ARGC * 2^K bits
// 2^cell_argc, and the whole state is cell_argc * 2^K bits
// * forward BFS keeps every reachable state of depth < d plus the block
// that produced it
// * the last block is not searched forward. A block clears its own
@@ -56,10 +56,10 @@
#include <utility>
#include <vector>
template <int CELL_ARGC> class r8veritas {
template <int cell_argc> class r8veritas {
public:
using cell = uint8_t;
using stat = std::array<cell, (size_t(1) << CELL_ARGC)>;
using stat = std::array<cell, (size_t(1) << cell_argc)>;
using stat_ref = const stat *;
using truthtable = std::pair<stat_ref, stat_ref>;
using op = std::function<cell(cell)>;
@@ -85,7 +85,7 @@ public:
// set_1. The inter-block hop from the previous sacrifice back to this one
// is not in the model -- the emitter charges it afterwards.
struct cost_options {
std::array<int, CELL_ARGC> addr{}; // cell address of each plane
std::array<int, cell_argc> addr{}; // cell address of each plane
int max_cost = 4096; // give up above this tape length
size_t max_states = 600'000'000;
unsigned threads = 0; // 0 = one worker per hardware thread
@@ -113,16 +113,16 @@ public:
std::string message;
};
std::array<std::string, CELL_ARGC> nicknames;
std::array<std::string, CELL_ARGC> tp_paths;
std::array<std::string, cell_argc> nicknames;
std::array<std::string, cell_argc> tp_paths;
void initialize_nicknames() {
for (int i = 0; i < CELL_ARGC; i++)
for (int i = 0; i < cell_argc; i++)
nicknames[i] = "%" + std::to_string(i + 1);
}
void initialize_tp_paths() {
for (int i = 0; i < CELL_ARGC; i++)
for (int i = 0; i < cell_argc; i++)
tp_paths[i] = ".tp " + nicknames[i];
}
@@ -135,7 +135,7 @@ public:
truthtable generate_truthtable(const op &operation) {
stat in{}, out{};
for (size_t i = 0; i < (size_t(1) << CELL_ARGC); i++) {
for (size_t i = 0; i < (size_t(1) << cell_argc); i++) {
in[i] = cell(i);
out[i] = operation(cell(i));
}
@@ -152,13 +152,13 @@ public:
// starts from a canonical state.
truthtable compress_stat_space(const truthtable &raw) {
stat start = *raw.first;
for (int i = 0; i < CELL_ARGC; i++) {
for (int i = 0; i < cell_argc; i++) {
bool influences = false;
for (size_t j = 0; j < (size_t(1) << CELL_ARGC); j++)
for (size_t j = 0; j < (size_t(1) << cell_argc); j++)
if ((*raw.second)[j] != (*raw.second)[j ^ (size_t(1) << i)])
influences = true;
if (!influences)
for (size_t j = 0; j < (size_t(1) << CELL_ARGC); j++)
for (size_t j = 0; j < (size_t(1) << cell_argc); j++)
start[j] = cell(start[j] & ~(1u << i));
}
return {keep(start), raw.second};
@@ -173,7 +173,7 @@ public:
for (size_t j = 0; j < cur.size(); j++)
if (cur[j] & (1u << i.sacrifice)) {
cur[j] = cell(cur[j] & ~(1u << i.sacrifice));
for (int b = 0; b < CELL_ARGC; b++)
for (int b = 0; b < cell_argc; b++)
if (i.mask & (1 << b))
cur[j] = i.or_mode ? cell(cur[j] | (1u << b))
: cell(cur[j] ^ (1u << b));
@@ -189,7 +189,7 @@ public:
// ---------------------------------------------------------------- output
void output_stat(const stat &s) const {
for (auto v : s)
std::cout << std::bitset<CELL_ARGC>(v).to_string() << " ";
std::cout << std::bitset<cell_argc>(v).to_string() << " ";
}
void output_ins(const instruction &ins, std::ostream &os,
@@ -199,7 +199,7 @@ public:
if (ins.mask) {
os << (ins.or_mode ? ", SET1: {" : ", FLIP: {");
bool first = true;
for (int b = 0; b < CELL_ARGC; b++)
for (int b = 0; b < cell_argc; b++)
if (ins.mask & (1 << b)) {
if (!first)
os << ',';
@@ -213,7 +213,7 @@ public:
}
os << tp_paths[ins.sacrifice] << "\n";
os << "biz\n";
for (int b = 0; b < CELL_ARGC; b++)
for (int b = 0; b < cell_argc; b++)
if (ins.mask & (1 << b)) {
os << '\t' << tp_paths[b] << "\n";
os << '\t' << (ins.or_mode ? "set_1" : "flb") << "\n";
@@ -242,10 +242,10 @@ public:
return r;
};
std::array<int, CELL_ARGC> bit_of{};
std::array<int, cell_argc> bit_of{};
int k = 0;
for (int i = 0; i < CELL_ARGC; i++)
for (size_t j = 0; j < (size_t(1) << CELL_ARGC); j++)
for (int i = 0; i < cell_argc; i++)
for (size_t j = 0; j < (size_t(1) << cell_argc); j++)
if ((*raw.second)[j] != (*raw.second)[j ^ (size_t(1) << i)]) {
bit_of[k++] = i;
break;
@@ -289,10 +289,10 @@ public:
};
// which input bits matter, in compression order
std::array<int, CELL_ARGC> bit_of{};
std::array<int, cell_argc> bit_of{};
int k = 0;
for (int i = 0; i < CELL_ARGC; i++) {
for (size_t j = 0; j < (size_t(1) << CELL_ARGC); j++)
for (int i = 0; i < cell_argc; i++) {
for (size_t j = 0; j < (size_t(1) << cell_argc); j++)
if ((*raw.second)[j] != (*raw.second)[j ^ (size_t(1) << i)]) {
bit_of[k++] = i;
break;
@@ -336,10 +336,10 @@ private:
// ---------------------------------------------------------------- engine
// K relevant inputs: every plane is a 2^K bit truth table, the whole state
// is CELL_ARGC * 2^K bits packed into KEYW words.
// is cell_argc * 2^K bits packed into KEYW words.
template <int K> struct engine {
static constexpr int M = 1 << K; // bits per plane
static constexpr int KEYW = (CELL_ARGC * M + 63) / 64;
static constexpr int KEYW = (cell_argc * M + 63) / 64;
static constexpr uint64_t PMASK =
(M >= 64) ? ~uint64_t(0) : ((uint64_t(1) << (M & 63)) - 1);
using key = std::array<uint64_t, KEYW>;
@@ -364,7 +364,7 @@ private:
key n = k;
const uint64_t c = get(k, i.sacrifice);
put(n, i.sacrifice, 0);
for (int b = 0; b < CELL_ARGC; b++)
for (int b = 0; b < cell_argc; b++)
if (i.mask & (1 << b))
put(n, b, i.or_mode ? (get(k, b) | c) : (get(k, b) ^ c));
return n;
@@ -456,7 +456,7 @@ private:
for (size_t i = 0; i < insns.size(); i++) {
const instruction &in = insns[i];
int lo = opt.addr[in.sacrifice], hi = lo, cnt = 0;
for (int b = 0; b < CELL_ARGC; b++)
for (int b = 0; b < cell_argc; b++)
if (in.mask & (1 << b)) {
cnt++;
lo = std::min(lo, opt.addr[b]);
@@ -470,7 +470,7 @@ private:
// start = identity over the compressed inputs, goal = the target
key start = E::zero(), goal = E::zero();
for (size_t j = 0; j < full.size(); j++)
for (int b = 0; b < CELL_ARGC; b++) {
for (int b = 0; b < cell_argc; b++) {
if (j & (size_t(1) << b))
E::put(start, b, E::get(start, b) | (uint64_t(1) << j));
if ((*raw.second)[full[j]] & (1u << b))
@@ -675,7 +675,7 @@ private:
// start = identity over the compressed inputs, goal = the target
key start = E::zero(), goal = E::zero();
for (size_t j = 0; j < full.size(); j++)
for (int b = 0; b < CELL_ARGC; b++) {
for (int b = 0; b < cell_argc; b++) {
if (j & (size_t(1) << b))
E::put(start, b, E::get(start, b) | (uint64_t(1) << j));
if ((*raw.second)[full[j]] & (1u << b))
@@ -794,10 +794,10 @@ private:
const instruction &ins, uint64_t c,
typename E::key pre, int b, F &f) {
using key = typename E::key;
for (; b < CELL_ARGC; b++)
for (; b < cell_argc; b++)
if (ins.mask & (1 << b))
break;
if (b == CELL_ARGC)
if (b == cell_argc)
return f(pre);
const uint64_t T = E::get(post, b);
@@ -821,13 +821,13 @@ private:
// ---------------------------------------------------------------- syntax
std::vector<instruction> build_instructions() const {
std::vector<instruction> out;
out.reserve(CELL_ARGC * (2 * (1 << (CELL_ARGC - 1)) + 1));
for (int s = 0; s < CELL_ARGC; s++) {
out.reserve(cell_argc * (2 * (1 << (cell_argc - 1)) + 1));
for (int s = 0; s < cell_argc; s++) {
out.push_back({uint8_t(s), 0, false}); // pure sacrifice: clear plane s
for (int sub = 1; sub < (1 << (CELL_ARGC - 1)); sub++) {
for (int sub = 1; sub < (1 << (cell_argc - 1)); sub++) {
uint8_t m = 0;
int bit = 0;
for (int b = 0; b < CELL_ARGC; b++)
for (int b = 0; b < cell_argc; b++)
if (b != s)
m |= uint8_t(((sub >> bit++) & 1) << b);
out.push_back({uint8_t(s), m, false});
+7 -7
View File
@@ -65,9 +65,9 @@ std::string peel(std::string &str) { // Peel the first word from string.
#undef OPERATORS
void r8asm::ast::set_cell_size(size_t cell_size) {
CELL_SIZE = cell_size;
this->cell_size = cell_size;
// the names a .r8asm program sees stay as they were: _CELL_SIZE is the
// machine word width in bits (CELL_SIZE on the C++ side)
// machine word width in bits (cell_size on the C++ side)
scopes = {{{"_CELL_SIZE", static_cast<general_data>(cell_size)},
{"_CELL_MAX", static_cast<general_data>((1 << cell_size) - 1)},
{"_ROL_STEP", static_cast<general_data>(cell_size - 1)}}};
@@ -259,10 +259,10 @@ r8asm::ast_node r8asm::ast::expand_node_to_ins(const ast_node &node) {
/*
XOR
children[0]: argument
WARNING: argument bigger than ((1<<CELL_SIZE)-1) will be cut off
WARNING: argument bigger than ((1<<cell_size)-1) will be cut off
e.g.
children[0] -> 5(0b101)
when define CELL_SIZE 2, only the last 2 bit will be noticed,
when define cell_size 2, only the last 2 bit will be noticed,
and 5 means 0b01(1) here.
then the node will be expanded like this:
@@ -438,7 +438,7 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
filename += tp->value;
// now tp points at RQUOTE
import_file(filename, main_tree.CELL_SIZE);
import_file(filename, main_tree.cell_size);
// import_file has already said why if it failed; the error flag is
// set, so this file will not be reported as assembled.
} break;
@@ -588,7 +588,7 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
main_tree.fail("%synth '" + name +
"': cannot write the synthesised macro anywhere");
} else {
import_file(path, main_tree.CELL_SIZE);
import_file(path, main_tree.cell_size);
std::remove(path.c_str());
}
}
@@ -894,7 +894,7 @@ bool r8asm::import_file(const std::string &filename, size_t cell_size) {
return (false);
}
// Before parsing: %include asks main_tree.CELL_SIZE for the width to hand
// Before parsing: %include asks main_tree.cell_size for the width to hand
// to the included file, and that used to answer 0 because the size was
// only set at the end of this function.
main_tree.set_cell_size(cell_size);
+1 -1
View File
@@ -57,7 +57,7 @@ r8asm_synth_run(const std::vector<int> &in, const std::vector<int> &out,
// ---- cache: the target table is what the search is given, so it is the
// identity of the problem. Keying on it (rather than on the map or the stat
// line the author wrote) means two blocks that describe the same table share
// one entry, and a table of a different CELL_SIZE can never collide with it
// one entry, and a table of a different cell_size can never collide with it
// because the key covers every entry.
// bump kModelVersion whenever the instruction model changes, otherwise a
// table could be served a program that was optimal for the old model