amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

76 lines
2.0 KiB
C

#include "sim_device.h"
#include <string.h>
static void record(struct sim_device *device, int op, unsigned first,
unsigned second, int status)
{
if (device->count < SIM_EVENTS) {
struct sim_event *event = &device->events[device->count];
event->op = op;
event->first = first;
event->second = second;
event->status = status;
}
++device->count;
}
static int set_width(struct sim_device *device, unsigned channel, unsigned bits)
{
int status = DMA_OK;
if (bits < 1 || bits > 64) {
status = DMA_EINVAL;
} else if (bits > device->caps[channel]) {
status = DMA_ENOTSUP;
} else if (device->transient[channel][bits] > 0) {
--device->transient[channel][bits];
status = DMA_EAGAIN;
} else {
device->bits[channel] = bits;
}
record(device, (int)channel, bits, 0, status);
return status;
}
static int streaming(void *context, unsigned bits)
{
return set_width(context, 0, bits);
}
static int coherent(void *context, unsigned bits)
{
return set_width(context, 1, bits);
}
static void restore(void *context, unsigned streaming_bits, unsigned coherent_bits)
{
struct sim_device *device = context;
device->bits[0] = streaming_bits;
device->bits[1] = coherent_bits;
record(device, 2, streaming_bits, coherent_bits, 0);
}
void sim_init(struct sim_device *device, unsigned streaming_cap,
unsigned coherent_cap, unsigned streaming_bits, unsigned coherent_bits)
{
memset(device, 0, sizeof(*device));
device->caps[0] = streaming_cap;
device->caps[1] = coherent_cap;
device->bits[0] = streaming_bits;
device->bits[1] = coherent_bits;
}
struct dma_backend sim_backend(struct sim_device *device)
{
struct dma_backend backend;
backend.context = device;
backend.streaming = streaming;
backend.coherent = coherent;
backend.restore = restore;
return backend;
}
void sim_clear(struct sim_device *device)
{
device->count = 0;
}