omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / omega_unwritten_trap.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "omega_unwritten_trap.h" |
| 18 | #include <string.h> |
| 19 | |
| 20 | void omega_unwritten_scan(const uint32_t *out, size_t n, uint32_t poison, uint32_t block, |
| 21 | OmegaUnwrittenReport *r) { |
| 22 | memset(r, 0, sizeof(*r)); |
| 23 | if (!out || block == 0) return; |
| 24 | uint64_t run = 0; |
| 25 | for (size_t b = 0; b < n; b += block) { |
| 26 | size_t end = b + block < n ? b + block : n; |
| 27 | uint64_t hits = 0; |
| 28 | for (size_t i = b; i < end; i++) { |
| 29 | if (out[i] == poison) { |
| 30 | if (r->count == 0) r->first = i; |
| 31 | r->last = i; |
| 32 | r->count++; |
| 33 | hits++; |
| 34 | if (run == 0) r->runs++; |
| 35 | run++; |
| 36 | if (run > r->longest_run) r->longest_run = run; |
| 37 | } else { |
| 38 | run = 0; |
| 39 | } |
| 40 | } |
| 41 | if (hits == end - b) r->full_blocks++; |
| 42 | else if (hits) r->partial_blocks++; |
| 43 | } |
| 44 | r->whole_blocks = r->count > 0 && r->partial_blocks == 0; |
| 45 | r->tail = r->count > 0 && r->last == n - 1 && r->count == (uint64_t)n - r->first; |
| 46 | } |