Skip to content

Commit e43e12e

Browse files
Dmitrii Vasilevclaude
andcommitted
feat(igla): Wave Loop 763 — module-scope [345][2]^6 Pt non-power-of-two outer-dimension array-of-struct variable from call with indexed signed writes
Closes #1734 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1b3967e commit e43e12e

13 files changed

Lines changed: 66128 additions & 59 deletions

.claude/plans/wave-loop-763.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ field writes and `assert_eq` read-back in a `bench` block.
1212

1313
## PHI LOOP decomposition
1414

15-
- [ ] **Issue** - Confirm #1734 scope and Variant A.
16-
- [ ] **Spec** - Generate `specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27`.
17-
- [ ] **TDD** - Include `test` write schedule and `bench` read-back assertions.
18-
- [ ] **Impl** - No compiler changes; reuse W632 inner-dimension offset formula.
19-
- [ ] **Gen** - Run `tri gen` (or direct witness generation) from `scripts/gen_w763.py`.
20-
- [ ] **Seal** - `t27c seal --save` the witness.
21-
- [ ] **Verify** - `parse`, `icarus-lowerable`, `icarus-simulate`, `icarus-cocotb`, cargo suites.
15+
- [x] **Issue** - Confirm #1734 scope and Variant A.
16+
- [x] **Spec** - Generate `specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27`.
17+
- [x] **TDD** - Include `test` write schedule and `bench` read-back assertions.
18+
- [x] **Impl** - No compiler changes; reuse W632 inner-dimension offset formula.
19+
- [x] **Gen** - Run direct witness generation from `scripts/gen_w763.py`.
20+
- [x] **Seal** - `t27c seal --save` the witness.
21+
- [x] **Verify** - `parse`, `icarus-lowerable`, `icarus-simulate`, `icarus-cocotb`, cargo suites.
2222
- [ ] **Land** - Merge `wave-loop-763` to `master` with `Closes #1734`.
23-
- [ ] **Learn** - Save W763 memory + update `skills-wave-loop-recipe.md` + `MEMORY.md`.
23+
- [x] **Learn** - Save W763 memory + update `skills-wave-loop-recipe.md` + `MEMORY.md`.
2424

2525
## Three cooperation variants for next Wave Loop
2626

.claude/plans/wave-loop-764.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Wave Loop 764 Plan
2+
3+
**Issue:** #1735
4+
**Branch:** `wave-loop-764`
5+
**Date:** 2026-07-23
6+
7+
## Goal
8+
9+
Close Wave Loop 764 by validating a module-scope `[347][2]^6 Pt` packed
10+
array-of-struct variable initialized from a function call, with indexed signed
11+
field writes and `assert_eq` read-back in a `bench` block.
12+
13+
## PHI LOOP decomposition
14+
15+
- [ ] **Issue** - Confirm #1735 scope and Variant A.
16+
- [ ] **Spec** - Generate `specs/scratch/w764_bench_module_347x2p6_aos_var_call_write.t27`.
17+
- [ ] **TDD** - Include `test` write schedule and `bench` read-back assertions.
18+
- [ ] **Impl** - No compiler changes; reuse W632 inner-dimension offset formula.
19+
- [ ] **Gen** - Run direct witness generation from `scripts/gen_w764.py`.
20+
- [ ] **Seal** - `t27c seal --save` the witness.
21+
- [ ] **Verify** - `parse`, `icarus-lowerable`, `icarus-simulate`, `icarus-cocotb`, cargo suites.
22+
- [ ] **Land** - Merge `wave-loop-764` to `master` with `Closes #1735`.
23+
- [ ] **Learn** - Save W764 memory + update `skills-wave-loop-recipe.md` + `MEMORY.md`.
24+
25+
## Three cooperation variants for next Wave Loop
26+
27+
1. **Variant A (recommended):** continue the odd outer-dimension ladder with `[349][2]^6 Pt`.
28+
2. **Variant B:** keep width at ~0.678 MiBit but move the packed var to bench/function scope.
29+
3. **Variant C:** add `if`-guarded indexed signed field writes at the current width.
30+
31+
## Definition of done
32+
33+
All acceptance criteria in `.trinity/current-issue.md` are green and the
34+
closeout report is written to `docs/reports/FPGA_LOOP_CLOSEOUT_W764_2026-07-23.md`.
35+
36+
---
37+
38+
phi^2 + 1/phi^2 = 3 | TRINITY

