feat(v4): Phase 7 Task 2a -- decay, heat, temperature and the rolling window at every call (#189)
As v3's physics_pre_execute, in its order (Captain Bob, 2026-11-13: "Every call, as v3"): a word's heat decays by the ticks since its last touch at the node's decay slope (Q48.16, v3's arithmetic), unless frozen or L8 has Loop #3 off; +1; its temperature smoothed 3:1; its ID into the node's Rolling Window of Truth (4096, warm at 1024, a diversity check due every 512). The kernel's heartbeat is read at each call. Pipelining and the hot-words cache ruled "Built, off as v3" (Task 2b). Test first: test_mesh_boot.c, 56 checks. amd64 boots, RESULT: PASS, 146 s against Phase 2's 142 s. Not pushed (held). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
+69
-5
@@ -182,14 +182,71 @@ static void words_gone(unsigned place, const v4_node *n, v4_cell w)
|
||||
}
|
||||
}
|
||||
|
||||
/* at `call` (exec.h): a word's record counts one; any other target, nothing */
|
||||
/* Loop #3, on touch (v3's physics_metadata_apply_linear_decay): the ticks since, times the decay slope
|
||||
* (Q48.16), off the heat -- not for a frozen word, not while L8 has Loop #3 off */
|
||||
static void decay(v4_mesh_account *a, const v4_mesh_physics *p, uint64_t elapsed)
|
||||
{
|
||||
uint64_t amount;
|
||||
if ((a->state_flags & V4_MESH_STATE_FROZEN) || elapsed == 0 || !p->l3_decay) return;
|
||||
amount = (elapsed * p->decay_slope_q48) >> 16;
|
||||
if (amount == 0) return;
|
||||
a->heat = amount >= a->heat ? 0 : a->heat - amount;
|
||||
}
|
||||
|
||||
/* the temperature (v3's physics_metadata_touch): the heat in Q8, smoothed 3:1 */
|
||||
static uint16_t temperature(v4_uheat_t heat, uint16_t prior)
|
||||
{
|
||||
uint64_t scaled;
|
||||
uint16_t target;
|
||||
if (heat == 0) return 0;
|
||||
scaled = (uint64_t)heat << 8;
|
||||
target = scaled > 65535u ? 65535u : (uint16_t)scaled;
|
||||
return (uint16_t)((3u * prior + target) / 4u);
|
||||
}
|
||||
|
||||
/* Loop #2 (v3's rolling_window_record_execution): the word's ID into the window */
|
||||
static void window_record(v4_mesh_physics *p, uint32_t id)
|
||||
{
|
||||
p->history[p->window_pos] = id;
|
||||
p->window_pos = (p->window_pos + 1u) % V4_MESH_WINDOW;
|
||||
p->total_executions++;
|
||||
if (p->total_executions >= V4_MESH_WINDOW_WARM && !p->is_warm) p->is_warm = 1;
|
||||
if (p->is_warm && ++p->adaptive_check_accumulator >= V4_MESH_ADAPTIVE_CHECK) {
|
||||
p->adaptive_check_accumulator = 0;
|
||||
p->adaptive_pending = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* at `call` (exec.h), on a word -- any other target, nothing -- in v3's order (physics_pre_execute,
|
||||
* V3-PARITY.md 2.1; Captain Bob, 2026-11-13: "Every call, as v3"): decay by the ticks since, heat +1,
|
||||
* the count the Stadium is charged by, the temperature, the rolling window */
|
||||
static void on_call(void *ctx, v4_node *n, v4_cell target)
|
||||
{
|
||||
unsigned place = place_of_device(ctx);
|
||||
v4_cell id;
|
||||
v4_mesh_account *a;
|
||||
if (!is_word(place, target)) return;
|
||||
id = n->mem[target - 4];
|
||||
if (id >= 0 && id < (v4_cell)V4_MESH_WORD_IDS) { accounts_of(place)[id].calls++; accounts_of(place)[id].since++; }
|
||||
if (id < 0 || id >= (v4_cell)V4_MESH_WORD_IDS) return;
|
||||
a = &accounts_of(place)[id];
|
||||
if (the->physics) {
|
||||
v4_mesh_physics *p = &the->physics[place];
|
||||
if (the->ticks) p->tick = the->ticks();
|
||||
decay(a, p, p->tick - a->last_decay_tick);
|
||||
a->last_decay_tick = p->tick;
|
||||
a->heat++;
|
||||
a->temperature_q8 = temperature(a->heat, a->temperature_q8);
|
||||
if (p->l2_window) window_record(p, (uint32_t)id);
|
||||
}
|
||||
a->calls++;
|
||||
a->since++;
|
||||
}
|
||||
|
||||
void v4_mesh_set_tick(v4_mesh *ms, uint64_t tick)
|
||||
{
|
||||
unsigned k;
|
||||
if (!ms->physics) return;
|
||||
for (k = 0; k < ms->capacity; k++) ms->physics[k].tick = tick;
|
||||
}
|
||||
|
||||
/* is the entry at xt named `name`? (dict.f18: the name's word address at xt-2, its count byte, then its
|
||||
@@ -228,9 +285,16 @@ static void words_attach(unsigned place, v4_fabric_node *x)
|
||||
x->n.mem[im->word_forgotten] = gone;
|
||||
}
|
||||
if (the->physics) { /* the node's physics, as v3's VM starts */
|
||||
the->physics[place].tick = 0;
|
||||
the->physics[place].decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
|
||||
the->physics[place].l3_decay = 1;
|
||||
v4_mesh_physics *p = &the->physics[place];
|
||||
uint64_t tick = p->tick; /* the heartbeat's, which goes on */
|
||||
unsigned char *z = (unsigned char *)p;
|
||||
unsigned long i;
|
||||
for (i = 0; i < sizeof *p; i++) z[i] = 0;
|
||||
p->tick = tick;
|
||||
p->decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
|
||||
p->l3_decay = 1;
|
||||
p->l2_window = 1; /* v3: "No config yet: recorded" */
|
||||
p->effective_window_size = V4_MESH_WINDOW;
|
||||
}
|
||||
x->es.on_call = on_call;
|
||||
x->es.on_call_ctx = &the->kernel[place];
|
||||
|
||||
Reference in New Issue
Block a user