amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

136 lines
3.3 KiB
C++

#include "engine_internal.hpp"
#include <tuple>
namespace deferred {
bool Node::eligible() const
{
if (life != LIVE) {
return false;
}
if (depth != 0) {
return false;
}
return !pending.empty();
}
void Engine::Impl::record(int kind, int id, const Batch& batch)
{
const Node& node = nodes[id];
Event event{};
event.kind = kind;
event.id = id;
event.generation = node.generation;
event.count = batch.count;
event.sum = batch.sum;
event.value = batch.transformed(node.cookie);
history.push(event);
}
int Engine::Impl::select() const
{
int selected = -1;
for (int id = 0; id < 16; ++id) {
const Node& node = nodes[id];
if (!node.eligible()) {
continue;
}
if (selected == -1) {
selected = id;
continue;
}
const Node& previous = nodes[selected];
const auto candidate = std::make_tuple(node.priority, node.pending.ticket, id);
const auto current = std::make_tuple(previous.priority, previous.pending.ticket, selected);
if (candidate < current) {
selected = id;
}
}
return selected;
}
Action Engine::Impl::begin(int id)
{
Node& node = nodes[id];
node.active = node.pending;
node.pending.clear();
active_id = id;
starts += 1;
record(2, id, node.active);
Action action{};
action.kind = START;
action.id = id;
action.generation = node.generation;
action.count = node.active.count;
action.sum = node.active.sum;
action.value = node.active.transformed(node.cookie);
return action;
}
Action Engine::Impl::complete(int id)
{
Node& node = nodes[id];
const Batch completed = node.active;
Action action{};
action.kind = FINISH;
action.id = id;
action.generation = node.generation;
action.count = completed.count;
action.sum = completed.sum;
action.value = completed.transformed(node.cookie);
node.ledger.account(completed, node.cookie);
finishes += 1;
record(3, id, completed);
node.active.clear();
node.pending.clear();
active_id = -1;
return action;
}
Action Engine::Impl::idle() const
{
Action action{};
action.kind = IDLE;
action.id = -1;
action.generation = 0;
action.count = 0;
action.sum = 0;
action.value = 0;
return action;
}
Action Engine::step()
{
Impl& state = *state_;
if (state.active_id >= 0) {
return state.complete(state.active_id);
}
const int selected = state.select();
if (selected < 0) {
return state.idle();
}
return state.begin(selected);
}
void EventRing::push(Event value)
{
sequence += 1;
value.serial = sequence;
if (used < storage.size()) {
const std::size_t index = (first + used) % storage.size();
storage[index] = value;
used += 1;
return;
}
storage[first] = value;
first = (first + 1) % storage.size();
}
int EventRing::get(int index, Event& out) const
{
if (index < 0 || index >= 16) {
return BAD_VALUE;
}
if (static_cast<std::size_t>(index) >= used) {
return NO_EVENT;
}
const std::size_t position = (first + static_cast<std::size_t>(index)) % storage.size();
out = storage[position];
return OK;
}
Number EventRing::size() const
{
return static_cast<Number>(used);
}
}