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>
89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
#include "flag_audit.h"
|
|
#include <stdint.h>
|
|
|
|
static cfg_status validate_field(unsigned width, unsigned offset,
|
|
unsigned bits, unsigned is_signed)
|
|
{
|
|
if (!cfg_width_valid(width)) {
|
|
return CFG_WIDTH;
|
|
}
|
|
if (bits < 1 || bits > 32 || offset >= width ||
|
|
bits > width - offset || is_signed > 1) {
|
|
return CFG_FIELD;
|
|
}
|
|
return CFG_OK;
|
|
}
|
|
|
|
static int64_t decode_signed(uint64_t raw, unsigned bits)
|
|
{
|
|
uint64_t sign = UINT64_C(1) << (bits - 1);
|
|
if ((raw & sign) != 0) {
|
|
return (int64_t)raw - (INT64_C(1) << bits);
|
|
}
|
|
return (int64_t)raw;
|
|
}
|
|
|
|
cfg_status cfg_extract(uint64_t raw, unsigned width, unsigned offset,
|
|
unsigned bits, unsigned is_signed, cfg_field *out)
|
|
{
|
|
cfg_status status;
|
|
cfg_field result;
|
|
uint64_t mask;
|
|
status = validate_field(width, offset, bits, is_signed);
|
|
if (status != CFG_OK) {
|
|
return status;
|
|
}
|
|
mask = cfg_mask(bits);
|
|
result.raw = (raw >> offset) & mask;
|
|
if (is_signed) {
|
|
result.value = decode_signed(result.raw, bits);
|
|
} else {
|
|
result.value = (int64_t)result.raw;
|
|
}
|
|
*out = result;
|
|
return CFG_OK;
|
|
}
|
|
|
|
static int value_fits(int64_t value, unsigned bits, unsigned is_signed)
|
|
{
|
|
int64_t minimum;
|
|
int64_t maximum;
|
|
if (is_signed) {
|
|
int64_t half = INT64_C(1) << (bits - 1);
|
|
minimum = -half;
|
|
maximum = half - 1;
|
|
} else {
|
|
minimum = 0;
|
|
maximum = (int64_t)cfg_mask(bits);
|
|
}
|
|
return value >= minimum && value <= maximum;
|
|
}
|
|
|
|
static uint64_t encode_field(int64_t value, unsigned bits)
|
|
{
|
|
uint64_t mask = cfg_mask(bits);
|
|
return (uint64_t)value & mask;
|
|
}
|
|
|
|
cfg_status cfg_insert(uint64_t raw, unsigned width, unsigned offset,
|
|
unsigned bits, unsigned is_signed, int64_t value,
|
|
uint64_t *out)
|
|
{
|
|
cfg_status status;
|
|
uint64_t field_mask;
|
|
uint64_t encoded;
|
|
uint64_t result;
|
|
status = validate_field(width, offset, bits, is_signed);
|
|
if (status != CFG_OK) {
|
|
return status;
|
|
}
|
|
if (!value_fits(value, bits, is_signed)) {
|
|
return CFG_RANGE;
|
|
}
|
|
field_mask = cfg_mask(bits) << offset;
|
|
encoded = encode_field(value, bits) << offset;
|
|
result = ((raw & ~field_mask) | encoded) & cfg_mask(width);
|
|
*out = result;
|
|
return CFG_OK;
|
|
}
|