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>
172 lines
4.3 KiB
C
172 lines
4.3 KiB
C
#include "fields.h"
|
|
#include <string.h>
|
|
|
|
void pf_init(struct pf_bank *bank)
|
|
{
|
|
memset(bank, 0, sizeof(*bank));
|
|
}
|
|
|
|
static int reject(struct pf_bank *bank, int status)
|
|
{
|
|
bank->rejects += 1u;
|
|
return status;
|
|
}
|
|
|
|
static struct pf_field new_field(uint32_t id, uint32_t width,
|
|
uint32_t offset, uint32_t scale,
|
|
uint32_t bias)
|
|
{
|
|
struct pf_field field;
|
|
field.id = id;
|
|
field.width = width;
|
|
field.offset = offset;
|
|
field.scale = scale;
|
|
field.bias = bias;
|
|
field.value = 0u;
|
|
return field;
|
|
}
|
|
|
|
static int commit_layout(struct pf_bank *bank, struct pf_bank *trial)
|
|
{
|
|
uint32_t word;
|
|
int status = pf_layout(trial);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
status = pf_encode(trial, &word);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
trial->word = word;
|
|
trial->epoch += 1u;
|
|
*bank = *trial;
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_add(struct pf_bank *bank, uint32_t id, uint32_t width,
|
|
uint32_t offset, uint32_t scale, uint32_t bias)
|
|
{
|
|
struct pf_bank trial = *bank;
|
|
struct pf_field field = new_field(id, width, offset, scale, bias);
|
|
int status = pf_shape(&field);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
if (pf_find(bank, id) >= 0) {
|
|
return reject(bank, PF_BAD_ID);
|
|
}
|
|
if (bank->count == PF_CAPACITY) {
|
|
return reject(bank, PF_FULL);
|
|
}
|
|
trial.fields[trial.count] = field;
|
|
trial.count += 1u;
|
|
return commit_layout(bank, &trial);
|
|
}
|
|
|
|
int pf_replace(struct pf_bank *bank, uint32_t id, uint32_t width,
|
|
uint32_t offset, uint32_t scale, uint32_t bias)
|
|
{
|
|
struct pf_bank trial = *bank;
|
|
struct pf_field field = new_field(id, width, offset, scale, bias);
|
|
int index = pf_find(bank, id);
|
|
int status;
|
|
if (index < 0) {
|
|
return reject(bank, PF_NOT_FOUND);
|
|
}
|
|
status = pf_shape(&field);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
field.value = trial.fields[index].value;
|
|
trial.fields[index] = field;
|
|
return commit_layout(bank, &trial);
|
|
}
|
|
|
|
int pf_drop(struct pf_bank *bank, uint32_t id)
|
|
{
|
|
struct pf_bank trial = *bank;
|
|
int index = pf_find(bank, id);
|
|
uint32_t cursor;
|
|
if (index < 0) {
|
|
return reject(bank, PF_NOT_FOUND);
|
|
}
|
|
for (cursor = (uint32_t)index; cursor + 1u < trial.count; ++cursor) {
|
|
trial.fields[cursor] = trial.fields[cursor + 1u];
|
|
}
|
|
trial.count -= 1u;
|
|
memset(&trial.fields[trial.count], 0, sizeof(trial.fields[trial.count]));
|
|
return commit_layout(bank, &trial);
|
|
}
|
|
|
|
int pf_write(struct pf_bank *bank, uint32_t id, uint32_t value)
|
|
{
|
|
struct pf_bank trial = *bank;
|
|
uint32_t word;
|
|
int index = pf_find(bank, id);
|
|
int status;
|
|
if (index < 0) {
|
|
return reject(bank, PF_NOT_FOUND);
|
|
}
|
|
if (value > pf_limit(&trial.fields[index])) {
|
|
return reject(bank, PF_RANGE);
|
|
}
|
|
trial.fields[index].value = value;
|
|
status = pf_encode(&trial, &word);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
trial.word = word;
|
|
trial.writes += 1u;
|
|
*bank = trial;
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_import(struct pf_bank *bank, uint32_t word)
|
|
{
|
|
uint32_t values[PF_CAPACITY];
|
|
uint32_t index;
|
|
int status = pf_decode(bank, word, values);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
bank->fields[index].value = values[index];
|
|
}
|
|
bank->word = word;
|
|
bank->imports += 1u;
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_zero(struct pf_bank *bank)
|
|
{
|
|
struct pf_bank trial = *bank;
|
|
uint32_t index;
|
|
uint32_t word;
|
|
int status;
|
|
for (index = 0u; index < trial.count; ++index) {
|
|
trial.fields[index].value = 0u;
|
|
}
|
|
status = pf_encode(&trial, &word);
|
|
if (status != PF_OK) {
|
|
return reject(bank, status);
|
|
}
|
|
trial.word = word;
|
|
trial.writes += 1u;
|
|
*bank = trial;
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_clear(struct pf_bank *bank)
|
|
{
|
|
uint32_t epoch = bank->epoch + 1u;
|
|
uint32_t writes = bank->writes;
|
|
uint32_t imports = bank->imports;
|
|
uint32_t rejects = bank->rejects;
|
|
pf_init(bank);
|
|
bank->epoch = epoch;
|
|
bank->writes = writes;
|
|
bank->imports = imports;
|
|
bank->rejects = rejects;
|
|
return PF_OK;
|
|
}
|