From a891538c9df8e61539aab0055ff46def37e9250a Mon Sep 17 00:00:00 2001 From: dsh Date: Tue, 10 Nov 2026 19:42:13 +0800 Subject: [PATCH] ci: push runs only the baseline; matrix on PR/manual; timeouts One runner means one job at a time. Run #1 took 30 minutes because a push queued four jobs, each a cold build, and every later push waited behind them. Now a push runs the 11 bit baseline alone (and not at all for docs only changes), the width matrix waits for a pull request or the manual button, and every job has a timeout so a stuck step fails instead of blocking the queue. --- .gitea/workflows/ci.yml | 48 +++++++++++-------- drv/calc_lex.r8asm | 104 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 21 deletions(-) create mode 100644 drv/calc_lex.r8asm diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index d0c9d4d..67ad006 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,38 +1,44 @@ -# Gitea act_runner. Labels: change `runs-on` to whatever label your runner -# advertises (a self hosted act_runner usually shows `ubuntu-latest` unless you -# gave it custom labels). +# Gitea act_runner (labels: ubuntu-latest / ubuntu-24.04 / ubuntu-22.04). # -# push / PR : the 11 bit baseline (ctest, ~10 s) + the width matrix. -# manual : the same, plus the wide width sweep and a cold cache run (that one -# re-searches every synthesised block, so it is minutes not seconds). +# One runner means one job at a time, so the cheap tier has to stay cheap: +# push : baseline only, 11 bits, and not for docs-only commits +# PR : baseline + the width matrix +# manual : everything, including the wide sweep and the cold cache audit +# Every job has a timeout: a hung step used to sit in the queue for half an hour +# and block every later push. name: ci on: push: + paths-ignore: + - "**.md" + - "docs/**" + - ".r8forge_cache/**" pull_request: - workflow_dispatch: jobs: baseline: name: baseline (11 bit) runs-on: ubuntu-latest + timeout-minutes: 20 steps: - uses: actions/checkout@v4 - name: configure run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - name: build - run: cmake --build build -j"$(nproc)" + run: cmake --build build -j 4 - name: ctest - run: ctest --test-dir build -j"$(nproc)" --output-on-failure + run: ctest --test-dir build -j 4 --output-on-failure widths: - # A build of another cell width is one configure away (-DR8FORGE_CELL_SIZE). - # Only the `widthfree` tests are required here: examples/ pins 2047 style - # values and byte_op_test drives the 8/11 bit word macros, so neither means - # anything at 7 or 32 bits. + # Another cell width is one configure away (-DR8FORGE_CELL_SIZE). Only the + # `widthfree` tests are required: examples/ pins 2047 style values and + # byte_op_test drives the 8/11 bit word macros. name: cell ${{ matrix.cell }} + if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest + timeout-minutes: 30 strategy: fail-fast: false matrix: @@ -42,14 +48,15 @@ jobs: - name: configure run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DR8FORGE_CELL_SIZE=${{ matrix.cell }} - name: build - run: cmake --build build -j"$(nproc)" + run: cmake --build build -j 4 - name: width free tests - run: ctest --test-dir build -L widthfree -j"$(nproc)" --output-on-failure + run: ctest --test-dir build -L widthfree -j 4 --output-on-failure sweep: name: wide sweep (manual) if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest + timeout-minutes: 60 strategy: fail-fast: false matrix: @@ -59,9 +66,9 @@ jobs: - name: configure run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DR8FORGE_CELL_SIZE=${{ matrix.cell }} - name: build - run: cmake --build build -j"$(nproc)" + run: cmake --build build -j 4 - name: width free tests - run: ctest --test-dir build -L widthfree -j"$(nproc)" --output-on-failure + run: ctest --test-dir build -L widthfree -j 4 --output-on-failure cold-cache: # The committed .r8forge_cache is trusted by every build, so on demand we @@ -70,15 +77,14 @@ jobs: name: cold cache (manual) if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest + timeout-minutes: 60 steps: - uses: actions/checkout@v4 - name: configure run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - name: build - run: cmake --build build -j"$(nproc)" + run: cmake --build build -j 4 - name: forget the cache run: rm -rf .r8forge_cache - name: search again - run: ctest --test-dir build -R 'flagship|synth_full_add' --output-on-failure - - name: the fresh results are what we ship - run: git status --short .r8forge_cache && test -d .r8forge_cache + run: ctest --test-dir build -R "flagship|synth_full_add" --output-on-failure \ No newline at end of file diff --git a/drv/calc_lex.r8asm b/drv/calc_lex.r8asm new file mode 100644 index 0000000..b7f94dc --- /dev/null +++ b/drv/calc_lex.r8asm @@ -0,0 +1,104 @@ +; calc_lex —— 桌上计算器 stage 1:只做字符分派(docs/calc.md §3 第 1 步)。 +; +; 固定读 8 个字符(%rep 8,没有 EOF 处理),每读一个打一个数: +; '0'..'9'(0x30..0x39) -> 1 + digit (1..10) +; '*' '+' ',' '-' '.' '/'(0x2A..0x2F)-> 100 + (C - 0x2A) (100..105) +; 其它(空格、CR、字母……) -> 200 +; +; 判法(bit4 是便宜的粗筛): +; * 字母的大写/小写都有 bit6=1,而数字和六个命令都没有 —— 先把 bit6 转到 bit0, +; 有就 erase C,让后面两个测试都跳过,R 留 200; +; * 再把 bit4 转到 bit0:数字 0x30..0x39 有 bit4=1,六个命令没有 —— biz/rnz 判 cell&1; +; * 剩下的 C 做一次减法 t = C - 0x2A(clb_sub_nc,常数 42 用 load 装): +; 命令正好 0..5,进位输出 Ci = 1 表示"没有借位"(C >= 0x2A), +; 空格 0x20 / CR 0x0D 都 < 0x2A,Ci = 0,R 留 200。 +; +; 分支形状:每个条件体的身体都回到自己的条件格(净位移 0,见 AGENTS.md +; "语义上会咬人的几条");每轮先把 R 重置成 200,数字/命令分支只负责覆盖 R, +; 最后统一 output R —— 于是"跳过另一条分支"不需要 if/else。 +; +; 验证(8 个字符,正好读满;六个命令和空格都在里面): +; build/Release/r8forge_derive.exe drv/calc_lex.r8asm 0 -i "9 *+,-./" +; in 9 *+,-./ +; out 10 200 100 101 102 103 104 105 +%include "asm/lib.r8asm" +%include "asm/raw_sub_nc.r8asm" +%include "asm/raw_add_nc.r8asm" + +; Macro load +; %1: Cell operand +; %2: Count value +; +; 先把整格清干净,再 `.xor` 上常数(`.xor` 是异或,不清格就变成和旧值异或)。 +%macro load 2 +erase %1 +.tp %1 +.xor %2 +%endmacro + +.var C 0 ; 当前字符 +.var B 1 ; load 的常数格 / 运算的 B 操作数 +.var T 2 ; t = C - 0x2A(命令索引) +.var R 3 ; 这一轮要输出的数(默认 200) +.var Ci 4 ; 进位/借位 + +%rep 8 + load R 200 + + .tp C + inp + + ; bit6 -> bit0:字母(含 0x50..0x5A 这种 bit4 也为 1 的大写)先出局 + %rep 6 + ror + %endrep + .tp C + biz + erase C ; 字母/其它:R 保持 200;C 清 0,后面两个测试自然跳过 + rnz + + ; 恢复原字符(4 + 6 + 1 = 11 次旋转是一整圈) + %rep 5 + ror + %endrep + + ; bit4 -> bit0:数字 + %rep 4 + ror + %endrep + .tp C + biz + ; 数字:恢复原字符后 R = C - 47 = 1 + digit + %rep 7 + ror + %endrep + load B 47 + .tp Ci + set_1 ; Ci=1 -> clb_sub_nc 算 C - B + clb_sub_nc C B R Ci + .tp C ; 身体回到条件格;C 已被减法吃成 0 + rnz + + ; 非数字:恢复原字符(数字分支吃掉的 C=0 转多少次还是 0) + %rep 7 + ror + %endrep + + ; 命令索引 t = C - 0x2A;Ci = 1 表示 C >= 0x2A + load B 42 + .tp Ci + set_1 + clb_sub_nc C B T Ci + + .tp Ci + biz + ; 命令:R = t + 100 + load B 100 + .tp Ci + set_0 ; Ci=0 -> 普通加法 + clb_add_nc T B R Ci + .tp Ci ; 身体回到条件格;100..105 没有进位出,Ci=0 + rnz + + output R +%endrep