amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

230 lines
6.0 KiB
C++

#include "irq_internal.hpp"
namespace irqcycle {
Summary Model::summary() const {
Summary result;
for (int id=0;id<8;++id) {
const Impl::Line* line=impl_->find(id);
if (line==nullptr) {
continue;
}
const View& v=line->v;
++result.slots;
if (v.state==1) {
++result.open;
} else if (v.state==2) {
++result.closing;
} else if (v.state==3) {
++result.closed;
}
result.ready+=v.ready;
result.running+=v.running;
result.pending+=v.pending;
result.masked+=v.masked;
result.received+=v.received;
result.hard+=v.hard;
result.none+=v.none;
result.handled+=v.handled;
result.wakes+=v.wakes;
result.masked_arrivals+=v.masked_arrivals;
result.begun+=v.begun;
result.ended+=v.ended;
result.replays+=v.replays;
}
for (const auto& token:impl_->tokens) {
if (token.second) {
++result.completed_tokens;
} else {
++result.waiting_tokens;
}
}
return result;
}
bool Model::Impl::valid_line(const Line& line) const {
if (!line.present) {
return true;
}
const View& v=line.v;
if (!valid_id(v.id) || v.generation==0) {
return false;
}
if (v.state<1 || v.state>3) {
return false;
}
if (v.oneshot>1 || v.priority>7 || !valid_mode(v.mode)) {
return false;
}
if (v.ready>1 || v.running>1 || v.masked>1 || v.pending>1) {
return false;
}
if (v.ready!=0 && v.running!=0) {
return false;
}
if ((v.ticket!=0)!=(v.ready!=0)) {
return false;
}
if (v.ticket>=next_ticket) {
return false;
}
if (v.masked!=(v.oneshot!=0 && (v.ready!=0 || v.running!=0))) {
return false;
}
if (v.pending!=0 && v.ready==0 && v.running==0) {
return false;
}
if (v.begun<v.ended || v.begun-v.ended!=v.running) {
return false;
}
if (v.hard!=v.none+v.handled+v.wakes) {
return false;
}
if (v.hard<v.replays || v.received!=v.hard-v.replays+v.masked_arrivals) {
return false;
}
if (v.state==1) {
if (v.token!=0) {
return false;
}
} else {
const auto token=tokens.find(v.token);
if (token==tokens.end()) {
return false;
}
if (v.state==3) {
if (!token->second || v.ready || v.running || v.pending || v.masked || v.ticket) {
return false;
}
} else {
if (token->second || (!v.ready && !v.running && !v.pending)) {
return false;
}
}
}
return true;
}
bool Model::invariant() const {
std::set<int> members;
std::set<std::uint64_t> tickets;
std::set<std::uint64_t> current_tokens;
for (int id:impl_->queue) {
if (!members.insert(id).second) {
return false;
}
const Impl::Line* line=impl_->find(id);
if (line==nullptr || !line->v.ready) {
return false;
}
}
for (int id=0;id<8;++id) {
const Impl::Line* line=impl_->find(id);
if (line==nullptr) {
continue;
}
if (!impl_->valid_line(*line)) {
return false;
}
const View& v=line->v;
if ((members.count(id)!=0)!=(v.ready!=0)) {
return false;
}
if (v.ready && !tickets.insert(v.ticket).second) {
return false;
}
if (v.token && !current_tokens.insert(v.token).second) {
return false;
}
}
std::uint64_t expected=1;
for (const auto& entry:impl_->tokens) {
if (entry.first!=expected) {
return false;
}
if (!entry.second && current_tokens.count(entry.first)==0) {
return false;
}
++expected;
}
if (expected!=impl_->next_token) {
return false;
}
const Summary total=summary();
if (total.slots!=total.open+total.closing+total.closed) {
return false;
}
return true;
}
std::string encode(const Result& value) {
return std::to_string(value.code)+" "+std::to_string(value.value);
}
std::string encode(const View& v) {
std::ostringstream out;
out<<v.id;
out<<','<<v.generation;
out<<','<<v.state;
out<<','<<v.oneshot;
out<<','<<v.priority;
out<<','<<v.mode;
out<<','<<v.ready;
out<<','<<v.running;
out<<','<<v.masked;
out<<','<<v.pending;
out<<','<<v.ticket;
out<<','<<v.token;
out<<','<<v.received;
out<<','<<v.hard;
out<<','<<v.none;
out<<','<<v.handled;
out<<','<<v.wakes;
out<<','<<v.masked_arrivals;
out<<','<<v.begun;
out<<','<<v.ended;
out<<','<<v.replays;
return out.str();
}
std::string encode(const Summary& v) {
std::ostringstream out;
out<<v.slots;
out<<','<<v.open;
out<<','<<v.closing;
out<<','<<v.closed;
out<<','<<v.ready;
out<<','<<v.running;
out<<','<<v.pending;
out<<','<<v.masked;
out<<','<<v.received;
out<<','<<v.hard;
out<<','<<v.none;
out<<','<<v.handled;
out<<','<<v.wakes;
out<<','<<v.masked_arrivals;
out<<','<<v.begun;
out<<','<<v.ended;
out<<','<<v.replays;
out<<','<<v.waiting_tokens;
out<<','<<v.completed_tokens;
return out.str();
}
std::string Model::render() const {
std::ostringstream out;
out<<"S "<<impl_->step<<' '<<impl_->next_ticket<<' '<<impl_->next_token<<'\n';
for (int id=0;id<8;++id) {
const Impl::Line* line=impl_->find(id);
if (line!=nullptr) {
out<<"L "<<encode(line->v)<<'\n';
}
}
out<<'Q';
for (int id:impl_->ordered()) {
out<<' '<<id;
}
out<<'\n';
out<<'T';
for (const auto& entry:impl_->tokens) {
out<<' '<<entry.first<<':'<<(entry.second?1:0);
}
out<<'\n';
out<<"A "<<encode(summary())<<'\n';
out<<"I "<<(invariant()?1:0)<<'\n';
return out.str();
}
}