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

106 lines
2.3 KiB
C++

#include "model_internal.hpp"
#include <algorithm>
namespace ps {
Model::Model() : state(new Impl) {
}
Model::~Model() = default;
void Model::reset() {
state.reset(new Impl);
}
bool valid_device(int device) {
return device >= 0 && device < 4;
}
bool valid_actor(int actor) {
return actor >= 0 && actor < 8;
}
int device_error(const Impl &state, int device) {
if (!valid_device(device)) {
return -22;
}
if (!state.devices[device].live) {
return -19;
}
return 0;
}
int watch_error(const Impl &state, int actor, std::uint64_t token) {
if (!valid_actor(actor)) {
return -22;
}
const auto &watch = state.actors[actor].view;
if (watch.phase == IDLE || watch.token != token) {
return -116;
}
return 0;
}
unsigned readiness(const Device &device) {
unsigned result = device.flags;
if (!device.bytes.empty()) {
result |= READ;
}
if (device.credits != 0 && !(device.flags & HUP)) {
result |= WRITE;
}
return result;
}
unsigned filter_ready(unsigned bits, unsigned requested) {
return (bits & requested & (READ | WRITE)) | (bits & (ERROR | HUP));
}
bool is_terminal(int phase) {
return phase >= READY && phase <= GONE;
}
int terminal_result(const WatchView &watch) {
switch (watch.phase) {
case READY:
return 1;
case CANCELLED:
return -125;
case INTERRUPTED:
return -4;
case GONE:
return -19;
default:
return 0;
}
}
void subscribe(Impl &state, int actor) {
state.actors[actor].view.registered = 1;
}
void unsubscribe(Impl &state, int actor) {
state.actors[actor].view.registered = 0;
}
int finish_watch(Impl &state, int actor, int phase) {
auto &watch = state.actors[actor].view;
unsubscribe(state, actor);
watch.phase = phase;
watch.ready = 0;
watch.pending = 0;
return 0;
}
std::vector<std::uint8_t> queue_data(const Device &device) {
return {device.bytes.begin(), device.bytes.end()};
}
void queue_append(Device &device, const std::vector<std::uint8_t> &data) {
device.bytes.insert(device.bytes.end(), data.begin(), data.end());
}
void queue_consume(Device &device, int count) {
device.bytes.erase(device.bytes.begin(), device.bytes.begin() + count);
}
}