One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
134 lines
3.8 KiB
C
134 lines
3.8 KiB
C
#include "scanner.h"
|
|
#include <string.h>
|
|
|
|
void sp_init(sp_scanner *scanner)
|
|
{
|
|
memset(scanner, 0, sizeof(*scanner));
|
|
scanner->cursor = -1;
|
|
scanner->phase = SP_FETCH;
|
|
scanner->stop = SP_UNCONFIGURED;
|
|
}
|
|
|
|
int sp_plan_valid(const sp_plan *plan)
|
|
{
|
|
int index;
|
|
if (!plan) {
|
|
return 0;
|
|
}
|
|
if (plan->count < 0 || plan->count > SP_MAX_ITEMS) {
|
|
return 0;
|
|
}
|
|
if (plan->modulus < 1 || plan->modulus > 17) {
|
|
return 0;
|
|
}
|
|
if (plan->residue < 0 || plan->residue >= plan->modulus) {
|
|
return 0;
|
|
}
|
|
if (plan->count == 0) {
|
|
return plan->first == 0 && plan->last == 0;
|
|
}
|
|
if (plan->first < 0 || plan->first >= plan->count) {
|
|
return 0;
|
|
}
|
|
if (plan->last < 0 || plan->last >= plan->count) {
|
|
return 0;
|
|
}
|
|
for (index = 0; index < plan->count; ++index) {
|
|
if (plan->values[index] < -1000 || plan->values[index] > 1000) {
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void reset_position(sp_scanner *scanner)
|
|
{
|
|
scanner->cursor = scanner->plan.count ? scanner->plan.first : -1;
|
|
scanner->direction = scanner->plan.first <= scanner->plan.last ? 1 : -1;
|
|
scanner->phase = SP_FETCH;
|
|
scanner->value = 0;
|
|
scanner->selected = 0;
|
|
scanner->steps = 0;
|
|
scanner->visited = 0;
|
|
scanner->kept = 0;
|
|
scanner->sum = 0;
|
|
scanner->digest = 0;
|
|
scanner->stop = scanner->plan.count ? SP_READY : SP_DONE;
|
|
}
|
|
|
|
int sp_install(sp_scanner *scanner, const sp_plan *plan)
|
|
{
|
|
if (!sp_plan_valid(plan)) {
|
|
return -1;
|
|
}
|
|
scanner->plan = *plan;
|
|
scanner->configured = 1;
|
|
reset_position(scanner);
|
|
return 0;
|
|
}
|
|
|
|
int sp_restart(sp_scanner *scanner)
|
|
{
|
|
if (!scanner->configured) {
|
|
return -1;
|
|
}
|
|
reset_position(scanner);
|
|
return 0;
|
|
}
|
|
|
|
|
|
int sp_tick(sp_scanner *scanner, int budget, sp_journal *journal)
|
|
{
|
|
uint64_t kept[SP_MAX_ITEMS + 1] = {0};
|
|
int64_t sums[SP_MAX_ITEMS + 1] = {0};
|
|
uint32_t hashes[SP_MAX_ITEMS + 1] = {0};
|
|
int length;
|
|
int rank;
|
|
uint64_t finish;
|
|
uint64_t target;
|
|
sp_journal_clear(journal);
|
|
if (!scanner->configured || budget < 0 || budget > SP_MAX_BUDGET) {
|
|
return -1;
|
|
}
|
|
if (scanner->stop == SP_DONE) {
|
|
return 0;
|
|
}
|
|
length = sp_domain_length(&scanner->plan);
|
|
for (rank = 0; rank < length; ++rank) {
|
|
int index = scanner->plan.first + rank * scanner->direction;
|
|
int value = scanner->plan.values[index];
|
|
int selected = sp_selected(value, scanner->plan.modulus, scanner->plan.residue);
|
|
kept[rank + 1] = kept[rank] + (unsigned int)selected;
|
|
sums[rank + 1] = sums[rank] + (selected ? value : 0);
|
|
hashes[rank + 1] = selected ? sp_digest_next(hashes[rank], index, value) : hashes[rank];
|
|
}
|
|
finish = (uint64_t)length * 3u;
|
|
target = scanner->steps + (unsigned int)budget;
|
|
if (target > finish) {
|
|
target = finish;
|
|
}
|
|
scanner->stop = SP_BUDGET;
|
|
while (scanner->steps < target) {
|
|
uint64_t ordinal = scanner->steps;
|
|
int stage = (int)(ordinal % 3u);
|
|
int slot = (int)(ordinal / 3u);
|
|
int index = scanner->plan.first + slot * scanner->direction;
|
|
scanner->cursor = index;
|
|
scanner->value = scanner->plan.values[index];
|
|
scanner->selected = stage == 0 ? 0 : sp_selected(scanner->value, scanner->plan.modulus, scanner->plan.residue);
|
|
scanner->steps = ordinal + 1;
|
|
scanner->phase = (sp_phase)((stage + 1) % 3);
|
|
scanner->visited = scanner->steps / 3u;
|
|
scanner->kept = kept[scanner->visited];
|
|
scanner->sum = sums[scanner->visited];
|
|
scanner->digest = hashes[scanner->visited];
|
|
sp_journal_add(journal, scanner, stage + 1);
|
|
if (scanner->steps == finish) {
|
|
scanner->stop = SP_DONE;
|
|
} else if (stage == 2) {
|
|
scanner->cursor += scanner->direction;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|