6static int span(
const void *pointer,
size_t bytes) {
7 return pointer && (uintptr_t)pointer <= UINTPTR_MAX - bytes;
11 const void *
right,
size_t right_bytes) {
12 const uintptr_t a = (uintptr_t)
left;
13 const uintptr_t b = (uintptr_t)
right;
14 return a + left_bytes <= b || b + right_bytes <= a;
18 return offset % _Alignof(int32_t) == 0 &&
19 offset <= arena_bytes &&
20 sizeof(int32_t) <= arena_bytes - offset;
23static int32_t
read_scalar(
const uint8_t *arena,
size_t offset) {
25 memcpy(&result, arena + offset,
sizeof(result));
29static void write_scalar(uint8_t *arena,
size_t offset, int32_t value) {
30 memcpy(arena + offset, &value,
sizeof(value));
36 int control_required) {
38 (uintptr_t)request->
valid_frames % _Alignof(
size_t) != 0 ||
43 SIZE_MAX /
sizeof(int32_t) &&
51 if ((control_required && !should_cancel) ||
58 (uintptr_t)request->
output_codes % _Alignof(int32_t) != 0 ||
64 if (required > SIZE_MAX /
sizeof(int32_t) ||
69 !span(request->
output_codes, required *
sizeof(int32_t)) ||
89 for (
size_t codebook = 0; codebook < request->
codebooks; ++codebook) {
96 if (should_cancel && should_cancel(cancel_context))
100 if (should_cancel && should_cancel(cancel_context))
106 for (
size_t codebook = 0; codebook < request->
codebooks; ++codebook)
110 for (
size_t step = 0; step < request->
max_frames - 1; ++step) {
111 if (should_cancel && should_cancel(cancel_context))
115 const int status = request->
frame(request->
arena,
117 if (should_cancel && should_cancel(cancel_context))
120 const size_t frames = step + 1;
122 frames * request->
codebooks *
sizeof(int32_t));
132 for (
size_t codebook = 0; codebook < request->
codebooks; ++codebook)
static int disjoint(schedule_region first, schedule_region second)
static int run_checked_frame_loop(const ck_checked_frame_loop *request, ck_checked_frame_cancel should_cancel, void *cancel_context, int control_required)
int ck_run_checked_frame_loop(const ck_checked_frame_loop *request)
static int scalar_offset(size_t offset, size_t arena_bytes)
int ck_run_checked_frame_loop_control(const ck_checked_frame_loop_control *request)
static void write_scalar(uint8_t *arena, size_t offset, int32_t value)
static int span(const void *pointer, size_t bytes)
static int disjoint(const void *left, size_t left_bytes, const void *right, size_t right_bytes)
static int32_t read_scalar(const uint8_t *arena, size_t offset)
@ CK_FRAME_LOOP_INVALID_OUTPUT
@ CK_FRAME_LOOP_BUDGET_EXHAUSTED
@ CK_FRAME_LOOP_CANCELLED
@ CK_FRAME_LOOP_ENTRY_FAILED
int(* ck_checked_frame_cancel)(void *context)
ck_checked_frame_loop base
ck_checked_frame_cancel should_cancel
const size_t * prefill_code_offsets
const size_t * frame_code_offsets
size_t prefill_valid_code_count_offset
ck_checked_frame_entry frame
size_t frame_valid_code_count_offset
ck_checked_frame_entry prefill
const char const char * right