.trinity/current-issue.md

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,46 @@
1-
# Wave Loop 763 - Current Issue
1+
# Wave Loop 764 — Issue #1735
22

3-
**Issue:** #1734
4-
**Branch:** `wave-loop-763`
5-
**Date:** 2026-07-23
6-
**Variant:** A (recommended)
3+
**Branch:** `wave-loop-764`
4+
**Date:** 2026-07-23
5+
**Cooperation variant:** A (recommended)
76

8-
## Problem statement
7+
## Goal
98

10-
Validate a module-scope packed array-of-struct variable with a non-power-of-two
11-
outer dimension, initialized from a function call, and exercised with indexed
12-
signed field writes and read-back.
13-
14-
## Target witness
15-
16-
- Outer dimension: `345`
17-
- Shape: `[345][2]^6 Pt`
18-
- Type: `pub struct Pt { x : i16, y : i16 }`
19-
- Mode: module-scope `pub var dst : [345][2]^6 Pt = make_grid(...)`
20-
- Writes: indexed signed field writes inside a `test` block
21-
- Reads: `assert_eq` read-back checks in a `bench` block
22-
23-
## Expected metrics
24-
25-
- Total elements: `345 * 64 = 22,080`
26-
- Packed vector width: `22,080 * 32 = 706,560` bits
27-
- Approximate size: ~0.674 MiBit
28-
- Mid index: `MID_IDX = 172`
29-
- Frame-condition element: `[172][1][0][0][0][0][0]` - element `172*64 + 32 = 11040`
30-
- Generator: `scripts/gen_w763.py`
31-
- Witness: `specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27`
32-
- Integration test: `accepts_w763_bench_module_345x2p6_aos_var_call_write`
33-
34-
## Variant candidates
35-
36-
1. **Variant A (recommended): `[345][2]^6 Pt` module-scope var from call with indexed signed field writes.**
37-
- Continues the odd outer-dimension ladder and confirms non-p2 stride 345.
38-
39-
2. **Variant B: `[343][2]^6 Pt` bench-local packed array var from call with indexed signed writes.**
40-
- Same width as W762 but tests the mutable reg declared inside a bench/function.
41-
42-
3. **Variant C: `[343][2]^6 Pt` module-scope var with `if`-guarded indexed signed field writes.**
43-
- Stays at ~0.670 MiBit and tests control-flow-guarded writes on a packed reg.
9+
Close Wave Loop 764 by validating a module-scope `[347][2]^6 Pt` packed
10+
array-of-struct variable initialized from a function call, with indexed signed
11+
field writes and `assert_eq` read-back in a `bench` block.
4412

4513
## Acceptance criteria
4614

