sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / seed / LOCAL.patch
| 1 | --- a/seed/omc/omc.om |
| 2 | +++ b/seed/omc/omc.om |
| 3 | @@ -1374,8 +1374,8 @@ |
| 4 | end |
| 5 | |
| 6 | note ======== OM-2 words (spec/omegese-om2.md): reserved only in an OM-2 unit. rotr 59, rotl 60 are |
| 7 | -note binary operators; dit 225 and scrub 226 are program-mode value words (OMEGESE 9.13.1); the rest are |
| 8 | -note statement and declaration words of later sections. ======== |
| 9 | +note binary operators; dit 225 and scrub 226 are program-mode value words (OMEGESE 9.13.1); count 179 is a |
| 10 | +note value word (cnt_word); the rest are statement and declaration words of later sections. ======== |
| 11 | fn kw2 w ulong to ulong |
| 12 | if eq w 1920233330 |
| 13 | ret 59 |
| 14 | @@ -1437,6 +1437,9 @@ |
| 15 | if eq w 422877225843 |
| 16 | ret 226 |
| 17 | end |
| 18 | +if eq w 500069396323 |
| 19 | +ret 179 |
| 20 | +end |
| 21 | ret 0 |
| 22 | end |
| 23 | |
| 24 | @@ -4499,10 +4502,6 @@ |
| 25 | fn ffma dst ulong to void |
| 26 | o = get fpo 0 |
| 27 | put fpo 0 0 |
| 28 | -note x86's baseline is SSE2, not FMA3. No unfused fallback is permitted. |
| 29 | -if or ne get irmode 0 0 ne get xtarget 0 0 |
| 30 | -fail 9 |
| 31 | -end |
| 32 | put fpw 0 1 |
| 33 | rdval 0 0 255 0 |
| 34 | if eq get rk 0 6 |
| 35 | @@ -4532,6 +4531,12 @@ |
| 36 | if ne get rt 0 at |
| 37 | fail 7 |
| 38 | end |
| 39 | +note x86's baseline is SSE2, not FMA3. No unfused fallback is permitted. The operands are typed |
| 40 | +note first, so an ill-typed fma gets the same error 7 or 11 on every target; only a well-typed one |
| 41 | +note is refused here. |
| 42 | +if or ne get irmode 0 0 ne get xtarget 0 0 |
| 43 | +fail 9 |
| 44 | +end |
| 45 | va = fvop ak av at 0 |
| 46 | vb = fvop bk bv at 1 |
| 47 | vc = fvop get rk 0 get rv 0 at 2 |
| 48 | @@ -5752,6 +5757,114 @@ |
| 49 | vdone 1 r 9 |
| 50 | end |
| 51 | |
| 52 | +note cnt_word: OM-2 `count A off n v`, a ulong: how many of the n uchar elements of A from off equal v. |
| 53 | +note A is an array name (a local, global, text, or a view or edit parameter, sized or unsized); off and n |
| 54 | +note are ulong, v is uchar. The four values are read left to right; then the slice is checked exactly as |
| 55 | +note read and write check theirs (vs_chk: a non-uchar A is error 7; n <= len A and off <= len A - n, else |
| 56 | +note trap 3), and only then is any element read, so an out-of-bounds slice traps 3 whatever v is and an |
| 57 | +note in-bounds one never traps. A tracked fresh array (error 27, fz_arg), a struct or layout (error 7) and |
| 58 | +note a contract clause (error 30, cp_token) are refused; an IR unit is never OM-2, so count is no word there |
| 59 | +note (error 3), and the irmode guard (error 9, as dit) only keeps it so. Code (AArch64): P = A + off |
| 60 | +note (ADD, C6.2.6), M = n (MOV = ORR), V0 = v in all 16 byte lanes (DUP), S = 0 (MOVZ, C6.2.285); then |
| 61 | +note while M >= 16 (CMP, C6.2.96; B.LO, C6.2.34): a block of K = min(M >> 4, 255) chunks (LSR = UBFM, |
| 62 | +note C6.2.487; CMP; B.LS; MOVZ X16, #255; V1 = 0 by MOVI, C7.2.247), each chunk LD1 {V2.16B}, [P], #16 |
| 63 | +note (post-index), CMEQ V2, V2, V0 (0xff where equal), SUB V1.16B, V1, V2 (+1 per equal lane; 255 chunks |
| 64 | +note keep each lane <= 255), SUB M, M, #16, SUBS X16, X16, #1, B.NE; then UADDLV H2, V1.16B (the 16 lanes, |
| 65 | +note at most 4080), UMOV W16, V2.H[0], ADD S, S, X16, B back (C6.2.35). The last M < 16 bytes one at a |
| 66 | +note time: CBZ M (C6.2.78), UMOV WK, V0.B[0], LDRB W16, [P], #1 (post-index), CMP W16, WK, CINC S, S, EQ |
| 67 | +note (CSINC), SUBS M, M, #1, B.NE. Every word is a fixed part from the instruction's Arm ARM encoding ORed |
| 68 | +note with register fields; each fixed part was checked against llvm-mc 18 at two or more register |
| 69 | +note choices. P, M, S and K are new temporaries, so no name's register changes; X16 is scratch; |
| 70 | +note V0-V2 carry nothing between operations (see scrub). The result moves to the destination after the |
| 71 | +note temporaries are given back. |
| 72 | +fn cnt_word dst ulong to void |
| 73 | +if ne get irmode 0 0 |
| 74 | +fail 9 |
| 75 | +end |
| 76 | +x = mul get depth 0 32 |
| 77 | +sl = get nslot 0 |
| 78 | +put fr add x 8 sl |
| 79 | +e = arrname |
| 80 | +fz_arg e |
| 81 | +if ge get nm_kind sub e 1 6 |
| 82 | +fail 7 |
| 83 | +end |
| 84 | +rdval 0 5 255 0 |
| 85 | +vs_off x |
| 86 | +rdval 0 5 255 0 |
| 87 | +if ne get rt 0 5 |
| 88 | +fail 7 |
| 89 | +end |
| 90 | +put fr add x 12 matreg get rk 0 get rv 0 get rt 0 |
| 91 | +rdval 0 2 255 0 |
| 92 | +if ne get rt 0 2 |
| 93 | +fail 7 |
| 94 | +end |
| 95 | +v = matreg get rk 0 get rv 0 get rt 0 |
| 96 | +ro = get fr add x 11 |
| 97 | +rn = get fr add x 12 |
| 98 | +vs_chk e ro rn |
| 99 | +if ne get xtarget 0 0 |
| 100 | +xcount e ro rn v |
| 101 | +put nslot 0 sl |
| 102 | +d = destreg dst |
| 103 | +xrr 137 0 2 |
| 104 | +xstore 0 d |
| 105 | +vdone 1 d 5 |
| 106 | +ret |
| 107 | +end |
| 108 | +s = cnt_a64 e ro rn v |
| 109 | +put nslot 0 sl |
| 110 | +d = destreg dst |
| 111 | +if ne d s |
| 112 | +emit or or 2852127712 d shl s 16 |
| 113 | +end |
| 114 | +vdone 1 d 5 |
| 115 | +end |
| 116 | + |
| 117 | +note cnt_a64: the AArch64 loop of cnt_word (see there), after vs_chk; gives S, the register of the count |
| 118 | +fn cnt_a64 e ulong ro ulong rn ulong v ulong to ulong |
| 119 | +i = sub e 1 |
| 120 | +p = alloc |
| 121 | +if ge get nm_kind i 4 |
| 122 | +matconst p get nm_addr i |
| 123 | +e3 2332033024 p p ro |
| 124 | +else |
| 125 | +e3 2332033024 p ulong get nm_reg i ro |
| 126 | +end |
| 127 | +m = alloc |
| 128 | +emit or or 2852127712 m shl rn 16 |
| 129 | +emit or 1308691456 shl v 5 |
| 130 | +s = alloc |
| 131 | +emit or 3531603968 s |
| 132 | +k = alloc |
| 133 | +emit or 4043325471 shl m 5 |
| 134 | +emit 1409286659 |
| 135 | +emit or 3544513552 shl m 5 |
| 136 | +emit 4043570719 |
| 137 | +emit 1409286217 |
| 138 | +emit 3531612144 |
| 139 | +emit 1862329345 |
| 140 | +emit or 1289711618 shl p 5 |
| 141 | +emit 1847626818 |
| 142 | +emit 1847755809 |
| 143 | +emit or or 3506454528 m shl m 5 |
| 144 | +emit 4043310608 |
| 145 | +emit 1426063201 |
| 146 | +emit 1848653858 |
| 147 | +emit 235027536 |
| 148 | +emit or or 2333081600 s shl s 5 |
| 149 | +emit 402653168 |
| 150 | +emit or 3019899104 m |
| 151 | +emit or 234961920 k |
| 152 | +emit or 943723536 shl p 5 |
| 153 | +emit or 1795162655 shl k 16 |
| 154 | +emit or or or 2592084992 s shl s 5 shl s 16 |
| 155 | +emit or or 4043310080 m shl m 5 |
| 156 | +emit 1426063233 |
| 157 | +ret s |
| 158 | +end |
| 159 | + |
| 160 | note Native Linux ARM64 host operations. Encoding forms are those in seed/rung2/table.s2. |
| 161 | note Syscall numbers and layouts: Linux asm-generic/unistd.h, fcntl.h and time.h. |
| 162 | note No raw address or arbitrary syscall is exposed to an Omega program. |
| 163 | @@ -8578,6 +8691,10 @@ |
| 164 | vdec |
| 165 | ret |
| 166 | end |
| 167 | +if eq c 179 |
| 168 | +cnt_word dst |
| 169 | +ret |
| 170 | +end |
| 171 | if eq c 51 |
| 172 | e = arrname |
| 173 | if ge get nm_kind sub e 1 6 |
| 174 | @@ -17012,6 +17129,101 @@ |
| 175 | emitb 5 |
| 176 | end |
| 177 | |
| 178 | +note xcount: the x86-64 loop of cnt_word, after vs_chk. RSI = A + off (LEA of a global or text, else the |
| 179 | +note array's slot; ADD), RCX = n, AL = v (zero-extended uchar). XMM0 = v in all 16 byte lanes (MOVD, |
| 180 | +note PUNPCKLBW, PSHUFLW 0, PSHUFD 0), XMM3 = 0, EDX = 0 (the count). While RCX >= 16 (CMP; JB): a block of |
| 181 | +note R8 = min(RCX >> 4, 255) chunks (MOV, SHR, CMP, JBE, MOV R8D 255; PXOR XMM1), each chunk MOVDQU XMM2, |
| 182 | +note [RSI]; PCMPEQB XMM2, XMM0 (0xff where equal); PSUBB XMM1, XMM2 (+1 per equal lane; 255 chunks keep |
| 183 | +note each lane <= 255); ADD RSI, 16; SUB RCX, 16; DEC R8; JNE; then PSADBW XMM1, XMM3 (each 8-lane half |
| 184 | +note summed into its quadword), MOVQ R9 / ADD RDX twice around PSRLDQ XMM1, 8, JMP back. The last RCX < 16 |
| 185 | +note bytes one at a time: TEST; JE; CMP [RSI], AL; JNE; INC RDX; INC RSI; DEC RCX; JNE. SSE2 only (every |
| 186 | +note x86-64 CPU), unaligned loads, never a byte outside the checked slice. The 128 bytes after the four |
| 187 | +note setup moves are fixed (Intel SDM vol. 2 encodings, checked byte for byte against llvm-mc 18; the short |
| 188 | +note jumps' distances are constant); RDX holds the result for cnt_word. RAX, RCX, RDX, RSI, R8, R9 and |
| 189 | +note XMM0-XMM3 are emitter scratch here: language values live in RBP slots. |
| 190 | +fn xcount e ulong ro ulong rn ulong v ulong to void |
| 191 | +i = sub e 1 |
| 192 | +if ge get nm_kind i 4 |
| 193 | +xaddr 6 get nm_addr i |
| 194 | +else |
| 195 | +xload 6 ulong get nm_reg i |
| 196 | +end |
| 197 | +xload 0 ro |
| 198 | +xrr 1 6 0 |
| 199 | +xload 1 rn |
| 200 | +xload 0 v |
| 201 | +xb 102 15 110 |
| 202 | +emitb 192 |
| 203 | +xb 102 15 96 |
| 204 | +emitb 192 |
| 205 | +xb 242 15 112 |
| 206 | +emitb 192 |
| 207 | +emitb 0 |
| 208 | +xb 102 15 112 |
| 209 | +emitb 192 |
| 210 | +emitb 0 |
| 211 | +xb 102 15 239 |
| 212 | +emitb 219 |
| 213 | +emitb 49 |
| 214 | +emitb 210 |
| 215 | +xb 72 131 249 |
| 216 | +emitb 16 |
| 217 | +emitb 114 |
| 218 | +emitb 78 |
| 219 | +xb 73 137 200 |
| 220 | +xb 73 193 232 |
| 221 | +emitb 4 |
| 222 | +xb 73 129 248 |
| 223 | +xb 255 0 0 |
| 224 | +emitb 0 |
| 225 | +emitb 118 |
| 226 | +emitb 6 |
| 227 | +xb 65 184 255 |
| 228 | +xb 0 0 0 |
| 229 | +xb 102 15 239 |
| 230 | +emitb 201 |
| 231 | +xb 243 15 111 |
| 232 | +emitb 22 |
| 233 | +xb 102 15 116 |
| 234 | +emitb 208 |
| 235 | +xb 102 15 248 |
| 236 | +emitb 202 |
| 237 | +xb 72 131 198 |
| 238 | +emitb 16 |
| 239 | +xb 72 131 233 |
| 240 | +emitb 16 |
| 241 | +xb 73 255 200 |
| 242 | +emitb 117 |
| 243 | +emitb 231 |
| 244 | +xb 102 15 246 |
| 245 | +emitb 203 |
| 246 | +xb 102 73 15 |
| 247 | +emitb 126 |
| 248 | +emitb 201 |
| 249 | +xb 76 1 202 |
| 250 | +xb 102 15 115 |
| 251 | +emitb 217 |
| 252 | +emitb 8 |
| 253 | +xb 102 73 15 |
| 254 | +emitb 126 |
| 255 | +emitb 201 |
| 256 | +xb 76 1 202 |
| 257 | +emitb 235 |
| 258 | +emitb 172 |
| 259 | +xb 72 133 201 |
| 260 | +emitb 116 |
| 261 | +emitb 15 |
| 262 | +emitb 56 |
| 263 | +emitb 6 |
| 264 | +emitb 117 |
| 265 | +emitb 3 |
| 266 | +xb 72 255 194 |
| 267 | +xb 72 255 198 |
| 268 | +xb 72 255 201 |
| 269 | +emitb 117 |
| 270 | +emitb 241 |
| 271 | +end |
| 272 | + |
| 273 | fn xarray w ulong to void |
| 274 | if ne get nb 0 0 |
| 275 | fail 9 |