interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / tests / omc / README.md

95 lines · 4883 bytes Raw Blame History Source

tests/omc: compiler words beyond the imported harness

harness/ is the Omega harness imported verbatim (harness/PROVENANCE.md), so a word this repository adds to seed/omc/omc.om cannot be documented or tested there. Its guide notes are here, written as the rows the harness guide (harness/skills/writing-omega/SKILL.md) gains when it takes the word. Its examples are in examples/, in the harness format (NAME.om, NAME.expect, optional NAME.stdout), and build.sh runs them on both targets:

EXAMPLES_ROOT=tests/omc sh tests/examples.sh out/omc out/omc-x86 [qemu-aarch64-static]

Every rule below was observed with the compilers build.sh grows from seed/ (pins in seed/PINS.tsv), on AArch64 and on x86-64 through target x86linux, with the same results on both.

count (OM-2)

count A off n v is a ulong: how many of the n elements of A from off equal v.

unitOM-2 only (the first line that is not blank or note is om2); in an OM-1 unit count is an ordinary name
Athe name of a uchar array: a local, a global, a text, or a view / edit parameter, sized or unsized (*)
off, nulong; a bare number takes ulong
vuchar; a bare number takes uchar (0..255)
resultulong, 0..n
traps3 when the slice is outside A: unless n <= len A and off <= len A - n. Nothing else
orderthe four values are read left to right; then the slice is checked; then the elements are read

The slice check is the one read and write make (vs_chk in seed/omc/omc.om): off + n is never formed, so it cannot wrap (count_trap3_wrap.om). An in-bounds slice never traps, including n = 0 at off = len A (count_word.om). The word replaces the loop

c = ulong 0
for i ulong n bound N
if eq get A add off i v
c = add c 1
end
end

with one machine loop, 16 bytes per pass (AArch64: LD1, CMEQ, SUB in NEON lanes; x86-64: MOVDQU, PCMPEQB, PSUBB in SSE2, which every x86-64 CPU has), summed every 255 passes, and the last 0..15 bytes one at a time. The loop above costs about 37 x86-64 instructions per byte under omc-x86, because every name lives in a stack slot; count measured at over 20 GB/s on a cached 1 MiB buffer.

Rows for the harness guide

Section 4, Words:

KindWords
arrays (OM-2)count A off n v

Section 5, Traps: the row "array index or I/O slice out of bounds", trap 3, gains count's slice (count_trap3.om, count_trap3_wrap.om).

Section 9, OM-2 units, gains: "count A off n v, the number of uchar elements of A[off, off+n) equal to v, the slice checked as read checks it (trap 3)".

Section 11, Compiler errors: count adds no error number. Each refusal is an existing code with its existing meaning; code 26 is still never emitted.

CodeRefusal of countExample
3count in an OM-1 unit (an unknown name or function)count_err03_om1
4fewer than four values (reported on the next line, as every error 4)count_err04_short
7A not a uchar array: another element type, a scalar, a struct or layout, a constcount_err07_element, count_err07_scalar, count_err07_struct
7off or n not ulong, v not ucharcount_err07_offset, count_err07_value
8a bare number v outside 0..255count_err08_value
9part as A (part is only a call argument)count_err09_part
16count as a name in an OM-2 unit, or as a statementcount_err16_name, count_err16_statement
27A a tracked fresh array (it leaves the analysis, as with read and write)count_err27_fresh
30count in a requires, ensures or invariant clausecount_err30_contract

Section 12, Common mistakes:

MistakeWrite insteadRefusalExample
count a 0 n 10 on its own linek = count a 0 n 10error 16count_err16_statement
count a 0 n 10 with a a uint arraya uchar array, or a looperror 7count_err07_element
count a o n c with c an intuchar cerror 7count_err07_value
a loop that checks add off n against len a itselfcount, which checks off <= len a - nwraps for huge offcount_trap3_wrap

Section 14, Example index: OM-2 and contracts gain count_word; traps gain count_trap3, count_trap3_wrap; refusals gain count_err*.

What build.sh checks