Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# NOW -- Port scripts/gen_w672.py (Python, 3 functions) to specs/port/scripts/gen_w672.t27 (published 2026-10-10)

## A bee's work on #8265, published from `queen-8265` (Closes #8265)

- The branch changes 1 file(s): `specs/port/scripts/gen_w672.t27`.
- `git diff --stat origin/master...queen-8265` reads: 1 file changed, 80 insertions(+)
- This entry is written by the publisher, not by the bee. A pull request must
add exactly one `docs/now/` entry and a bee has no way to know that: its brief
names a boundary file and acceptance criteria, and `docs/now/` is neither.
- What this entry does NOT establish: that the work is correct. The gates on the
pull request judge that, and they are the same gates every other change meets.
124 changes: 124 additions & 0 deletions specs/port/scripts/gen_w672.t27
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: Apache-2.0
// Port of scripts/gen_w672.py (issue #8265).
// The original writes the spec w672_bench_module_163x2p6_aos_var_call_write.t27: a
// [163][2][2][2][2][2][2]Pt grid literal whose points are numbered in row-major order.
// The decisions in it are the expected point values the generated test asserts, the
// indent width, the coordinate of each point (2e + offset, wrapped at 32768) and the
// row-major point numbering build_tree's recursion threads through the shape.
// Building the text and writing the file are plumbing.
module gen_w672 {
const WRAP: u32 = 32768;
const INDENT_UNIT: u32 = 4;

// Expected values the original substitutes into the emitted test (lines 9-21):
// 163 * 2^6 = 10432 points, the last at e = 10431, the mid one at
// dst[MID_IDX][1][0][0][0][0][0]. The original's "# 73" comment on MID_IDX is
// stale: 163 // 2 is 81, and 81 is what the original actually substitutes.
const OUTER: u32 = 163;
const TOTAL: u32 = OUTER * 64;
const LAST_IDX: u32 = OUTER - 1;
const MID_IDX: u32 = OUTER / 2;
const MID_E: u32 = MID_IDX * 64 + 32;
const LAST_X: u32 = (2 * (TOTAL - 1)) % WRAP;
const LAST_Y: u32 = (2 * (TOTAL - 1) + 1) % WRAP;
const MID_X: u32 = (2 * MID_E) % WRAP;
const MID_Y: u32 = (2 * MID_E + 1) % WRAP;
const WRAP_LAST_X: u32 = (2 * (TOTAL - 1) + WRAP) % WRAP;
const WRAP_LAST_Y: u32 = (2 * (TOTAL - 1) + 1 + WRAP) % WRAP;

// SHAPE: the grid's dims, one outer [163] and six [2]s. build_tree walks
// exactly this, one level per dimension, the way the original slices
// shape[1:] on every recursive call.
const SHAPE: [7]u32 = [163, 2, 2, 2, 2, 2, 2];

// indent(level): the number of spaces for one indent level (" " * level).
fn indent(level: u32) -> u32 {
return INDENT_UNIT * level;
}

// coordinate(e, offset, step): x is step 0, y is step 1 -> (2e + offset + step) % 32768.
fn coordinate(e: u32, offset: u32, step: u32) -> u32 {
return (2 * e + offset + step) % WRAP;
}

// build_tree(shape, depth, base): the original's recursion, one dimension
// per level. A leaf row (the last dimension) lays out n single points and
// returns base + n; above it, n subtrees of the remaining shape run one
// after another, each starting from the base the previous sibling ended on.
// The original's third argument, offset, feeds only the leaf coordinates --
// coordinate()'s decision here -- so it is not threaded; the literal text
// it joins from these calls is plumbing. The point numbering the base
// threading computes (e at index path [i0]..[ik] is base + i0*d1*..*dk +
// ... + ik) is the decision, and the next base is what this returns, the
// second slot of the original's tuple.
fn build_tree(shape: [7]u32, depth: u32, base: u32) -> u32 {
if (depth == 6) {
return base + shape[depth];
}
var b: u32 = base;
var i: u32 = 0;
while (i < shape[depth]) {
b = build_tree(shape, depth + 1, b);
i = i + 1;
}
return b;
}

// Plumbing: assembles the literal with build_tree, gates the text on ASCII,
// writes the .t27 file and prints the byte count; no test calls it.
fn generate() -> u32 {
undefined;
}

test indent_is_four_spaces_per_level {
assert(indent(0) == 0);
assert(indent(1) == 4);
assert(indent(2) == 8);
}

test first_point_is_zero_one {
assert(coordinate(0, 0, 0) == 0);
assert(coordinate(0, 0, 1) == 1);
}

test last_point_matches_the_generated_expectations {
// 163 * 64 = 10432 points, the last has e = 10431: x = 20862, y = 20863.
assert(coordinate(TOTAL - 1, 0, 0) == LAST_X);
assert(coordinate(TOTAL - 1, 0, 1) == LAST_Y);
// The point at dst[MID_IDX][1][0][0][0][0][0] has e = MID_IDX * 64 + 32.
assert(coordinate(MID_E, 0, 0) == MID_X);
assert(coordinate(MID_E, 0, 1) == MID_Y);
}

test offset_32768_wraps_back {
assert(coordinate(0, WRAP, 0) == 0);
assert(coordinate(0, WRAP, 1) == 1);
assert(coordinate(TOTAL - 1, WRAP, 0) == WRAP_LAST_X);
assert(coordinate(TOTAL - 1, WRAP, 1) == WRAP_LAST_Y);
}

test build_tree_walks_one_dimension_per_level {
// a leaf row (the last [2]) lays out two single points from base 7
assert(build_tree(SHAPE, 6, 7) == 9);
// one inner subtree: the six [2]s under a single outer entry hold 64
// points, so from base 10 the subtree ends at 74
assert(build_tree(SHAPE, 1, 10) == 74);
}

test base_threading_numbers_points_row_major {
// dst[MID_IDX][1][0][0][0][0][0] is element MID_IDX*64 + 32: the first
// MID_IDX outer entries consume MID_IDX*64 points -- the base handed
// to the next outer subtree -- then one [2]-subtree consumes 32 more
// before the point's own leaf row
var head: [7]u32 = [81, 2, 2, 2, 2, 2, 2];
assert(build_tree(head, 0, 0) == MID_IDX * 64);
assert(build_tree(head, 0, 0) + 32 == MID_E);
}

test whole_grid_has_10432_points {
// the full recursion over all seven dimensions: 163 outer entries of
// 64 points each, the base threaded through every subtree -- the count
// the original's generated literal embodies
assert(build_tree(SHAPE, 0, 0) == TOTAL);
}
}
Loading