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

139 lines
4.1 KiB
C

#include "mode_formula.h"
#include <string.h>
static int channel_ok(int64_t c)
{
return c>=0 && c<MF_CHANNELS;
}
static int scalar_ok(int64_t x)
{
return x>=-1000 && x<=1000;
}
void mf_reset(mf_bank *b)
{
memset(b,0,sizeof(*b));
b->next_ticket=1;
}
int mf_configure(mf_bank *b,int64_t c,const mf_profile *p)
{
if (!channel_ok(c)) return MF_RANGE;
if (!scalar_ok(p->gate) || !scalar_ok(p->base) || !scalar_ok(p->gain)) return MF_RANGE;
if (!scalar_ok(p->shift) || !scalar_ok(p->scale) || !scalar_ok(p->pivot)) return MF_RANGE;
if (p->mode!=0 && p->mode!=1) return MF_RANGE;
b->channels[c].configured=1;
b->channels[c].generation++;
b->channels[c].profile=*p;
b->cutoff[c]=b->next_ticket;
return MF_OK;
}
static mf_event record(mf_bank *b,int64_t c,int64_t x)
{
mf_event event;
const mf_profile *p=&b->channels[c].profile;
int64_t raw=0;
if (p->gate!=0) {
raw=p->gain*x;
raw+=p->base;
}
event.raw=raw;
if (p->mode==0) event.value=raw;
else {
int64_t left=raw*p->scale;
int64_t right=p->pivot*p->scale;
event.value=left-right+p->shift;
}
event.ticket=b->next_ticket++;
event.generation=b->channels[c].generation;
event.input=x;
b->journal[b->journal_size]=event;
b->journal_channel[b->journal_size++]=c;
return event;
}
int mf_apply(mf_bank *b,int64_t c,int64_t x,mf_event *out)
{
if (!channel_ok(c) || !scalar_ok(x)) return MF_RANGE;
if (!b->channels[c].configured) return MF_UNCONFIGURED;
*out=record(b,c,x);
return MF_OK;
}
int mf_batch(mf_bank *b,int64_t c,const int64_t *xs,size_t n,mf_batch_result *out)
{
size_t i;
mf_batch_result result={0,0,0,0,0,0};
if (!channel_ok(c) || n>MF_BATCH) return MF_RANGE;
for (i=0;i<n;i++) if (!scalar_ok(xs[i])) return MF_RANGE;
if (!b->channels[c].configured) return MF_UNCONFIGURED;
for (i=0;i<n;i++) {
mf_event event=record(b,c,xs[i]);
if (i==0) {
result.first_ticket=event.ticket;
result.minimum=event.value;
result.maximum=event.value;
}
if (event.value<result.minimum) result.minimum=event.value;
if (event.value>result.maximum) result.maximum=event.value;
result.sum+=event.value;
}
result.count=(int64_t)n;
*out=result;
return MF_OK;
}
int mf_stats(const mf_bank *b,int64_t c,mf_channel *out)
{
size_t i;
if (!channel_ok(c)) return MF_RANGE;
memset(out,0,sizeof(*out));
out->configured=b->channels[c].configured;
out->generation=b->channels[c].generation;
out->profile=b->channels[c].profile;
for (i=0;i<b->journal_size;i++) {
const mf_event *e=&b->journal[i];
if (b->journal_channel[i]!=c || e->ticket<b->cutoff[c]) continue;
if (out->count==0) out->minimum=out->maximum=e->value;
if (e->value<out->minimum) out->minimum=e->value;
if (e->value>out->maximum) out->maximum=e->value;
out->count++;
out->sum+=e->value;
out->last_ticket=e->ticket;
}
return MF_OK;
}
int mf_history(const mf_bank *b,int64_t c,int64_t offset,mf_event *out)
{
size_t i=b->journal_size;
int64_t seen=0;
if (!channel_ok(c) || offset<0) return MF_RANGE;
if (!b->channels[c].configured) return MF_UNCONFIGURED;
if (offset>=MF_HISTORY) return MF_MISSING;
while (i>0) {
const mf_event *e=&b->journal[--i];
if (b->journal_channel[i]!=c || e->ticket<b->cutoff[c]) continue;
if (seen++==offset) {
*out=*e;
return MF_OK;
}
}
return MF_MISSING;
}
int mf_clear(mf_bank *b,int64_t c)
{
if (!channel_ok(c)) return MF_RANGE;
if (!b->channels[c].configured) return MF_UNCONFIGURED;
b->cutoff[c]=b->next_ticket;
return MF_OK;
}
int mf_get_profile(const mf_bank *bank,int64_t index,mf_profile *out,int64_t *generation)
{
const mf_channel *channel;
if (index<0 || index>=MF_CHANNELS) {
return MF_RANGE;
}
channel=&bank->channels[index];
if (!channel->configured) {
return MF_UNCONFIGURED;
}
*out=channel->profile;
*generation=channel->generation;
return MF_OK;
}