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>
145 lines
3.6 KiB
C
145 lines
3.6 KiB
C
#include "fields.h"
|
|
|
|
uint32_t pf_mask(uint32_t width)
|
|
{
|
|
if (width == 0u || width > 16u) {
|
|
return 0u;
|
|
}
|
|
return (UINT32_C(1) << width) - UINT32_C(1);
|
|
}
|
|
|
|
uint32_t pf_limit(const struct pf_field *field)
|
|
{
|
|
uint32_t mask = pf_mask(field->width);
|
|
if (mask < field->bias || field->scale > 5u) {
|
|
return 0u;
|
|
}
|
|
return (mask - field->bias) >> field->scale;
|
|
}
|
|
|
|
uint32_t pf_bits(const struct pf_field *field)
|
|
{
|
|
if (field->offset > 31u || field->width > 32u - field->offset) {
|
|
return 0u;
|
|
}
|
|
return pf_mask(field->width) << field->offset;
|
|
}
|
|
|
|
int pf_shape(const struct pf_field *field)
|
|
{
|
|
if (field->id == 0u || field->id > 255u) {
|
|
return PF_BAD_ID;
|
|
}
|
|
if (field->width == 0u || field->width > 16u) {
|
|
return PF_BAD_LAYOUT;
|
|
}
|
|
if (field->offset > 31u || field->width > 32u - field->offset) {
|
|
return PF_BAD_LAYOUT;
|
|
}
|
|
if (field->scale > 5u || field->bias > 5u) {
|
|
return PF_BAD_LAYOUT;
|
|
}
|
|
if (field->bias > pf_mask(field->width)) {
|
|
return PF_BAD_LAYOUT;
|
|
}
|
|
return PF_OK;
|
|
}
|
|
|
|
int pf_find(const struct pf_bank *bank, uint32_t id)
|
|
{
|
|
uint32_t index;
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
if (bank->fields[index].id == id) {
|
|
return (int)index;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int pf_layout(const struct pf_bank *bank)
|
|
{
|
|
uint32_t left;
|
|
uint32_t right;
|
|
uint32_t occupied = 0u;
|
|
if (bank->count > PF_CAPACITY) {
|
|
return PF_FULL;
|
|
}
|
|
for (left = 0u; left < bank->count; ++left) {
|
|
int status = pf_shape(&bank->fields[left]);
|
|
uint32_t bits;
|
|
if (status != PF_OK) {
|
|
return status;
|
|
}
|
|
bits = pf_bits(&bank->fields[left]);
|
|
if ((occupied & bits) != 0u) {
|
|
return PF_OVERLAP;
|
|
}
|
|
occupied |= bits;
|
|
for (right = 0u; right < left; ++right) {
|
|
if (bank->fields[right].id == bank->fields[left].id) {
|
|
return PF_BAD_ID;
|
|
}
|
|
}
|
|
}
|
|
for (left = 0u; left < bank->count; ++left) {
|
|
if (bank->fields[left].value > pf_limit(&bank->fields[left])) {
|
|
return PF_RANGE;
|
|
}
|
|
}
|
|
return PF_OK;
|
|
}
|
|
|
|
uint32_t pf_occupied(const struct pf_bank *bank)
|
|
{
|
|
uint32_t index;
|
|
uint32_t bits = 0u;
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
bits |= pf_bits(&bank->fields[index]);
|
|
}
|
|
return bits;
|
|
}
|
|
|
|
static void include_number(uint32_t *hash, uint32_t number)
|
|
{
|
|
*hash = *hash * UINT32_C(33) + number;
|
|
}
|
|
|
|
uint32_t pf_fingerprint(const struct pf_bank *bank)
|
|
{
|
|
uint32_t index;
|
|
uint32_t hash = UINT32_C(5381);
|
|
include_number(&hash, bank->count);
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
const struct pf_field *field = &bank->fields[index];
|
|
include_number(&hash, field->id);
|
|
include_number(&hash, field->width);
|
|
include_number(&hash, field->offset);
|
|
include_number(&hash, field->scale);
|
|
include_number(&hash, field->bias);
|
|
}
|
|
return hash;
|
|
}
|
|
|
|
uint32_t pf_minimum_word(const struct pf_bank *bank)
|
|
{
|
|
uint32_t index;
|
|
uint32_t word = 0u;
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
const struct pf_field *field = &bank->fields[index];
|
|
word |= field->bias << field->offset;
|
|
}
|
|
return word;
|
|
}
|
|
|
|
uint32_t pf_maximum_word(const struct pf_bank *bank)
|
|
{
|
|
uint32_t index;
|
|
uint32_t word = 0u;
|
|
for (index = 0u; index < bank->count; ++index) {
|
|
const struct pf_field *field = &bank->fields[index];
|
|
uint32_t token = (pf_limit(field) << field->scale) + field->bias;
|
|
word |= token << field->offset;
|
|
}
|
|
return word;
|
|
}
|