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>
137 lines
4.4 KiB
C++
137 lines
4.4 KiB
C++
#include "progress.hpp"
|
|
#include <algorithm>
|
|
namespace progress {
|
|
namespace {
|
|
std::uint32_t rotate_word(std::uint32_t value, std::uint32_t distance) {
|
|
distance %= 16;
|
|
const std::uint32_t low = value & 65535;
|
|
if (distance == 0) {
|
|
return low;
|
|
}
|
|
const std::uint32_t left = low << distance;
|
|
const std::uint32_t right = low >> (16 - distance);
|
|
return (left | right) & 65535;
|
|
}
|
|
std::uint32_t folded_sum(std::uint32_t value) {
|
|
const std::uint32_t low = value & 255;
|
|
const std::uint32_t high = (value >> 8) & 255;
|
|
return (low * 257 + high) % 65536;
|
|
}
|
|
std::uint32_t reverse_bytes(std::uint32_t value) {
|
|
const std::uint32_t low = value & 255;
|
|
const std::uint32_t high = (value >> 8) & 255;
|
|
return low * 256 + high;
|
|
}
|
|
void account(Statistics& target, std::uint32_t word) {
|
|
accumulate(target, word);
|
|
}
|
|
std::uint32_t next_counter(std::uint32_t previous, const Job& job, const Plan& plan) {
|
|
const std::uint64_t advance = job.stride;
|
|
return (std::uint64_t(previous) + advance) % plan.modulus;
|
|
}
|
|
void account_total(Report& report, std::uint32_t word, std::uint32_t lane) {
|
|
++report.units;
|
|
const std::uint64_t mixed = std::uint64_t(report.digest) * 137 + word + lane;
|
|
report.digest = mixed % digest_mod;
|
|
}
|
|
}
|
|
std::uint32_t sample_word(const Job& job, std::uint32_t unit) {
|
|
const std::uint32_t base = (job.seed + unit * 109 + job.lane * 13) % 65536;
|
|
std::uint32_t result = 0;
|
|
switch (job.operation) {
|
|
case 0:
|
|
result = folded_sum(base);
|
|
break;
|
|
case 1:
|
|
result = rotate_word(base ^ 42405, unit % 16);
|
|
break;
|
|
case 2:
|
|
result = reverse_bytes(base) ^ ((unit * 17) & 65535);
|
|
break;
|
|
default:
|
|
result = 0;
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
int validate(const Plan& plan) {
|
|
if (plan.lanes == 0 || plan.lanes > maximum_lanes) {
|
|
return 1;
|
|
}
|
|
if (plan.modulus < 2 || plan.modulus > 65536) {
|
|
return 2;
|
|
}
|
|
if (plan.jobs.size() > 64) {
|
|
return 3;
|
|
}
|
|
for (std::uint32_t lane = 0; lane < plan.lanes; ++lane) {
|
|
if (plan.initial[lane] >= plan.modulus) {
|
|
return 4;
|
|
}
|
|
}
|
|
for (const Job& job : plan.jobs) {
|
|
if (job.lane >= plan.lanes) {
|
|
return 5;
|
|
}
|
|
if (job.units > 32) {
|
|
return 6;
|
|
}
|
|
if (job.stride == 0 || job.stride > 31) {
|
|
return 7;
|
|
}
|
|
if (job.seed > 65535) {
|
|
return 8;
|
|
}
|
|
if (job.operation > 2) {
|
|
return 9;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
Report execute(const Plan& plan, Device& device) {
|
|
struct Action {
|
|
std::uint32_t job;
|
|
std::uint32_t unit;
|
|
std::uint32_t word;
|
|
};
|
|
Report report;
|
|
report.status = validate(plan);
|
|
if (report.status) return report;
|
|
std::vector<Action> tape;
|
|
std::vector<std::size_t> boundaries{0};
|
|
for (std::uint32_t job = 0; job < plan.jobs.size(); ++job) {
|
|
const Job& descriptor = plan.jobs[job];
|
|
std::uint32_t remaining = descriptor.units;
|
|
while (remaining) {
|
|
const std::uint32_t unit = descriptor.units - remaining;
|
|
tape.push_back(Action{job, unit, sample_word(descriptor, unit)});
|
|
--remaining;
|
|
}
|
|
boundaries.push_back(tape.size());
|
|
}
|
|
report.jobs.resize(plan.jobs.size());
|
|
for (std::uint32_t id = 0; id < plan.jobs.size(); ++id) {
|
|
const Job& job = plan.jobs[id];
|
|
JobResult& result = report.jobs[id];
|
|
result.lane = job.lane;
|
|
device.begin(id, job);
|
|
std::size_t cursor = boundaries[id];
|
|
while (cursor != boundaries[id + 1]) {
|
|
const Action action = tape[cursor++];
|
|
account(result.statistics, action.word);
|
|
account(report.lanes[job.lane], action.word);
|
|
account_total(report, action.word, job.lane);
|
|
volatile ProgressRegister& bus = device.port(job.lane);
|
|
const std::uint32_t before = bus.read();
|
|
const std::uint64_t sum = std::uint64_t(before) + job.stride;
|
|
bus.write(sum % plan.modulus);
|
|
device.checkpoint(action.job, action.unit, job.lane, action.word, result.statistics.digest);
|
|
device.certificate(encode_certificate(Certificate{action.job, action.unit, job.lane, action.word, result.statistics.digest}));
|
|
}
|
|
device.end(id, job.lane, result.statistics);
|
|
}
|
|
return report;
|
|
}
|
|
}
|