47-
- `t27c parse` W763: PASS.
48-
- `t27c icarus-lowerable` W763: PASS (`lowerable`).
49-
- `t27c icarus-simulate` W763: PASS (expected 17 cycles, PASSED).
50-
- `t27c icarus-cocotb` W763: PASS (reference-model OK).
51-
- `t27c seal --save` W763: PASS.
52-
- `cargo test -p t27c --bin t27c`: 1494 passed; 0 failed; 2 ignored.
53-
- `cargo test -p tri`: 78 passed; 0 failed.
54-
- `cargo test -p t27c --test icarus_lowerable`: 223 passed; 0 failed.
55-
- Zero changes to `bootstrap/src/compiler.rs`, `bootstrap/stage0/FROZEN_HASH`,
56-
and `scripts/cocotb_ref_model.py`.
15+
1. `specs/scratch/w764_bench_module_347x2p6_aos_var_call_write.t27` is generated and parses.
16+
2. The witness is Icarus-lowerable and simulates correctly (17 cycles, PASSED).
17+
3. The cocotb reference model matches the t27 semantics.
18+
4. `t27c seal --save` succeeds and FROZEN_HASH remains unchanged.
19+
5. All cargo suites remain green.
20+
6. Integration test `accepts_w764_bench_module_347x2p6_aos_var_call_write` is added.
21+
7. Closeout report `docs/reports/FPGA_LOOP_CLOSEOUT_W764_2026-07-23.md` is written.
22+
8. Learning is saved to `.trinity/experience.md`, memory, and `skills-wave-loop-recipe.md`.
23+
9. Branch merges to `master` with `Closes #1735`.
24+
25+
## Technical notes
26+
27+
- Shape: `[347][2]^6 Pt` where `Pt = pub struct Pt { x : i16, y : i16 }`.
28+
- Total elements: `347 × 64 = 22,208`.
29+
- Packed vector width: `22,208 × 32 = 710,656` bits (~0.678 MiBit).
30+
- `MID_IDX = 173`; frame-condition element `[173][1][0][0][0][0][0]` is element
31+
`173*64 + 32 = 11,104`.
32+
- Generator script: `scripts/gen_w764.py` (copy from `scripts/gen_w763.py`, set
33+
`OUTER = 347` and `MID_IDX = 173`, manually fix the f-string header).
34+
- Use `assert_eq` checks on changed elements (Icarus simulation path does not
35+
emit `assert_ne`).
36+
- Include `make_grid(32768)` period-identity check because `32768 ≡ 0 (mod 32768)`.
37+
- Zero compiler / reference-model / FROZEN_HASH changes expected.
38+
39+
## Cooperation variants for next Wave Loop
40+
41+
- **Variant A (recommended):** continue the odd outer-dimension ladder with `[349][2]^6 Pt`.
42+
- **Variant B:** keep width at ~0.678 MiBit but move the packed var to bench/function scope.
43+
- **Variant C:** add `if`-guarded indexed signed field writes at the current width.
5744

5845
---
5946

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1613
1+
1614

.trinity/current_task/activity.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,3 +3656,7 @@
36563656
- **Commit:** docs(trinity): Wave Loop 763 issue #1734 + branch wave-loop-763 created, next-wave cooperation variants set
36573657
- **Files:** .claude/plans/wave-loop-762.md,.trinity/current_task/.commit_count,.trinity/current_task/session_log.jsonl
36583658

3659+
## 2026-07-23T16:29:56Z — wave-loop-763
3660+
- **Commit:** chore(trinity): record final W762 session log and commit count, set W763 current issue
3661+
- **Files:** .claude/plans/wave-loop-763.md,.claude/plans/wave-loop-764.md,.trinity/current-issue.md,.trinity/current_task/.commit_count,.trinity/current_task/session_log.jsonl,.trinity/experience.md,.trinity/icarus-baselines/specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27.baseline,.trinity/seals/scratch_w763_bench_module_345x2p6_aos_var_call_write.json,bootstrap/tests/icarus_lowerable.rs,docs/reports/FPGA_LOOP_CLOSEOUT_W763_2026-07-23.md,scripts/gen_w763.py,specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27
3662+

.trinity/current_task/session_log.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,4 @@
786786
{"ts":"2026-07-23T16:00:14Z","branch":"wave-loop-762","msg":"docs(trinity): Wave Loop 762 issue #1733 + branch wave-loop-762 created, next-wave cooperation variants set","files":".claude/plans/wave-loop-761.md,.trinity/current_task/.commit_count,.trinity/current_task/session_log.jsonl","notebook":"b83263109fb055dc"}
787787
{"ts":"2026-07-23T16:11:21Z","branch":"wave-loop-762","msg":"chore(trinity): record final W761 session log and commit count, set W762 current issue","files":".trinity/current_task/.commit_count,.trinity/current_task/session_log.jsonl,.trinity/experience.md,.trinity/icarus-baselines/specs/scratch/w762_bench_module_343x2p6_aos_var_call_write.t27.baseline,.trinity/seals/scratch_w762_bench_module_343x2p6_aos_var_call_write.json,bootstrap/tests/icarus_lowerable.rs,docs/reports/FPGA_LOOP_CLOSEOUT_W762_2026-07-23.md,scripts/gen_w762.py,specs/scratch/w762_bench_module_343x2p6_aos_var_call_write.t27","notebook":"b83263109fb055dc"}
788788
{"ts":"2026-07-23T16:12:09Z","branch":"wave-loop-763","msg":"chore(trinity): record final W762 session log and commit count","files":".claude/plans/wave-loop-763.md,.trinity/current-issue.md","notebook":"b83263109fb055dc"}
789+
{"ts":"2026-07-23T16:12:32Z","branch":"wave-loop-763","msg":"docs(trinity): Wave Loop 763 issue #1734 + branch wave-loop-763 created, next-wave cooperation variants set","files":".claude/plans/wave-loop-762.md,.trinity/current_task/.commit_count,.trinity/current_task/session_log.jsonl","notebook":"b83263109fb055dc"}

