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>
115 lines
3.0 KiB
C
115 lines
3.0 KiB
C
#include "fields.h"
|
|
|
|
int pf_token(const struct pf_field *field, uint32_t value, uint32_t *token)
|
|
{
|
|
int status = pf_shape(field);
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
if (value > pf_limit(field)) {
|
|
return PF_RANGE;
|
|
}
|
|
*token = value << (field->scale + field->bias);
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_untoken(const struct pf_field *field, uint32_t token, uint32_t *value)
|
|
{
|
|
uint32_t delta;
|
|
uint32_t quantum;
|
|
int status = pf_shape(field);
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
if (token > pf_mask(field->width) || token < field->bias) {
|
|
return PF_BAD_WORD;
|
|
}
|
|
delta = token - field->bias;
|
|
quantum = UINT32_C(1) << field->scale;
|
|
if (delta % quantum != 0u) {
|
|
return PF_BAD_WORD;
|
|
}
|
|
*value = delta / quantum;
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_encode(const struct pf_bank *bank, uint32_t *word)
|
|
{
|
|
uint32_t index;
|
|
uint32_t result = 0u;
|
|
int status = pf_layout(bank);
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
const struct pf_field *field = &bank->fields[index];
|
|
uint32_t token;
|
|
status = pf_token(field, field->value, &token);
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
result |= token << field->offset;
|
|
}
|
|
*word = result;
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_decode(const struct pf_bank *bank, uint32_t word, uint32_t *values)
|
|
{
|
|
uint32_t index;
|
|
uint32_t decoded[PF_CAPACITY];
|
|
int status = pf_layout(bank);
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
if ((word & ~pf_occupied(bank)) != 0u) {
|
|
return PF_BAD_WORD;
|
|
}
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
const struct pf_field *field = &bank->fields[index];
|
|
uint32_t token = (word >> field->offset) & pf_mask(field->width);
|
|
status = pf_untoken(field, token, &decoded[index]);
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
}
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
values[index] = decoded[index];
|
|
}
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_read(const struct pf_bank *bank, uint32_t id, uint32_t *value)
|
|
{
|
|
int index = pf_find(bank, id);
|
|
if (index < 0) {
|
|
return PF_NOT_FOUND;
|
|
}
|
|
*value = bank->fields[index].value;
|
|
return PF_OK;
|
|
}
|
|
|
|
void pf_info(const struct pf_bank *bank, uint32_t id, struct pf_info *info)
|
|
{
|
|
int index = pf_find(bank, id);
|
|
info->present = 0u;
|
|
info->width = 0u;
|
|
info->offset = 0u;
|
|
info->scale = 0u;
|
|
info->bias = 0u;
|
|
info->value = 0u;
|
|
info->limit = 0u;
|
|
info->token = 0u;
|
|
if (index >= 0) {
|
|
const struct pf_field *field = &bank->fields[index];
|
|
info->present = 1u;
|
|
info->width = field->width;
|
|
info->offset = field->offset;
|
|
info->scale = field->scale;
|
|
info->bias = field->bias;
|
|
info->value = field->value;
|
|
info->limit = pf_limit(field);
|
|
info->token = (bank->word >> field->offset) & pf_mask(field->width);
|
|
}
|
|
}
|