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 / runtime / rx_plan_core.om
| 1 | om2 |
| 2 | note rx_plan_core.om -- Plan IR word packing, predicate sorting, and |
| 3 | note arrangement-domain fact pack/unpack in pure OM-2. |
| 4 | note Replaces pure logic in src/runtime/rx_plan.c and src/runtime/rx_plan_arrange.c. |
| 5 | |
| 6 | note Read little-endian ulong word k (0..3) from 32-byte digest. |
| 7 | export fn rx_pl_word dig view uchar 32 k ulong to ulong |
| 8 | if ge k 4 |
| 9 | ret 0 |
| 10 | end |
| 11 | base = mul k 8 |
| 12 | v = ulong 0 |
| 13 | for i ulong 8 |
| 14 | b = ulong get dig add base i |
| 15 | v = or v shl b mul i 8 |
| 16 | end |
| 17 | ret v |
| 18 | end |
| 19 | |
| 20 | note Pack arrangement fact: bit 63=1, x.id(0..7), x.gen(8..31), |
| 21 | note floor(62), t.id(32..39), t.gen(40..61). |
| 22 | export fn rx_pla_fact_pack xid ulong xgen ulong is_floor ulong tid ulong tgen ulong to ulong |
| 23 | v = or shl ulong 1 63 and xid 255 |
| 24 | v = or v shl and xgen 16777215 8 |
| 25 | if ne is_floor 0 |
| 26 | ret or v shl ulong 1 62 |
| 27 | end |
| 28 | v = or v shl and tid 255 32 |
| 29 | v = or v shl and tgen 4194303 40 |
| 30 | ret v |
| 31 | end |
| 32 | |
| 33 | note Unpack arrangement fact into dst[0..4]: xid, xgen, is_floor, tid, tgen. |
| 34 | export fn rx_pla_fact_unpack f ulong dst edit ulong 5 to void |
| 35 | put dst 0 and f 255 |
| 36 | put dst 1 and shr f 8 16777215 |
| 37 | put dst 2 and shr f 62 1 |
| 38 | put dst 3 and shr f 32 255 |
| 39 | put dst 4 and shr f 40 4194303 |
| 40 | end |
| 41 | |
| 42 | fn pred_gt buf view ulong 288 a ulong b ulong to ulong |
| 43 | ia = mul a 6 |
| 44 | ib = mul b 6 |
| 45 | for k ulong 6 |
| 46 | va = get buf add ia k |
| 47 | vb = get buf add ib k |
| 48 | if gt va vb |
| 49 | ret 1 |
| 50 | end |
| 51 | if lt va vb |
| 52 | ret 0 |
| 53 | end |
| 54 | end |
| 55 | ret 0 |
| 56 | end |
| 57 | |
| 58 | fn pred_swap buf edit ulong 288 a ulong b ulong to void |
| 59 | ia = mul a 6 |
| 60 | ib = mul b 6 |
| 61 | for k ulong 6 |
| 62 | t = get buf add ia k |
| 63 | put buf add ia k get buf add ib k |
| 64 | put buf add ib k t |
| 65 | end |
| 66 | end |
| 67 | |
| 68 | note Insertion-sort up to 48 PlPreds packed as 6 ulongs each (kind, slot, field, slot2, type, value). |
| 69 | export fn rx_pl_sort_preds buf edit ulong 288 n ulong to void |
| 70 | if le n 1 |
| 71 | ret |
| 72 | end |
| 73 | cnt = n |
| 74 | if gt cnt 48 |
| 75 | cnt = ulong 48 |
| 76 | end |
| 77 | i = ulong 1 |
| 78 | while lt i cnt bound 48 |
| 79 | j = i |
| 80 | while gt j 0 bound 48 |
| 81 | jm = sub j 1 |
| 82 | if eq pred_gt buf jm j 0 |
| 83 | break |
| 84 | end |
| 85 | pred_swap buf jm j |
| 86 | j = jm |
| 87 | end |
| 88 | i = add i 1 |
| 89 | end |
| 90 | end |