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 / train / kernel-template / kernel.om
| 1 | note kernel.om: every fn here becomes an OpenCL kernel in kernel.spv and is also |
| 2 | note compiled to a native AArch64 program. reference.py must give the expected value. |
| 3 | note Scalar types: uchar ushort uint ulong byte short int long bool; at most 6 parameters. |
| 4 | |
| 5 | note Average of two uint values, rounded down, without overflow: a + b can need 33 bits. |
| 6 | fn avg a uint b uint to uint |
| 7 | ret add and a b shr xor a b uint 1 |
| 8 | end |
| 9 | |
| 10 | note Greatest common divisor (Euclid). Loops carry a bound; 64 rounds cover any 32-bit pair. |
| 11 | fn gcd a uint b uint to uint |
| 12 | while ne b 0 bound 64 |
| 13 | t = rem a b |
| 14 | a = b |
| 15 | b = t |
| 16 | end |
| 17 | ret a |
| 18 | end |
| 19 | |
| 20 | note Clamp x into lo..hi; an empty range traps with code 3 on both targets. |
| 21 | fn clamp x int lo int hi int to int |
| 22 | if gt lo hi |
| 23 | trap 3 |
| 24 | end |
| 25 | if lt x lo |
| 26 | ret lo |
| 27 | end |
| 28 | if gt x hi |
| 29 | ret hi |
| 30 | end |
| 31 | ret x |
| 32 | end |