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>
121 lines
3.8 KiB
C++
121 lines
3.8 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) {
|
|
Report report;
|
|
report.status = validate(plan);
|
|
if (report.status != 0) {
|
|
return report;
|
|
}
|
|
report.jobs.reserve(plan.jobs.size());
|
|
for (std::size_t index = 0; index < plan.jobs.size(); ++index) {
|
|
const Job& job = plan.jobs[index];
|
|
device.begin(index, job);
|
|
JobResult result;
|
|
result.lane = job.lane;
|
|
volatile ProgressRegister& port = device.port(job.lane);
|
|
std::uint32_t cached = job.units ? port.read() : 0; // CACHE
|
|
for (std::uint32_t unit = 0; unit < job.units; ++unit) {
|
|
const std::uint32_t word = sample_word(job, unit);
|
|
account(result.statistics, word);
|
|
account(report.lanes[job.lane], word);
|
|
account_total(report, word, job.lane);
|
|
cached = next_counter(cached, job, plan); // TICK
|
|
device.checkpoint(index, unit, job.lane, word, result.statistics.digest);
|
|
device.certificate(encode_certificate(Certificate{std::uint32_t(index), unit, job.lane, word, result.statistics.digest}));
|
|
}
|
|
if (job.units) port.write(cached); // DEFER
|
|
device.end(index, job.lane, result.statistics);
|
|
report.jobs.push_back(result);
|
|
}
|
|
return report;
|
|
}
|
|
}
|