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 / om / gpu / dsv41 / lookup.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Little-endian f32 decode table. First 256 E4M3FN encodings, then 16 E2M1 encodings. |
| 3 | om2 |
| 4 | fn e4m3 c uint to uint |
| 5 | e = and shr c 3 15 |
| 6 | m = and c 7 |
| 7 | raw = or shl add e 120 23 shl m 20 |
| 8 | if eq e 0 |
| 9 | raw = bitcast uint mul f32 m 0.001953125f32 |
| 10 | end |
| 11 | if and eq e 15 eq m 7 |
| 12 | raw = uint 0x7fc00000 |
| 13 | end |
| 14 | ret or raw shl and c 128 24 |
| 15 | end |
| 16 | fn e2m1 c uint to uint |
| 17 | e = and shr c 1 3 |
| 18 | m = and c 1 |
| 19 | raw = or shl add e 126 23 shl m 22 |
| 20 | if eq e 0 |
| 21 | raw = bitcast uint mul f32 m 0.5f32 |
| 22 | end |
| 23 | ret or raw shl and c 8 28 |
| 24 | end |
| 25 | fn main to int |
| 26 | buf = new uchar 1088 0 |
| 27 | for i ulong 272 |
| 28 | v = e4m3 uint i |
| 29 | if ge i 256 |
| 30 | v = e2m1 uint sub i 256 |
| 31 | end |
| 32 | for j ulong 4 |
| 33 | put buf add mul i 4 j uchar and shr v uint mul j 8 255 |
| 34 | end |
| 35 | end |
| 36 | if ne write 1 buf 0 1088 1088 |
| 37 | ret 1 |
| 38 | end |
| 39 | ret 0 |
| 40 | end |