.trinity/experience.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1+
## 2026-07-23 — Wave Loop 763 (module-scope `[345][2]^6 Pt` non-power-of-two outer-dimension AoS variable)
2+
3+
### What worked
4+
- Variant A extended the module-scope packed AoS odd outer-dimension ladder to 345.
5+
The `[345][2]^6 Pt` witness is 706,560 bits (~0.674 MiBit), still well under the 4-MiBit
6+
cliff, and required no compiler changes.
7+
- A module-level `pub var dst : [345][2]^6 Pt` can be initialized from a function
8+
call and exercised with indexed signed field writes, with zero compiler changes.
9+
- The cocotb/Python reference model correctly mirrored the row-major flattening
10+
with outer stride 345, confirming the layout is preserved end-to-end.
11+
- Reused the corrected W632 element-index formula for mid-row expected values:
12+
`[r][a5][a4][a3][a2][a1][a0]` is element `r*64 + a5*32 + a4*16 + a3*8 + a2*4 + a1*2 + a0`.
13+
- For `OUTER = 345`, `MID_IDX = 172`; the frame-condition element is
14+
`[172][1][0][0][0][0][0]`, element number `172*64 + 32 = 11,040`.
15+
- Updated weak-point audit: 575 commits in 30 days (28 with `Closes #N`), 57
16+
`.t27` specs without `test`/`invariant`/`bench`, 23 `scripts/*.sh` under `scripts/`.
17+
18+
### What changed behavior
19+
- No changes to `bootstrap/src/compiler.rs`.
20+
- No changes to `bootstrap/stage0/FROZEN_HASH`.
21+
- No changes to `scripts/cocotb_ref_model.py`.
22+
- Added `specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27` (~1,510 KB /
23+
~65,611 lines) with seal and Icarus baseline.
24+
- Added integration test `accepts_w763_bench_module_345x2p6_aos_var_call_write`.
25+
- Added generator script `scripts/gen_w763.py`.
26+
27+
### Validation
28+
- `cargo build --release -p t27c`: OK.
29+
- `cargo test -p t27c --bin t27c`: 1494 passed; 0 failed; 2 ignored.
30+
- `cargo test -p tri`: 78 passed; 0 failed.
31+
- `cargo test -p t27c --test icarus_lowerable`: 223 passed; 0 failed.
32+
- Direct `t27c parse` W763: PASS.
33+
- Direct `t27c icarus-lowerable` W763: PASS (`lowerable`).
34+
- Direct `t27c icarus-simulate` W763: PASS (17 cycles, PASSED).
35+
- Direct `t27c icarus-cocotb` W763: PASS (`reference-model OK`).
36+
37+
### Scientific / engineering background
38+
- IEEE 1800-2017 7.4.1/7.4.3 define packed-array total width as the product of
39+
packed dimensions, with no power-of-two restriction. Variant A emits a single
40+
706,560-bit packed vector, which is legal SystemVerilog.
41+
- Lutsig verified array lowering and CIRCT `HWLegalizeModules` show that
42+
flattening nested arrays to wide packed vectors is a well-founded compiler
43+
discipline, even when outer dimensions are non-power-of-two.
44+
- Icarus issue #1134 documents assertion failures for unpacked arrays of packed
45+
structs; t27 scalar flattening avoids that construct entirely.
46+
- Yosys issue #2677 / #4653 confirm that arrays of packed structs remain
47+
unsupported in the native frontend; t27 packed-vector lowering avoids the
48+
gap.
49+
- 2025-2026 ternary/MVL literature scan found:
50+
- Trinity B002 / Trinity v2.0.x — zero-DSP ternary-weight autoregressive LLM
51+
inference on Xilinx Artix-7 via OpenXC7, ~63 tok/s @ ~1 W, QMTech XC7A100T
52+
(Zenodo 2025/2026).
53+
- TerEffic — highly efficient ternary LLM inference on AMD Alveo U280, 16,300
54+
tok/s on 370 M model, 455 tok/s/W (arXiv 2025).
55+
- TeLLMe v2 — end-to-end ternary LLM prefill/decode accelerator on AMD Kria
56+
KV260, up to 25 tok/s decode / 143 tok/s prefill under 5 W (arXiv 2025).
57+
- 5500FP / GargantuRAM — 24-trit balanced ternary RISC processor on Efinix
58+
Trion FPGA at 20 MHz, real ±3.3 V ternary I/O, CERN-OHL-P v2 board,
59+
commercially available (Zenodo/GitHub/Hackaday 2026).
60+
- TernaryCore — open-source native {-1,0,+1} Verilog BitNet b1.58 accelerator,
61+
zero DSP, 31/31 simulations passing, Artix-7 roadmap (GitHub 2026).
62+
- Unbalanced ternary full adder in CNTFET — 42-transistor design with 35.8–75.2%
63+
power reduction (IEEE TCAD 2026).
64+
- CNTFET-based ternary full adder — 76/55 CNTFET complete/partial adders with
65+
~24% delay improvement (IEEE TCAD 2025).
66+
- Energy-optimized ternary full adder using capacitive threshold logic and
67+
CNTFETs for DSP (AEU 2026).
68+
- OpenXC7 / nextpnr-xilinx / Project X-Ray — fully open-source Xilinx
69+
7-series toolchain, used for QMTech XC7A100T ternary projects without Vivado.
70+
171
## 2026-07-23 — Wave Loop 762 (module-scope `[343][2]^6 Pt` non-power-of-two outer-dimension AoS variable)
272

