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

113 lines
3.8 KiB
C++

#include "bounded_channel.hpp"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace bounded;
struct Input {
std::vector<uint8_t> data;
size_t cursor = 0;
uint32_t integer(unsigned bytes) {
uint32_t value = 0;
for (unsigned n = 0; n < bytes; ++n) {
value |= uint32_t(data.at(cursor++)) << (8 * n);
}
return value;
}
std::vector<uint8_t> blob(uint32_t count) {
std::vector<uint8_t> value(data.begin() + cursor, data.begin() + cursor + count);
cursor += count;
return value;
}
};
struct Output {
std::vector<uint8_t> data;
void integer(uint64_t value, unsigned bytes = 4) {
for (unsigned n = 0; n < bytes; ++n) {
data.push_back(uint8_t(value >> (8 * n)));
}
}
void blob(const std::vector<uint8_t>& value) {
integer(value.size());
data.insert(data.end(), value.begin(), value.end());
}
void code(ApiCode code) {
integer(static_cast<uint32_t>(code));
}
void result(TransferResult& value) {
integer(value.id);
integer(static_cast<uint32_t>(value.direction));
integer(static_cast<uint32_t>(value.mode));
integer(value.requested);
integer(value.transferred);
integer(static_cast<uint32_t>(value.state));
integer(value.wait_ticks, 8);
integer(value.remaining_budget);
blob(value.bytes);
std::fill(value.bytes.begin(), value.bytes.end(), 0xa5);
}
void snapshot(ChannelSnapshot& value) {
integer(value.capacity);
integer(value.used);
integer(value.pending_readers);
integer(value.pending_writers);
integer(value.retained);
integer(value.read_cursor, 8);
integer(value.write_cursor, 8);
integer(value.tick_count, 8);
blob(value.bytes);
std::fill(value.bytes.begin(), value.bytes.end(), 0xa5);
}
};
int main() {
Input input{std::vector<uint8_t>(std::istreambuf_iterator<char>(std::cin), {})};
if (input.data.size() < 8) {
return 2;
}
input.cursor = 4;
const uint32_t commands = input.integer(4);
Output output;
output.data = {'B', 'B', 'O', '1'};
output.integer(commands);
ByteChannel channel;
for (uint32_t n = 0; n < commands; ++n) {
const uint32_t opcode = input.integer(1);
output.integer(opcode, 1);
if (opcode == 1) {
output.code(channel.reset(input.integer(4)));
} else if (opcode == 2 || opcode == 3) {
const uint32_t id = input.integer(4);
const Mode mode = static_cast<Mode>(input.integer(4));
const uint32_t budget = input.integer(4);
const uint32_t count = input.integer(4);
if (opcode == 2) {
auto data = input.blob(count);
output.code(channel.submit_write(id, data, mode, budget));
std::fill(data.begin(), data.end(), 0xa5);
} else {
output.code(channel.submit_read(id, count, mode, budget));
}
} else if (opcode == 4) {
output.code(channel.tick());
} else if (opcode == 5) {
output.code(channel.interrupt(input.integer(4)));
} else if (opcode == 6) {
auto result = channel.result(input.integer(4));
output.code(result.code);
if (result.value) {
output.result(*result.value);
}
} else if (opcode == 7) {
output.code(channel.forget(input.integer(4)));
} else if (opcode == 8) {
auto snapshot = channel.snapshot();
output.code(ApiCode::Ok);
output.snapshot(snapshot);
} else {
return 2;
}
}
std::cout.write(reinterpret_cast<const char*>(output.data.data()), output.data.size());
return 0;
}