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 / gpu / nvidia / checks / arest-tern.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/nvidia/checks/arest-tern.om: the units over gpu/nvidia/om/apirest/terndata.om: artern, artrits, arrev, |
| 3 | note as data_parts() and misc_parts() of CUDApp tests/api_rest_partitions.h call them. Composed before arestg.om. |
| 4 | text t_name "AREST-TERN" |
| 5 | text t_tern "tern" |
| 6 | text t_trits "trits" |
| 7 | text t_rev "rev" |
| 8 | note the test's trits in turn: 0, 1, -1 (byte 255) |
| 9 | fn ax_tr i ulong to uchar |
| 10 | k = rem i 3 |
| 11 | if eq k 2 |
| 12 | ret 255 |
| 13 | end |
| 14 | ret uchar k |
| 15 | end |
| 16 | note Q the four q words (n, 32, layout, 2); w[i] = ax_tr i; NY the output length |
| 17 | fn ax_tn a view ulong 4 ny ulong o edit ulong 256 to ulong |
| 18 | w = new uchar 544 0 |
| 19 | for i ulong 544 |
| 20 | put w i ax_tr i |
| 21 | end |
| 22 | y = new uint 48 0xffffffff |
| 23 | wn = mul get a 0 32 |
| 24 | r = artern a part w 0 wn part y 0 ny |
| 25 | for i ulong 48 |
| 26 | put o i ulong get y i |
| 27 | end |
| 28 | ret r |
| 29 | end |
| 30 | fn ax_tern q view ulong 256 nq ulong ny ulong o edit ulong 256 to ulong |
| 31 | if or or ne nq 4 gt get q 0 17 gt ny 48 |
| 32 | ckbad |
| 33 | end |
| 34 | a = new ulong 4 0 |
| 35 | for i ulong 4 |
| 36 | put a i get q i |
| 37 | end |
| 38 | ret ax_tn a ny o |
| 39 | end |
| 40 | note Q n and a flag: 1 sets the last trit to 2 |
| 41 | fn ax_trits q view ulong 256 nq ulong to ulong |
| 42 | n = get q 0 |
| 43 | if or ne nq 2 gt n 33 |
| 44 | ckbad |
| 45 | end |
| 46 | w = new uchar 33 0 |
| 47 | for i ulong 33 |
| 48 | put w i ax_tr i |
| 49 | end |
| 50 | if eq get q 1 1 |
| 51 | if eq n 0 |
| 52 | ckbad |
| 53 | end |
| 54 | put w sub n 1 2 |
| 55 | end |
| 56 | ret artrits part w 0 n |
| 57 | end |
| 58 | note Q n; x[i] = (float)(i % 127); the four outputs as bit patterns |
| 59 | fn ax_rev q view ulong 256 nq ulong o edit ulong 256 to ulong |
| 60 | n = get q 0 |
| 61 | if or ne nq 1 gt n 4 |
| 62 | ckbad |
| 63 | end |
| 64 | x = new f32 4 0.0f32 |
| 65 | for i ulong 4 |
| 66 | put x i f32 rem i 127 |
| 67 | end |
| 68 | y = new f32 4 7.0f32 |
| 69 | r = arrev part x 0 n y |
| 70 | for i ulong 4 |
| 71 | put o i ulong bitcast uint get y i |
| 72 | end |
| 73 | ret r |
| 74 | end |
| 75 | fn arop q view ulong 256 nq ulong ny ulong o edit ulong 256 to ulong |
| 76 | if ckis 0 t_tern |
| 77 | ret ax_tern q nq ny o |
| 78 | end |
| 79 | if ckis 0 t_trits |
| 80 | ret ax_trits q nq |
| 81 | end |
| 82 | if ckis 0 t_rev |
| 83 | ret ax_rev q nq o |
| 84 | end |
| 85 | ckbad |
| 86 | ret 0 |
| 87 | end |