amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

101 lines
2.2 KiB
C

#include "window.h"
static unsigned opcode(uint16_t word)
{
return word >> 8;
}
static unsigned operand(uint16_t word)
{
return word & 255u;
}
int instruction_valid(uint16_t word, int last)
{
unsigned op = opcode(word);
unsigned byte = operand(word);
if (last) {
return op == 0 && byte == 0;
}
if (op == 0 || op > 6) {
return 0;
}
if (op == 4 && byte > 31) {
return 0;
}
return 1;
}
int program_valid(const uint16_t *words, unsigned count)
{
if (words == NULL || count == 0 || count > CW_CAPACITY) {
return 0;
}
for (unsigned index = 0; index < count; ++index) {
if (!instruction_valid(words[index], index + 1 == count)) {
return 0;
}
}
return 1;
}
static uint32_t signed_operand(unsigned byte)
{
if (byte < 128) {
return byte;
}
return UINT32_MAX - (255u - byte);
}
static uint32_t rotate_left(uint32_t value, unsigned bits)
{
if (bits == 0) {
return value;
}
return (value << bits) | (value >> (32u - bits));
}
static uint32_t apply_instruction(uint32_t accumulator, uint16_t word)
{
unsigned byte = operand(word);
switch (opcode(word)) {
case 1:
return accumulator + signed_operand(byte);
case 2:
return accumulator ^ byte;
case 3:
return accumulator * byte;
case 4:
return rotate_left(accumulator, byte);
case 5:
return signed_operand(byte);
case 6:
return accumulator & byte;
default:
return accumulator;
}
}
CodeResult interpret(const uint16_t *words, unsigned count, uint32_t input)
{
CodeResult result = {CW_OK, input, 0};
if (words == NULL || count == 0 || count > CW_CAPACITY) {
result.rc = CW_EXECUTION;
result.value = 0;
return result;
}
for (unsigned index = 0; index < count; ++index) {
uint16_t word = words[index];
result.retired += 1;
if (!instruction_valid(word, index + 1 == count)) {
result.rc = CW_EXECUTION;
result.value = 0;
return result;
}
if (opcode(word) != 0) {
result.value = apply_instruction(result.value, word);
}
}
return result;
}