feat(v4): Phase 7 Task 3b -- compudynamics on the 32 F18 opcodes as on the words, behind OPCODE_PHYSICS (#189)

Captain Bob, 2026-11-14: "we're supposed to be working on f18 opcode as well as our composed f18
dictionary"; ruled every loop on both, "and an easy revert if opcodes are too granular".

- The engine: a hook at retire (exec.h on_retire), as Part A's at call; NULL unless set. test_exec.c.
- The mesh: 32 opcode records per node, an opcode window, opcode transitions under L4; at every retired
  instruction decay at the opcodes' own slope, heat, temperature, the window, the transition; in each cycle
  all 32 cooled, the opcode window's service, inference on its heat. L8 scores from the words and its gates
  govern both; the tick stays paced by word calls. The window is now one type for words and opcodes.
- The revert: OPCODE_PHYSICS (Kconfig.physics, default y; the kernel's flags) -- 0 and the opcodes are
  counted and charged to the Stadium as in Phase 1. make -C v4 mesh-boot-noop builds and tests it.
- Tests first: test_mesh_boot.c 77 checks as built, 86 with pipelining on, 74 with the revert.
- Measured on amd64, back to back: 219 s on, 196 s off (+12% under TCG). Both boots' logs labelled.
Not pushed (held to the end of Phase 7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-14 00:29:08 +00:00
parent b5d99ba98b
commit e1b731f444
16 changed files with 296 additions and 57 deletions
+39 -7
View File
@@ -218,12 +218,44 @@ int main(void)
r = line(V4_MESH_HERA, "FORGET L8T", &how);
}
/* ---- the opcodes (#189 Phase 7, ruling 7: every loop on the 32 F18 opcodes too; revert: OPCODE_PHYSICS 0) ---- */
{
v4_mesh_physics *p = &ms.physics[0];
uint64_t heat_add, total0 = p->opwin.total_executions;
unsigned k, hot = 0;
v4_mesh_l8_force(&ms, 0, 60u, 1); /* L1..L4 on: the window, decay, pipelining */
r = line(V4_MESH_HERA, ": OPS 0 1000 0 DO 3 + LOOP DROP ; OPS", &how);
for (k = 0; k < V4_MESH_OPCODES; k++) if (p->op[k].heat > 0) hot++;
heat_add = p->op[20].heat; /* + is opcode 20 */
#if OPCODE_PHYSICS
CHECK(how == V4_TEXT_COMPLETED && hot > 5 && heat_add > 0 && p->op[20].temperature_q8 > 0,
"the opcodes have heat of their own: %u of 32 warm, + at %lu", hot, (unsigned long)heat_add);
CHECK(p->opwin.total_executions > total0 + 1000u, "the opcode window took every retirement (%lu)",
(unsigned long)(p->opwin.total_executions - total0));
CHECK(p->opwin.is_warm && p->op_decay_slope_q48 > 0, "it is warm, and the opcodes have a decay slope of their own");
#if ENABLE_PIPELINING
CHECK(p->op[20].total_transitions > 0, "pipelining on: + has transitions, its likeliest next opcode %u", p->op[20].most_likely_next);
#endif
{
uint64_t runs = p->op_inference_runs;
r = line(V4_MESH_HERA, ": LOPS 400 0 DO OPS LOOP ; LOPS", &how);
CHECK(p->op_inference_runs > runs || p->inference_runs == 0, "inference runs on the opcodes' window too (%lu)",
(unsigned long)p->op_inference_runs);
}
#else
CHECK(how == V4_TEXT_COMPLETED && hot == 0 && heat_add == 0 && p->opwin.total_executions == total0,
"built without OPCODE_PHYSICS (the revert): no opcode records, as Phase 1");
#endif
v4_mesh_l8_force(&ms, 0, p->l8.current_card, 0);
r = line(V4_MESH_HERA, "FORGET OPS", &how);
}
/* ---- inference every 1000 ticks, and Loop #7 (#189 Phase 7, Task 3) ---- */
{
v4_mesh_physics *p = &ms.physics[0];
uint64_t t0 = p->tick, runs0 = p->inference_runs;
r = line(V4_MESH_HERA, ": IW ; : LIW 30 0 DO 10000 0 DO IW LOOP LOOP ; LIW", &how); /* 300000 calls: over 1000 ticks */
CHECK(how == V4_TEXT_COMPLETED && p->tick - t0 > 1000u && p->is_warm, "a long run: over 1000 ticks (%lu), the window warm",
CHECK(how == V4_TEXT_COMPLETED && p->tick - t0 > 1000u && p->win.is_warm, "a long run: over 1000 ticks (%lu), the window warm",
(unsigned long)(p->tick - t0));
CHECK(p->inference_runs > runs0, "inference ran (%lu times)", (unsigned long)p->inference_runs);
CHECK(p->tick_target_ns != HEARTBEAT_TICK_NS && p->tick_target_ns >= HEARTBEAT_TICK_NS / 4u
@@ -232,7 +264,7 @@ int main(void)
CHECK(heartrates > 0 && heartrate_ns == (p->tick_target_ns * 10000000ULL) / HEARTBEAT_TICK_NS,
"and on Hera re-armed the kernel's heartbeat: %lu ns", (unsigned long)heartrate_ns);
CHECK(!p->inference.early_exited ? p->last_inference_tick > 0 : 1, "a full run marks its tick");
CHECK(p->snapshot.tick == p->tick && p->snapshot.window_width == p->effective_window_size
CHECK(p->snapshot.tick == p->tick && p->snapshot.window_width == p->win.effective_window_size
&& p->snapshot.decay_slope_q48 == p->decay_slope_q48 && p->snapshot.fill == V4_MESH_WINDOW
&& p->snapshot.total_heat == p->total_heat_at_check && p->total_heat_at_check > 0,
"the cycle's snapshot: its tick, window, slope, and the dictionary's heat as inference counted it");
@@ -283,12 +315,12 @@ int main(void)
CHECK(p->l2_window && p->l3_decay && !p->l4_pipelining && !p->l1_cache && p->l7_adaptive_heartrate,
"card 24's gates: the window, decay, and L7, which is always on");
v4_mesh_set_tick(&ms, 100);
total0 = p->total_executions;
total0 = p->win.total_executions;
r = line(V4_MESH_HERA, "2 P7 3 P7 4 P7 + + .", &how);
CHECK(strcmp(r, "29 ") == 0 && a && a->heat == 3 && a->last_decay_tick == 100,
"three calls: heat 3, decayed at tick 100 (%lu)", a ? (unsigned long)a->heat : 0ul);
CHECK(p->total_executions >= total0 + 3 && p->history[(p->window_pos + V4_MESH_WINDOW - 1u) % V4_MESH_WINDOW]
!= (uint32_t)-1, "the rolling window took them (%lu)", (unsigned long)(p->total_executions - total0));
CHECK(p->win.total_executions >= total0 + 3 && p->win.history[(p->win.window_pos + V4_MESH_WINDOW - 1u) % V4_MESH_WINDOW]
!= (uint32_t)-1, "the rolling window took them (%lu)", (unsigned long)(p->win.total_executions - total0));
CHECK(a && a->temperature_q8 > 0, "and the temperature rose: %u", a ? a->temperature_q8 : 0u);
v4_mesh_set_tick(&ms, 106); /* six ticks at 21845 (1/3 a tick, Q48.16): 1 heat */
r = line(V4_MESH_HERA, "2 P7 .", &how);
@@ -336,9 +368,9 @@ int main(void)
r = line(V4_MESH_HERA, ": NOP ; : LZ 20000 0 DO NOP LOOP ; LZ", &how); /* many cycles of calls, none to Q7 */
CHECK(qa && qa->heat < Q7_HOT && qa->last_decay_tick > 0, "Q7, never called again, has cooled in the background: %lu",
qa ? (unsigned long)qa->heat : 0ul);
CHECK(p->diversity_checks > 0 && p->effective_window_size >= 256u && p->effective_window_size <= V4_MESH_WINDOW,
CHECK(p->win.diversity_checks > 0 && p->win.effective_window_size >= 256u && p->win.effective_window_size <= V4_MESH_WINDOW,
"the window, warm, checked its diversity (%lu checks), its size within 256..4096: %u",
(unsigned long)p->diversity_checks, p->effective_window_size);
(unsigned long)p->win.diversity_checks, p->win.effective_window_size);
r = line(V4_MESH_HERA, "FORGET Q7", &how);
}
v4_mesh_l8_force(&ms, 0, ms.physics[0].l8.current_card, 0); /* L8 chooses again */