373
### What worked

.trinity/icarus-baselines/specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27.baseline

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"gen_hash_c": "sha256:7abba5ce6c7da30e89d188cb3d0c8c6f701f1b50fc219048e9997413983803b9",
3+
"gen_hash_rust": "sha256:7d424d87fb8c63abaca58ca3a3887b01d784b6f7589b696c32d6e17d7360d62f",
4+
"gen_hash_verilog": "sha256:1a26b82fd1bc30664bff6c3bb63a441dbd3b9bfd188dbbb41faff8a6a1128e2c",
5+
"gen_hash_zig": "sha256:f1520504aa69456fc7812e584a8a55f8d8bf5b398dc2d54c3bd04f3c5d423706",
6+
"module": "w763_bench_module_345x2p6_aos_var_call_write",
7+
"ring": 12,
8+
"sealed_at": "2026-07-23T16:26:18Z",
9+
"spec_hash": "sha256:6b598514c91f84a1e0bb7585692a594da126dba4f020e0058bdd1dc54fb76ca3",
10+
"spec_path": "specs/scratch/w763_bench_module_345x2p6_aos_var_call_write.t27"
11+
}

bootstrap/tests/icarus_lowerable.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,6 +4027,24 @@ fn accepts_w762_bench_module_343x2p6_aos_var_call_write() {
40274027
}
40284028
}
40294029

4030+
#[test]
4031+
fn accepts_w763_bench_module_345x2p6_aos_var_call_write() {
4032+
let dir = scratch_dir();
4033+
for name in &[
4034+
"w763_bench_module_345x2p6_aos_var_call_write.t27",
4035+
] {
4036+
let p = dir.join(name);
4037+
assert!(p.exists(), "missing W763 witness {}", p.display());
4038+
let (lowerable, json) = run_icarus_lowerable(&p);
4039+
assert!(
4040+
lowerable,
4041+
"expected {} to be lowerable, got: {}",
4042+
p.display(),
4043+
json
4044+
);
4045+
}
4046+
}
4047+
40304048
#[test]
40314049
fn accepts_known_lowerable_witnesses() {
40324050
let dir = scratch_dir();

0 commit comments

Comments
 (0)