aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / om / qwen-native / tokenizer / unicode.om
| 1 | global uclass uchar 1114112 |
| 2 | global combining uchar 1114112 |
| 3 | global decomp uint 1114112 |
| 4 | global decompdata uint 16384 |
| 5 | global compkeys ulong 4096 |
| 6 | global compval uint 4096 |
| 7 | global scalars uint * |
| 8 | global nfcstate ulong 1 |
| 9 | |
| 10 | fn urange lo ulong hi ulong kind uchar to void |
| 11 | for j ulong add sub hi lo 1 |
| 12 | put uclass add lo j kind |
| 13 | end |
| 14 | end |
| 15 | |
| 16 | fn compslot key ulong to ulong |
| 17 | s = shr mul key ulong 11400714819323198485 52 |
| 18 | while ne get compval s 0 |
| 19 | if eq get compkeys s key |
| 20 | break |
| 21 | end |
| 22 | s = and add s 1 4095 |
| 23 | end |
| 24 | ret s |
| 25 | end |
| 26 | |
| 27 | fn ucomposeadd a ulong b ulong c uint to void |
| 28 | key = or shl a 21 b |
| 29 | s = compslot key |
| 30 | put compkeys s key |
| 31 | put compval s c |
| 32 | end |
| 33 | |
| 34 | fn compose a ulong b ulong to ulong |
| 35 | if and and ge a 4352 lt a 4371 and ge b 4449 lt b 4470 |
| 36 | ret add 44032 mul add mul sub a 4352 21 sub b 4449 28 |
| 37 | end |
| 38 | if and and ge a 44032 lt a 55204 and gt b 4519 lt b 4547 |
| 39 | if eq rem sub a 44032 28 0 |
| 40 | ret add a sub b 4519 |
| 41 | end |
| 42 | end |
| 43 | ret ulong get compval compslot or shl a 21 b |
| 44 | end |
| 45 | |
| 46 | note Stable canonical ordering within the current combining sequence. |
| 47 | fn ordered cp ulong to void |
| 48 | i = get nfcstate 0 |
| 49 | put nfcstate 0 add i 1 |
| 50 | cc = get combining cp |
| 51 | if ne cc 0 |
| 52 | while gt i 0 bound 9223372036854775807 |
| 53 | prev = get scalars sub i 1 |
| 54 | if le get combining prev cc |
| 55 | break |
| 56 | end |
| 57 | put scalars i prev |
| 58 | i = sub i 1 |
| 59 | end |
| 60 | end |
| 61 | put scalars i uint cp |
| 62 | end |
| 63 | |
| 64 | fn decompose cp ulong to void |
| 65 | if and ge cp 44032 lt cp 55204 |
| 66 | s = sub cp 44032 |
| 67 | ordered add 4352 div s 588 |
| 68 | ordered add 4449 rem div s 28 21 |
| 69 | if ne rem s 28 0 |
| 70 | ordered add 4519 rem s 28 |
| 71 | end |
| 72 | ret |
| 73 | end |
| 74 | v = ulong get decomp cp |
| 75 | if eq v 0 |
| 76 | ordered cp |
| 77 | else |
| 78 | for j ulong and v 7 |
| 79 | ordered ulong get decompdata add shr v 3 j |
| 80 | end |
| 81 | end |
| 82 | end |
| 83 | |
| 84 | fn recompose to ulong |
| 85 | w = ulong 0 |
| 86 | starter = ulong 0 |
| 87 | cc = uchar 0 |
| 88 | for i ulong get nfcstate 0 bound 9223372036854775807 |
| 89 | cp = get scalars i |
| 90 | nextcc = get combining cp |
| 91 | merged = ulong 0 |
| 92 | if and gt w 0 or eq cc 0 lt cc nextcc |
| 93 | merged = compose ulong get scalars starter ulong cp |
| 94 | end |
| 95 | if ne merged 0 |
| 96 | put scalars starter uint merged |
| 97 | else |
| 98 | if eq nextcc 0 |
| 99 | starter = w |
| 100 | end |
| 101 | put scalars w cp |
| 102 | w = add w 1 |
| 103 | cc = nextcc |
| 104 | end |
| 105 | end |
| 106 | ret w |
| 107 | end |