Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/ng/ngcheck.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / ng / ngcheck.om` 2373 lines · 46991 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/ng/ngcheck.om: the ΩIR witness (seed/ng/IR.md s9, s11). Owner: ng-ir lane (Hive NG M0). 3 note It has its own reader: no code is shared with seed/ng/src/ir.om or opt.om (D1b). Build: 4 note cat seed/ng/sha256.om seed/ng/ngcheck.om | seed/out/omc > ngcheck 5 note ngcheck < unit.ir exit 0 and "ACCEPT fns=N blocks=N ops=N" on stdout, or exit with 6 note the refusal class (10..29) and "ngcheck: CLASS at OFFSET" on stderr 7 note ngcheck --table print the host word table compiled in (equal to seed/ng/hostwords.tsv) 8 note Order (IR.md s11): phase 1 reads the module front to back and checks every rule that needs only 9 note the bytes of one record (header, type table, globals, function and block headers, op rows and 10 note counts); phase 2 checks each function in order: terminators, branch targets, reachability, 11 note then each op in block and op order (ids and dominance, token, result type, placement, codes, 12 note typing, coverage, facts). The first fault ends the run. 13 text c_cls "MAGIC\nVERSION\nTRUNCATED\nNONCANONICAL\nTRAILING\nUNKNOWN_OP\nTYPE\nUSE_BEFORE_DEF\nDOMINANCE\nBLOCK_ARITY\nUNTERMINATED\nCHECK_CODE\nEFFECT\nLIMIT\nREF\nUNCHECKED\nUNREACHABLE\nIO\nTOKEN\nFACT\nENTRY\n" 14 const c_hxn ulong 52 15 text c_tx "ngcheck: \n at \nACCEPT \n fns=\n blocks=\n ops=\n--table\nngcheck: usage: ngcheck [--table] < unit.ir\nOSC1IR\nomega.ng.ir.v1\n" 16 note the op rows of IR.md s7.12: op tk imm fix var ty (tk 0 P 1 E 2 R 3 T; ty 0 none 1 r 2 o 3 p) 17 text c_rows "1 0 1 0 0 1 2 0 0 3 0 1 10 0 0 2 0 1 11 0 0 2 0 1 12 0 0 2 0 1 13 0 0 2 0 1 14 0 0 2 0 1 15 0 0 1 0 1 16 0 0 2 0 1 17 0 0 2 0 1 18 0 0 2 0 1 19 0 0 1 0 1 20 0 0 2 0 1 21 0 0 2 0 1 22 0 0 2 0 1 23 0 0 2 0 1 24 0 0 2 0 1 25 0 0 2 0 1 26 0 0 1 0 1 27 0 0 1 0 1 28 0 1 1 0 1 30 0 0 2 0 1 31 0 0 2 0 1 32 0 0 2 0 1 33 0 0 2 0 1 34 0 0 2 0 1 35 0 0 2 0 1 36 0 1 1 0 1 37 0 0 1 0 1 40 0 1 0 0 1 41 0 0 0 0 1 42 2 0 2 0 1 43 1 0 3 0 0 44 1 0 0 0 0 45 0 1 2 0 1 46 0 0 3 0 1 47 1 1 3 0 1 48 1 1 4 0 1 50 1 0 0 0 1 51 1 0 2 0 0 52 0 1 0 0 1 53 0 0 1 0 1 54 2 0 3 0 1 55 2 1 1 0 1 56 1 1 2 0 0 57 0 1 1 0 1 58 2 0 2 0 1 59 1 0 3 0 0 60 3 0 1 1 0 61 3 0 3 0 0 62 3 0 0 0 0 63 3 0 1 0 0 64 1 0 1 1 2 65 3 1 0 0 0 66 3 0 1 0 0 67 1 0 4 1 0 70 1 1 2 0 0 71 1 1 2 0 0 72 1 1 2 0 0 73 1 1 1 0 0 74 1 1 1 0 0 75 1 1 2 0 0 76 1 1 2 0 0 77 1 1 1 0 0 78 1 1 1 0 3 79 1 1 3 0 0 80 1 1 3 0 0 81 1 1 2 0 0 82 1 1 1 0 0 90 0 1 1 0 0 91 0 1 3 0 0 92 0 1 3 0 0 93 0 1 3 0 0 100 0 0 1 0 1 101 0 1 1 0 1 102 0 1 2 0 1 103 0 1 1 0 1 104 2 1 4 0 1 105 1 1 5 0 0 106 0 1 3 0 1 110 1 1 0 1 2 111 1 1 1 0 1 112 2 1 0 0 1 113 2 1 1 0 1 114 1 1 2 0 0 115 1 1 3 0 1 116 1 1 3 0 1" 18 note seed/ng/hostwords.tsv, byte for byte (the gate compares ngcheck --table with the file), then the rows of 19 note seed/ng/hostwords-ng.tsv: ng's own words, which omc does not have (IR.md s7.11). --table prints the first only: 20 note c_hxn is the length of the second, 52 bytes 21 text c_hwt "id\tword\targs\tclass\n53\tread\tiw\tio\n54\twrite\tir\tio\n100\tfclose\ti\tfs\n101\tfsync\ti\tfs\n102\tfchmod\tii\tfs\n103\tfseek\tili\tfs\n104\tsocknew\tiii\tnet\n105\tlisten\tii\tnet\n106\taccept\tii\tnet\n107\tfork\t-\tproc\n108\tdupfd\tiii\tproc\n109\tmonons\t-\ttime\n110\tfopen\trii\tfs\n111\tunlink\tr\tfs\n112\tmakedir\tri\tfs\n113\tgetdnts\tiw\tfs\n114\tconnect\tir\tnet\n115\tbind\tir\tnet\n116\twaitpid\tiwi\tproc\n117\tfstat\tiw\tfs\n118\trecv\tiwi\tio\n119\tsend\tiri\tio\n120\tsleepns\tl\ttime\n121\targcnt\t-\tenv\n122\targread\tLw\tenv\n123\twaitio\tiil\tio\n124\texecprog\tr\tproc\n125\trenames\tri\tfs\n126\trmdir\tr\tfs\n127\tkillpid\tii\tproc\n128\tpipefds\twi\tproc\n129\tgetpid\t-\tproc\n130\trealns\t-\ttime\n131\tsockname\tiw\tnet\n132\tcwd\tw\tfs\n133\treadlnk\trw\tfs\n134\tsockopt\tiiir\tnet\n135\trandom\twi\tenv\n136\tenvcnt\t-\tenv\n137\tenvread\tLw\tenv\n138\tchdir\tr\tfs\n139\tftrunc\til\tfs\n140\tstat\trw\tfs\n141\tlink\tr\tfs\n142\tsymlnk\tr\tfs\n143\tchmod\tri\tfs\n144\tfaccess\tri\tfs\n145\tgetuid\t-\tproc\n146\tgeteuid\t-\tproc\n147\tgetgid\t-\tproc\n148\tgetegid\t-\tproc\n149\tlstat\trw\tfs\n150\ttruncate\trl\tfs\n151\tchown\trii\tfs\n153\tfchdir\ti\tfs\n154\tgetppid\t-\tproc\n155\tumask\ti\tfs\n156\tfdsync\ti\tfs\n157\tmemfd\tri\tfs\n158\tsetsid\t-\tproc\n159\tgetpgid\ti\tproc\n160\tsetpgid\tii\tproc\n161\tpread\tiwl\tio\n162\tpwrite\tirl\tio\n163\tgetsid\ti\tproc\n164\tsyncfs\ti\tfs\n165\tshutdown\tii\tnet\n166\tdevctl\tiuw\tdev\n167\tmapnew\tiLLii\tdev\n168\tmapdrop\tl\tdev\n169\tmapread\tlLw\tdev\n170\tmapwrite\tlLr\tdev\n171\tdevcall\tiuww\tdev\n172\tuvmctl\tiuw\tdev\n173\tmapaddr\tl\tdev\n174\tmapget\tlLi\tdev\n175\tmapset\tlLiL\tdev\n176\tmaphold\tLL\tdev\n177\tmapbind\tliLi\tdev\n197\tflock\tii\tfs\n198\texecpure\tr\tproc\n199\tcpufence\t-\tcpu\n200\tcpurelax\t-\tcpu\n220\tpeercred\tiw\tnet\n221\tpollfds\twl\tio\n222\tsendmsg\tiri\tnet\n224\tpeername\tiw\tnet\n228\tvfioctl\tiuS\tdev\n229\tvfiomap\tir\tdev\n230\tvfiomapw\tir\tdev\n231\teventfd\tu\tdev\n232\tvfioirq\tiuw\tdev\n233\texecenv\trr\tproc\n235\tprlimit\tiiw\tlimit\n236\tcpuset\tir\tsched\n237\tcpuget\tiw\tsched\n238\tcpunow\t-\tsched\n239\tsetprio\tiii\tsched\n240\tgetprio\tii\tsched\n241\tlibfn\ti\tlib\n242\tlibptr\tw\tlib\n243\tlibcall\tLw\tlib\n" 22 global c_s ulong 4 23 global c_n ulong 16 24 global c_f ulong 16 25 global c_q ulong 16 26 global c_ob uchar 32 27 global c_ab uchar 256 28 global c_rok uchar 256 29 global c_rtk uchar 256 30 global c_rim uchar 256 31 global c_rfx uchar 256 32 global c_rva uchar 256 33 global c_rty uchar 256 34 global c_hok uchar 256 35 global c_hcp uchar 256 36 global c_has uint 256 37 global c_hal uint 256 38 global c_tk uchar 65568 39 global c_t1 uint 65568 40 global c_t2 uint 65568 41 global c_t3 uint 65568 42 global c_t4 uint 65568 43 global c_t5 uint 65568 44 global c_tsz ulong 65568 45 global c_xty uint 65536 46 global c_xof uint 65536 47 global c_xor uchar 65536 48 global c_th uint 131072 49 global c_gty uint 65536 50 global c_gcl uchar 65536 51 global c_fk uchar 65536 52 global c_ffl uchar 65536 53 global c_fnp uint 65536 54 global c_fp0 uint 65536 55 global c_frs uint 65536 56 global c_fsg uchar 65536 57 global c_fb0 uint 65536 58 global c_fnb uint 65536 59 global c_fof uint 65536 60 global c_fpt uint `4194304` 61 global c_bnp uint `1048576` 62 global c_bp0 uint `1048576` 63 global c_bo0 uint `1048576` 64 global c_bno uint `1048576` 65 global c_bof uint `1048576` 66 global c_bpt uint `4194304` 67 global c_oop uchar `4194304` 68 global c_oty uint `4194304` 69 global c_oim ulong `4194304` 70 global c_ona uint `4194304` 71 global c_oa0 uint `4194304` 72 global c_oof uint `4194304` 73 global c_ov uint `4194304` 74 global c_opb uint `4194304` 75 global c_opp uint `4194304` 76 global c_cvn uint `4194304` 77 global c_arg uint `4194304` 78 global c_vty uint `2097152` 79 global c_vb uint `2097152` 80 global c_vp uint `2097152` 81 global c_vo uint `2097152` 82 global c_cvh uint `2097152` 83 global c_s1 uint 65536 84 global c_s2 uint 65536 85 global c_bv0 uint 65536 86 global c_vis uchar 65536 87 global c_stk uint 65536 88 global c_sti uchar 65536 89 global c_rpo uint 65536 90 global c_ord uint 65536 91 global c_pc uint 65537 92 global c_pst uint 65537 93 global c_pfl uint 65537 94 global c_pl uint 131072 95 global c_idm uint 65536 96 global c_dch uint 65536 97 global c_dsb uint 65536 98 global c_dnx uint 65536 99 global c_pre uint 65536 100 global c_pos uint 65536 101 note ---- output ---------------------------------------------------------------------------------- 102 fn ck_txt k ulong fd int to void 103 s = ulong 0 104 c = ulong 1 105 for i ulong len c_tx 106 if eq get c_tx i 10 107 if eq c k 108 r = write fd c_tx s sub i s 109 ret 110 end 111 c = add c 1 112 s = add i 1 113 end 114 end 115 end 116 fn ck_cname k ulong to void 117 s = ulong 0 118 c = ulong 1 119 for i ulong len c_cls 120 if eq get c_cls i 10 121 if eq c k 122 r = write 2 c_cls s sub i s 123 ret 124 end 125 c = add c 1 126 s = add i 1 127 end 128 end 129 end 130 fn ck_num v ulong fd int to void 131 x = v 132 i = ulong 32 133 for j ulong 21 134 i = sub i 1 135 put c_ob i uchar add 48 rem x 10 136 x = div x 10 137 if eq x 0 138 r = write fd c_ob i sub 32 i 139 ret 140 end 141 end 142 end 143 fn ck_nl fd int to void 144 put c_ob 0 10 145 r = write fd c_ob 0 1 146 end 147 fn ck_bad c ulong off ulong to void 148 ck_txt 1 2 149 ck_cname sub c 9 150 ck_txt 2 2 151 ck_num off 2 152 ck_nl 2 153 exit int c 154 end 155 note refuse with class c at the offset of the op being checked (c_q 12) 156 fn ck_fail c ulong to void 157 ck_bad c ulong get c_oof get c_q 12 158 end 159 fn ck_want b bool c ulong to void 160 if not b 161 ck_fail c 162 end 163 end 164 note ---- reading primitives (cursor c_s 0, end c_s 1) --------------------------------------------- 165 fn ck_at to ulong 166 ret get c_s 0 167 end 168 fn ck_need k ulong to ulong 169 p = get c_s 0 170 if gt add p k get c_s 1 171 ck_bad 12 p 172 end 173 put c_s 0 add p k 174 ret p 175 end 176 fn ck_u8 to ulong 177 p = ck_need 1 178 ret ulong get sh_dat p 179 end 180 fn ck_u16 to ulong 181 p = ck_need 2 182 v = ulong get sh_dat p 183 ret or v shl ulong get sh_dat add p 1 8 184 end 185 fn ck_un k ulong to ulong 186 p = ck_need k 187 v = ulong 0 188 for j ulong k bound 8 189 x = ulong get sh_dat add p j 190 v = or v shl x mul j 8 191 end 192 ret v 193 end 194 fn ck_u32 to ulong 195 ret ck_un 4 196 end 197 fn ck_u64 to ulong 198 ret ck_un 8 199 end 200 note ---- init: op rows and host words ---------------------------------------------------------- 201 fn ck_rows to void 202 p = ulong 0 203 for r ulong 256 204 if ge p len c_rows 205 ret 206 end 207 op = ck_dec p 208 p = get c_q 15 209 put c_rok op 1 210 put c_rtk op uchar ck_dec p 211 p = get c_q 15 212 put c_rim op uchar ck_dec p 213 p = get c_q 15 214 put c_rfx op uchar ck_dec p 215 p = get c_q 15 216 put c_rva op uchar ck_dec p 217 p = get c_q 15 218 put c_rty op uchar ck_dec p 219 p = get c_q 15 220 end 221 end 222 note decimal number in c_rows at p (skipping separators); the next position goes to c_q 15 223 fn ck_dec p ulong to ulong 224 i = p 225 while lt get c_rows i 48 bound 8 226 i = add i 1 227 end 228 v = ulong 0 229 while lt i len c_rows bound 12 230 c = get c_rows i 231 if or lt c 48 gt c 57 232 break 233 end 234 v = add mul v 10 ulong sub c 48 235 i = add i 1 236 end 237 put c_q 15 i 238 ret v 239 end 240 note host words: skip the header line, then "id\tword\targs\tclass\n" rows 241 fn ck_hosts to void 242 p = ck_hnext 0 243 while lt p len c_hwt bound 256 244 p = ck_hrow p 245 end 246 end 247 fn ck_hnext p ulong to ulong 248 i = p 249 while lt i len c_hwt bound 4096 250 if eq get c_hwt i 10 251 ret add i 1 252 end 253 i = add i 1 254 end 255 ret i 256 end 257 fn ck_hfld p ulong to ulong 258 i = p 259 while lt i len c_hwt bound 4096 260 if eq get c_hwt i 9 261 ret i 262 end 263 i = add i 1 264 end 265 ret i 266 end 267 fn ck_hrow p ulong to ulong 268 v = ulong 0 269 i = p 270 while ne get c_hwt i 9 bound 4 271 v = add mul v 10 ulong sub get c_hwt i 48 272 i = add i 1 273 end 274 i = ck_hfld add i 1 275 a = add i 1 276 e = ck_hfld a 277 put c_hok v 1 278 put c_has v uint a 279 if ne get c_hwt a 45 280 put c_hal v uint sub e a 281 end 282 if and eq get c_hwt add e 1 99 eq get c_hwt add e 2 112 283 put c_hcp v 1 284 end 285 ret ck_hnext e 286 end 287 note ---- header ------------------------------------------------------------------------------------ 288 fn ck_head to void 289 n = get c_s 1 290 for j ulong 7 291 if ge j n 292 ck_bad 12 0 293 end 294 if lt j 6 295 if ne get sh_dat j get c_tx add 96 j 296 ck_bad 10 0 297 end 298 else 299 if ne get sh_dat j 0 300 ck_bad 10 0 301 end 302 end 303 end 304 put c_s 0 7 305 if ne ck_u8 9 306 ck_bad 11 7 307 end 308 p = ck_need 16 309 for j ulong 16 310 c = get sh_dat add 8 j 311 if lt j 14 312 if ne c get c_tx add 103 j 313 ck_bad 11 8 314 end 315 else 316 if ne c 0 317 ck_bad 11 8 318 end 319 end 320 end 321 end 322 note ---- type predicates (ids are validated before these are used) ----------------------------- 323 fn ck_sb t ulong to ulong 324 if or eq t 1 eq t 2 325 ret 1 326 end 327 if or eq t 6 or eq t 18 eq t 19 328 ret 1 329 end 330 if or eq t 3 or eq t 7 or eq t 16 eq t 17 331 ret 2 332 end 333 if or eq t 4 or eq t 8 eq t 13 334 ret 4 335 end 336 if or eq t 5 or eq t 9 eq t 14 337 ret 8 338 end 339 ret 0 340 end 341 fn ck_kd t ulong to ulong 342 if lt t 32 343 ret 0 344 end 345 if ge t add 32 get c_n 0 346 ret 255 347 end 348 ret ulong get c_tk t 349 end 350 fn ck_g1 t ulong to ulong 351 if lt t 32 352 ret 0 353 end 354 ret ulong get c_t1 t 355 end 356 fn ck_g2 t ulong to ulong 357 if lt t 32 358 ret 0 359 end 360 ret ulong get c_t2 t 361 end 362 fn ck_g3 t ulong to ulong 363 if lt t 32 364 ret 0 365 end 366 ret ulong get c_t3 t 367 end 368 fn ck_g4 t ulong to ulong 369 if lt t 32 370 ret 0 371 end 372 ret ulong get c_t4 t 373 end 374 fn ck_g5 t ulong to ulong 375 if lt t 32 376 ret 0 377 end 378 ret ulong get c_t5 t 379 end 380 fn ck_isint t ulong to bool 381 ret and ge t 2 le t 9 382 end 383 fn ck_issgn t ulong to bool 384 ret and ge t 6 le t 9 385 end 386 fn ck_isuns t ulong to bool 387 ret and ge t 2 le t 5 388 end 389 fn ck_isflt t ulong to bool 390 ret or or eq t 13 eq t 14 or eq t 16 eq t 17 391 end 392 fn ck_isar t ulong to bool 393 ret or ck_isint t ck_isflt t 394 end 395 fn ck_isnum t ulong to bool 396 ret or ck_isar t or eq t 18 eq t 19 397 end 398 note the lane element of a scalar or VEC type 399 fn ck_el t ulong to ulong 400 if eq ck_kd t 1 401 ret ck_g1 t 402 end 403 ret t 404 end 405 fn ck_lanes t ulong to ulong 406 if eq ck_kd t 1 407 ret ck_g2 t 408 end 409 ret 1 410 end 411 note byte size of a memory element type (scalar, VEC, ARRAY, STRUCT) 412 fn ck_size t ulong to ulong 413 if lt t 32 414 ret ck_sb t 415 end 416 ret get c_tsz t 417 end 418 note the element type of a REF to an ARRAY or of a SLICE, else 0 419 fn ck_relt r ulong to ulong 420 k = ck_kd r 421 if eq k 5 422 ret ck_g1 r 423 end 424 if eq k 4 425 a = ck_g1 r 426 if eq ck_kd a 2 427 ret ck_g1 a 428 end 429 end 430 ret 0 431 end 432 note a type id usable as a value type: scalar, VEC, REF, SLICE, FRAG (never tok, void, ARRAY, STRUCT) 433 note returns 0 when it is, else the class (24 an absent table id, 16 otherwise) 434 fn ck_vtc t ulong to ulong 435 if lt t 32 436 if eq ck_sb t 0 437 ret 16 438 end 439 ret 0 440 end 441 k = ck_kd t 442 if eq k 255 443 ret 24 444 end 445 if or eq k 2 eq k 3 446 ret 16 447 end 448 ret 0 449 end 450 note ---- type table (phase 1); every fault is reported at the entry's offset --------------------- 451 fn ck_types to void 452 o = ck_at 453 n = ck_u32 454 if gt n 65536 455 ck_bad 23 o 456 end 457 for k ulong n bound 65536 458 ck_type add k 32 459 end 460 end 461 fn ck_type t ulong to void 462 o = ck_at 463 kd = ck_u8 464 put c_tk t uchar kd 465 if or eq kd 0 gt kd 6 466 ck_bad 13 o 467 end 468 if eq kd 1 469 ck_tvec t o 470 end 471 if eq kd 2 472 ck_tarr t o 473 end 474 if eq kd 3 475 ck_tstr t o 476 end 477 if or eq kd 4 eq kd 5 478 ck_tref t o kd 479 end 480 if eq kd 6 481 ck_tfrg t o 482 end 483 put c_n 0 sub t 31 484 ck_tdup t o 485 end 486 note a type id referenced from entry t: a scalar id or an earlier entry 487 fn ck_tid x ulong t ulong o ulong to void 488 if ge x 32 489 if ge x t 490 ck_bad 24 o 491 end 492 ret 493 end 494 if eq ck_sb x 0 495 ck_bad 16 o 496 end 497 end 498 fn ck_tvec t ulong o ulong to void 499 e = ck_u32 500 l = ck_u32 501 ck_tid e t o 502 if not or eq e 1 or ck_isint e ck_isflt e 503 ck_bad 16 o 504 end 505 if or or lt l 2 gt l 64 ne and l sub l 1 0 506 ck_bad 16 o 507 end 508 if gt mul l ck_sb e 64 509 ck_bad 16 o 510 end 511 put c_t1 t uint e 512 put c_t2 t uint l 513 put c_tsz t mul l ck_sb e 514 end 515 fn ck_tarr t ulong o ulong to void 516 e = ck_u32 517 c = ck_u32 518 ck_tid e t o 519 k = ck_kd e 520 if not or ck_isnum e or eq k 1 eq k 3 521 ck_bad 16 o 522 end 523 if or eq c 0 gt c `16777216` 524 ck_bad 16 o 525 end 526 put c_t1 t uint e 527 put c_t2 t uint c 528 put c_tsz t mul c ck_size e 529 end 530 fn ck_tstr t ulong o ulong to void 531 sz = ck_u32 532 no = ck_at 533 nf = ck_u32 534 if or eq sz 0 gt sz `1073741824` 535 ck_bad 16 o 536 end 537 if eq nf 0 538 ck_bad 16 o 539 end 540 if gt nf 64 541 ck_bad 23 no 542 end 543 f0 = get c_n 1 544 if gt add f0 nf 65536 545 ck_bad 23 no 546 end 547 put c_t1 t uint sz 548 put c_t2 t uint nf 549 put c_t3 t uint f0 550 put c_tsz t sz 551 put c_q 14 0 552 for j ulong nf bound 64 553 ck_tfld t o add f0 j 554 end 555 put c_n 1 add f0 nf 556 if gt get c_q 14 sz 557 ck_bad 16 o 558 end 559 end 560 note field x of struct t; c_q 14 is the end of the previous field 561 fn ck_tfld t ulong o ulong x ulong to void 562 ft = ck_u32 563 of = ck_u32 564 od = ck_u8 565 ck_tid ft t o 566 k = ck_kd ft 567 if not or ck_isnum ft or eq k 2 eq k 3 568 ck_bad 16 o 569 end 570 if gt od 1 571 ck_bad 13 o 572 end 573 if and eq od 1 ge ft 32 574 ck_bad 13 o 575 end 576 if lt of get c_q 14 577 ck_bad 16 o 578 end 579 put c_q 14 add of ck_size ft 580 put c_xty x uint ft 581 put c_xof x uint of 582 put c_xor x uchar od 583 end 584 fn ck_tref t ulong o ulong kd ulong to void 585 x = ck_u32 586 ac = ck_u8 587 sp = ck_u8 588 ck_tid x t o 589 k = ck_kd x 590 if eq kd 4 591 if not or eq k 2 eq k 3 592 ck_bad 16 o 593 end 594 else 595 if not or ck_isnum x or eq k 1 eq k 3 596 ck_bad 16 o 597 end 598 end 599 if or gt ac 1 gt sp 4 600 ck_bad 13 o 601 end 602 if and eq sp 3 eq ac 1 603 ck_bad 16 o 604 end 605 put c_t1 t uint x 606 put c_t2 t uint ac 607 put c_t3 t uint sp 608 end 609 fn ck_tfrg t ulong o ulong to void 610 ro = ck_u8 611 m = ck_u16 612 n = ck_u16 613 k = ck_u16 614 e = ck_u32 615 if gt ro 2 616 ck_bad 13 o 617 end 618 if or or eq m 0 gt m 256 or eq n 0 gt n 256 619 ck_bad 16 o 620 end 621 if or eq k 0 gt k 256 622 ck_bad 16 o 623 end 624 ck_tid e t o 625 if not ck_isnum e 626 ck_bad 16 o 627 end 628 put c_t1 t uint ro 629 put c_t2 t uint m 630 put c_t3 t uint n 631 put c_t4 t uint k 632 put c_t5 t uint e 633 end 634 note duplicate entries (NONCANONICAL): open hash over the entry's contents 635 fn ck_thash t ulong to ulong 636 h = ulong get c_tk t 637 h = add mul h `1000003` ulong get c_t1 t 638 h = add mul h `1000003` ulong get c_t2 t 639 if eq get c_tk t 3 640 f0 = ulong get c_t3 t 641 for j ulong ulong get c_t2 t bound 64 642 x = add f0 j 643 h = add mul h `1000003` ulong get c_xty x 644 h = add mul h `1000003` ulong get c_xof x 645 h = add mul h `1000003` ulong get c_xor x 646 end 647 ret h 648 end 649 h = add mul h `1000003` ulong get c_t3 t 650 h = add mul h `1000003` ulong get c_t4 t 651 ret add mul h `1000003` ulong get c_t5 t 652 end 653 fn ck_teq a ulong b ulong to bool 654 if ne get c_tk a get c_tk b 655 ret false 656 end 657 if ne get c_t1 a get c_t1 b 658 ret false 659 end 660 if ne get c_t2 a get c_t2 b 661 ret false 662 end 663 if eq get c_tk a 3 664 ret ck_feq ulong get c_t3 a ulong get c_t3 b ulong get c_t2 a 665 end 666 if ne get c_t3 a get c_t3 b 667 ret false 668 end 669 if ne get c_t4 a get c_t4 b 670 ret false 671 end 672 ret eq get c_t5 a get c_t5 b 673 end 674 fn ck_feq a ulong b ulong n ulong to bool 675 for j ulong n bound 64 676 x = add a j 677 y = add b j 678 if ne get c_xty x get c_xty y 679 ret false 680 end 681 if ne get c_xof x get c_xof y 682 ret false 683 end 684 if ne get c_xor x get c_xor y 685 ret false 686 end 687 end 688 ret true 689 end 690 fn ck_tdup t ulong o ulong to void 691 s = and ck_thash t 131071 692 for i ulong 131072 693 u = ulong get c_th s 694 if eq u 0 695 put c_th s uint t 696 ret 697 end 698 if ck_teq u t 699 ck_bad 13 o 700 end 701 s = and add s 1 131071 702 end 703 end 704 note ---- globals (phase 1) --------------------------------------------------------------------- 705 fn ck_globs to void 706 o = ck_at 707 n = ck_u32 708 if gt n 65536 709 ck_bad 23 o 710 end 711 put c_n 2 n 712 for g ulong n bound 65536 713 ck_glob g 714 end 715 end 716 fn ck_glob g ulong to void 717 o = ck_at 718 t = ck_u32 719 c = ck_u8 720 k = ck_kd t 721 if eq k 255 722 ck_bad 24 o 723 end 724 if gt c 2 725 ck_bad 13 o 726 end 727 if eq c 2 728 if not or and ge t 2 le t 9 or eq t 13 eq t 14 729 ck_bad 16 o 730 end 731 else 732 if ne k 2 733 ck_bad 16 o 734 end 735 end 736 put c_gty g uint t 737 put c_gcl g uchar c 738 if eq c 1 739 p = ck_need get c_tsz t 740 end 741 end 742 note ---- functions (phase 1): headers, blocks, op rows -------------------------------------------- 743 fn ck_funcs to void 744 o = ck_at 745 n = ck_u32 746 if gt n 65536 747 ck_bad 23 o 748 end 749 put c_n 3 n 750 for f ulong n bound 65536 751 ck_fread f 752 end 753 p = ck_at 754 if lt p get c_s 1 755 ck_bad 14 p 756 end 757 ck_entry o 758 ck_back 759 end 760 note at most one callback function (flags bit 1); a second one is FIELD at its record 761 fn ck_back to void 762 c = ulong 0 763 for f ulong get c_n 3 bound 65536 764 if ge ulong get c_ffl f 2 765 c = add c 1 766 if eq c 2 767 ck_bad 13 ulong get c_fof f 768 end 769 end 770 end 771 end 772 note D11, IR.md s6.1: exactly one program entry, an export with no parameters and result i32; 773 note none is ENTRY at the function count, a second one is ENTRY at its record 774 fn ck_entry o ulong to void 775 c = ulong 0 776 for f ulong get c_n 3 bound 65536 777 if and eq get c_fk f 2 eq get c_fnp f 0 778 if eq get c_frs f 8 779 c = add c 1 780 if eq c 2 781 ck_bad 30 ulong get c_fof f 782 end 783 end 784 end 785 end 786 if eq c 0 787 ck_bad 30 o 788 end 789 end 790 note a parameter count (function or block): LIMIT above 64 at its own offset 791 fn ck_pcount to ulong 792 o = ck_at 793 n = ck_u32 794 if gt n 64 795 ck_bad 23 o 796 end 797 ret n 798 end 799 fn ck_fread f ulong to void 800 o = ck_at 801 put c_fof f uint o 802 k = ck_u8 803 fl = ck_u8 804 if or gt k 2 gt fl 3 805 ck_bad 13 o 806 end 807 put c_fk f uchar k 808 put c_ffl f uchar fl 809 np = ck_pcount 810 put c_fnp f uint np 811 put c_fp0 f uint get c_n 8 812 for j ulong np bound 64 813 ck_fparam f o 814 end 815 r = ck_u32 816 if ne r 0 817 ck_ptype r f o 818 if eq k 1 819 ck_bad 22 o 820 end 821 end 822 put c_frs f uint r 823 note flags bit 1 (IR.md s6.1): the callback function, kind 0 with six u64 parameters and a u64 result 824 if ge fl 2 825 if or or ne k 0 ne np 6 ne r 5 826 ck_bad 13 o 827 end 828 for j ulong 6 829 if ne ulong get c_fpt add ulong get c_fp0 f j 5 830 ck_bad 13 o 831 end 832 end 833 end 834 if eq k 1 835 ck_kern f o 836 end 837 ck_blocks f 838 end 839 note a parameter or result type of function f: a value type, FRAG only in kernels 840 fn ck_ptype t ulong f ulong o ulong to void 841 c = ck_vtc t 842 if ne c 0 843 ck_bad c o 844 end 845 if and eq ck_kd t 6 ne get c_fk f 1 846 ck_bad 22 o 847 end 848 end 849 fn ck_fparam f ulong o ulong to void 850 t = ck_u32 851 ck_ptype t f o 852 x = get c_n 8 853 put c_fpt x uint t 854 put c_n 8 add x 1 855 end 856 fn ck_kern f ulong o ulong to void 857 x = ck_u32 858 y = ck_u32 859 z = ck_u32 860 s = ck_u8 861 if or or eq x 0 eq y 0 eq z 0 862 ck_bad 13 o 863 end 864 if or or gt x 4096 gt y 4096 gt z 4096 865 ck_bad 13 o 866 end 867 if gt mul mul x y z 4096 868 ck_bad 13 o 869 end 870 if not or eq s 0 and and ge s 4 le s 128 eq and s sub s 1 0 871 ck_bad 13 o 872 end 873 put c_fsg f uchar s 874 end 875 fn ck_blocks f ulong to void 876 o = ck_at 877 nb = ck_u32 878 if eq nb 0 879 ck_bad 13 o 880 end 881 if gt nb 65536 882 ck_bad 23 o 883 end 884 if gt add get c_n 4 nb `1048576` 885 ck_bad 23 o 886 end 887 put c_fb0 f uint get c_n 4 888 put c_fnb f uint nb 889 put c_q 9 0 890 for j ulong nb bound 65536 891 ck_bread f j 892 end 893 end 894 fn ck_bread f ulong j ulong to void 895 b = get c_n 4 896 put c_n 4 add b 1 897 o = ck_at 898 put c_bof b uint o 899 np = ck_pcount 900 put c_bnp b uint np 901 put c_bp0 b uint get c_n 7 902 if and eq j 0 gt np 0 903 ck_bad 19 o 904 end 905 if and ne j 0 eq np 0 906 ck_bad 19 o 907 end 908 for k ulong np bound 64 909 ck_bparam f k o 910 end 911 ck_bops b 912 end 913 fn ck_bparam f ulong k ulong o ulong to void 914 t = ck_u32 915 if eq k 0 916 if ne t 20 917 ck_bad 19 o 918 end 919 else 920 ck_ptype t f o 921 end 922 x = get c_n 7 923 put c_bpt x uint t 924 put c_n 7 add x 1 925 end 926 fn ck_bops b ulong to void 927 on = ck_at 928 n = ck_u32 929 if eq n 0 930 ck_bad 20 ulong get c_bof b 931 end 932 if gt add get c_q 9 n `1048576` 933 ck_bad 23 on 934 end 935 if gt add get c_n 5 n `4194304` 936 ck_bad 23 on 937 end 938 put c_q 9 add get c_q 9 n 939 put c_bo0 b uint get c_n 5 940 put c_bno b uint n 941 for k ulong n bound `1048576` 942 ck_oread 943 end 944 end 945 fn ck_oread to void 946 o = ck_at 947 op = ck_u8 948 x = get c_n 5 949 put c_n 5 add x 1 950 put c_oof x uint o 951 put c_oop x uchar op 952 if eq get c_rok op 0 953 ck_bad 15 o 954 end 955 put c_oty x uint ck_u32 956 if ne get c_rim op 0 957 put c_oim x ck_u64 958 end 959 n = ulong 0 960 if ne get c_rva op 0 961 no = ck_at 962 n = ck_u32 963 if gt n 64 964 ck_bad 23 no 965 end 966 end 967 m = add ck_ntok op add ulong get c_rfx op n 968 put c_ona x uint m 969 a0 = get c_n 6 970 put c_oa0 x uint a0 971 for k ulong m bound 128 972 put c_arg add a0 k uint ck_u32 973 end 974 put c_n 6 add a0 m 975 end 976 note 1 when op carries a token operand at slot 0 (E, R and T ops other than br) 977 fn ck_ntok op ulong to ulong 978 if or eq get c_rtk op 0 eq op 60 979 ret 0 980 end 981 ret 1 982 end 983 note ---- op field accessors ---------------------------------------------------------------------- 984 fn ck_op o ulong to ulong 985 ret ulong get c_oop o 986 end 987 fn ck_ty o ulong to ulong 988 ret ulong get c_oty o 989 end 990 fn ck_im o ulong to ulong 991 ret get c_oim o 992 end 993 fn ck_na o ulong to ulong 994 ret ulong get c_ona o 995 end 996 fn ck_a o ulong k ulong to ulong 997 s = add ulong get c_oa0 o k 998 ret ulong get c_arg s 999 end 1000 note the type of value operand k of op o 1001 fn ck_ta o ulong k ulong to ulong 1002 v = ck_a o k 1003 ret ulong get c_vty v 1004 end 1005 fn ck_isterm o ulong to bool 1006 op = ck_op o 1007 ret or and ge op 60 le op 63 or eq op 65 eq op 66 1008 end 1009 note ---- phase 2: one function --------------------------------------------------------------------- 1010 fn ck_fn f ulong to void 1011 put c_f 0 f 1012 put c_f 1 ulong get c_fb0 f 1013 put c_f 2 ulong get c_fnb f 1014 put c_f 5 ulong get c_fk f 1015 put c_f 6 ulong get c_frs f 1016 put c_f 7 ulong get c_fsg f 1017 ck_term 1018 ck_cfg 1019 ck_reach 1020 ck_doms 1021 ck_dtree 1022 ck_vnum f 1023 ck_covidx 1024 ck_walk 1025 end 1026 note every block ends with its one terminator (UNTERMINATED) 1027 fn ck_term to void 1028 for j ulong get c_f 2 bound 65536 1029 b = add get c_f 1 j 1030 o0 = ulong get c_bo0 b 1031 n = ulong get c_bno b 1032 for k ulong sub n 1 bound `1048576` 1033 if ck_isterm add o0 k 1034 ck_bad 20 ulong get c_oof add o0 k 1035 end 1036 end 1037 x = add o0 sub n 1 1038 if not ck_isterm x 1039 ck_bad 20 ulong get c_oof x 1040 end 1041 end 1042 end 1043 fn ck_last j ulong to ulong 1044 b = add get c_f 1 j 1045 ret sub add ulong get c_bo0 b ulong get c_bno b 1 1046 end 1047 note successors from each block's terminator: branch targets exist, are not block 0, arity (s7.6) 1048 fn ck_cfg to void 1049 for j ulong get c_f 2 bound 65536 1050 put c_s1 j 0 1051 put c_s2 j 0 1052 o = ck_last j 1053 op = ck_op o 1054 put c_q 12 o 1055 if eq op 60 1056 put c_s1 j uint ck_tgt o 0 1057 end 1058 if eq op 61 1059 put c_s1 j uint ck_tgt o 2 1060 put c_s2 j uint ck_tgt o 3 1061 end 1062 end 1063 end 1064 note block operand k of op o (a br or cbr): 1 + its local index 1065 fn ck_tgt o ulong k ulong to ulong 1066 t = ck_a o k 1067 if or eq t 0 ge t get c_f 2 1068 ck_fail 24 1069 end 1070 b = add get c_f 1 t 1071 np = ulong get c_bnp b 1072 if eq ck_op o 61 1073 ck_want eq np 1 19 1074 else 1075 ck_want eq np sub ck_na o 1 19 1076 end 1077 ret add t 1 1078 end 1079 note depth-first search from block 0: postorder into c_rpo, then reverse; UNREACHABLE 1080 fn ck_reach to void 1081 nb = get c_f 2 1082 for j ulong nb bound 65536 1083 put c_vis j 0 1084 end 1085 put c_vis 0 1 1086 put c_stk 0 0 1087 put c_sti 0 0 1088 sp = ulong 1 1089 pc = ulong 0 1090 while gt sp 0 bound 262144 1091 top = ulong get c_stk sub sp 1 1092 i = ulong get c_sti sub sp 1 1093 if lt i 2 1094 put c_sti sub sp 1 uchar add i 1 1095 s = ck_succ top i 1096 if ne s 0 1097 if eq get c_vis sub s 1 0 1098 put c_vis sub s 1 1 1099 put c_stk sp uint sub s 1 1100 put c_sti sp 0 1101 sp = add sp 1 1102 end 1103 end 1104 else 1105 put c_pfl pc uint top 1106 pc = add pc 1 1107 sp = sub sp 1 1108 end 1109 end 1110 for j ulong nb bound 65536 1111 if eq get c_vis j 0 1112 ck_bad 26 ulong get c_bof add get c_f 1 j 1113 end 1114 end 1115 for i ulong nb bound 65536 1116 x = ulong get c_pfl sub sub nb 1 i 1117 put c_rpo i uint x 1118 put c_ord x uint i 1119 end 1120 end 1121 fn ck_succ j ulong i ulong to ulong 1122 if eq i 0 1123 ret ulong get c_s1 j 1124 end 1125 ret ulong get c_s2 j 1126 end 1127 note immediate dominators (Cooper, Harvey, Kennedy) over predecessor lists 1128 fn ck_doms to void 1129 nb = get c_f 2 1130 for j ulong add nb 1 bound 65537 1131 put c_pc j 0 1132 end 1133 for j ulong nb bound 65536 1134 ck_pcnt ulong get c_s1 j 1135 ck_pcnt ulong get c_s2 j 1136 end 1137 s = ulong 0 1138 for j ulong nb bound 65536 1139 put c_pst j uint s 1140 put c_pfl j uint s 1141 s = add s ulong get c_pc j 1142 end 1143 for j ulong nb bound 65536 1144 ck_padd j ulong get c_s1 j 1145 ck_padd j ulong get c_s2 j 1146 put c_idm j `4294967295` 1147 end 1148 put c_idm 0 0 1149 ch = true 1150 while ch bound 65537 1151 ch = false 1152 for i ulong sub nb 1 bound 65536 1153 b = ulong get c_rpo add i 1 1154 ni = ck_newidom b 1155 if ne ni ulong get c_idm b 1156 put c_idm b uint ni 1157 ch = true 1158 end 1159 end 1160 end 1161 end 1162 fn ck_pcnt s ulong to void 1163 if ne s 0 1164 put c_pc sub s 1 add get c_pc sub s 1 1 1165 end 1166 end 1167 fn ck_padd j ulong s ulong to void 1168 if ne s 0 1169 x = ulong get c_pfl sub s 1 1170 put c_pl x uint j 1171 put c_pfl sub s 1 uint add x 1 1172 end 1173 end 1174 fn ck_newidom b ulong to ulong 1175 ni = ulong `4294967295` 1176 s = ulong get c_pst b 1177 for k ulong ulong get c_pc b bound 131072 1178 p = ulong get c_pl add s k 1179 if ne get c_idm p `4294967295` 1180 if eq ni `4294967295` 1181 ni = p 1182 else 1183 ni = ck_isect p ni 1184 end 1185 end 1186 end 1187 ret ni 1188 end 1189 fn ck_isect a ulong b ulong to ulong 1190 x = a 1191 y = b 1192 while ne x y bound 65537 1193 while gt get c_ord x get c_ord y bound 65537 1194 x = ulong get c_idm x 1195 end 1196 while gt get c_ord y get c_ord x bound 65537 1197 y = ulong get c_idm y 1198 end 1199 end 1200 ret x 1201 end 1202 note dominator tree: preorder and postorder numbers make dominance an O(1) query 1203 fn ck_dtree to void 1204 nb = get c_f 2 1205 for j ulong nb bound 65536 1206 put c_dch j 0 1207 put c_dsb j 0 1208 end 1209 for i ulong sub nb 1 bound 65536 1210 b = sub sub nb 1 i 1211 p = ulong get c_idm b 1212 put c_dsb b get c_dch p 1213 put c_dch p uint add b 1 1214 end 1215 put c_stk 0 0 1216 put c_dnx 0 get c_dch 0 1217 put c_pre 0 0 1218 sp = ulong 1 1219 pr = ulong 1 1220 po = ulong 0 1221 while gt sp 0 bound 262144 1222 top = ulong get c_stk sub sp 1 1223 c = ulong get c_dnx top 1224 if ne c 0 1225 x = sub c 1 1226 put c_dnx top get c_dsb x 1227 put c_stk sp uint x 1228 put c_pre x uint pr 1229 put c_dnx x get c_dch x 1230 pr = add pr 1 1231 sp = add sp 1 1232 else 1233 put c_pos top uint po 1234 po = add po 1 1235 sp = sub sp 1 1236 end 1237 end 1238 end 1239 note a dominates b (blocks, local indices; a dominates itself) 1240 fn ck_dom a ulong b ulong to bool 1241 if gt get c_pre a get c_pre b 1242 ret false 1243 end 1244 ret le get c_pos b get c_pos a 1245 end 1246 note ---- value numbering (IR.md s6.2) ------------------------------------------------------------- 1247 fn ck_vnum f ulong to void 1248 put c_f 3 0 1249 ck_vdef 20 0 0 0 1250 np = ulong get c_fnp f 1251 p0 = ulong get c_fp0 f 1252 for k ulong np bound 64 1253 ck_vdef ulong get c_fpt add p0 k 0 0 0 1254 end 1255 for j ulong get c_f 2 bound 65536 1256 ck_vblk j 1257 end 1258 end 1259 fn ck_vdef t ulong b ulong p ulong o ulong to void 1260 v = get c_f 3 1261 if ge v `2097152` 1262 ck_bad 23 ulong get c_fof get c_f 0 1263 end 1264 put c_vty v uint t 1265 put c_vb v uint b 1266 put c_vp v uint p 1267 put c_vo v uint o 1268 put c_f 3 add v 1 1269 end 1270 fn ck_vblk j ulong to void 1271 b = add get c_f 1 j 1272 put c_bv0 j uint get c_f 3 1273 p0 = ulong get c_bp0 b 1274 for k ulong ulong get c_bnp b bound 64 1275 ck_vdef ulong get c_bpt add p0 k j 0 0 1276 end 1277 o0 = ulong get c_bo0 b 1278 for k ulong ulong get c_bno b bound `1048576` 1279 ck_vop add o0 k j k 1280 end 1281 end 1282 fn ck_vop o ulong j ulong k ulong to void 1283 op = ck_op o 1284 put c_opb o uint j 1285 put c_opp o uint k 1286 put c_ov o uint get c_f 3 1287 if eq get c_rtk op 1 1288 ck_vdef 20 j add k 1 add o 1 1289 end 1290 c = ulong get c_rty op 1291 t = ck_ty o 1292 if and ne t 0 or eq c 1 eq c 2 1293 ck_vdef t j add k 1 add o 1 1294 end 1295 end 1296 note the result value of op o (after its token for an E op) 1297 fn ck_res o ulong to ulong 1298 v = ulong get c_ov o 1299 if eq get c_rtk ck_op o 1 1300 ret add v 1 1301 end 1302 ret v 1303 end 1304 note ---- coverage index: checks and facts keyed by their first value operand ---------------------- 1305 fn ck_covidx to void 1306 nv = get c_f 3 1307 for v ulong nv bound `2097152` 1308 put c_cvh v 0 1309 end 1310 for j ulong get c_f 2 bound 65536 1311 b = add get c_f 1 j 1312 o0 = ulong get c_bo0 b 1313 for k ulong ulong get c_bno b bound `1048576` 1314 ck_covadd add o0 k 1315 end 1316 end 1317 end 1318 fn ck_covadd o ulong to void 1319 op = ck_op o 1320 s = ulong 2 1321 if or eq op 79 or eq op 80 eq op 82 1322 s = 1 1323 end 1324 if or eq op 90 or eq op 92 eq op 93 1325 s = 0 1326 end 1327 if eq s 2 1328 ret 1329 end 1330 if le ck_na o s 1331 ret 1332 end 1333 r = ck_a o s 1334 if ge r get c_f 3 1335 ret 1336 end 1337 put c_cvn o get c_cvh r 1338 put c_cvh r uint add o 1 1339 end 1340 note ---- the op walk --------------------------------------------------------------------------------- 1341 fn ck_walk to void 1342 for j ulong get c_f 2 bound 65536 1343 b = add get c_f 1 j 1344 put c_f 4 0 1345 if ne j 0 1346 put c_f 4 ulong get c_bv0 j 1347 end 1348 o0 = ulong get c_bo0 b 1349 for k ulong ulong get c_bno b bound `1048576` 1350 ck_ochk add o0 k j k 1351 end 1352 end 1353 end 1354 fn ck_ochk o ulong j ulong k ulong to void 1355 put c_q 10 j 1356 put c_q 11 k 1357 put c_q 12 o 1358 op = ck_op o 1359 for s ulong ck_na o bound 128 1360 ck_opnd o op s 1361 end 1362 ck_tycol o op 1363 ck_place o op j 1364 ck_code o op 1365 ck_typing o op 1366 ck_cover o op 1367 if eq get c_rtk op 1 1368 put c_f 4 ulong get c_ov o 1369 end 1370 end 1371 note slot kind: 0 value, 1 block, 2 function, 3 the token 1372 fn ck_slot op ulong s ulong to ulong 1373 if eq op 60 1374 if eq s 0 1375 ret 1 1376 end 1377 if eq s 1 1378 ret 3 1379 end 1380 ret 0 1381 end 1382 if and eq s 0 ne get c_rtk op 0 1383 ret 3 1384 end 1385 if and eq op 61 or eq s 2 eq s 3 1386 ret 1 1387 end 1388 if and eq s 1 or eq op 64 eq op 67 1389 ret 2 1390 end 1391 ret 0 1392 end 1393 fn ck_opnd o ulong op ulong s ulong to void 1394 kd = ck_slot op s 1395 x = ck_a o s 1396 if eq kd 1 1397 ret 1398 end 1399 if eq kd 2 1400 ck_want lt x get c_n 3 24 1401 ret 1402 end 1403 ck_want lt x get c_f 3 17 1404 ck_usedef x 1405 t = ulong get c_vty x 1406 if eq kd 0 1407 ck_want ne t 20 28 1408 ret 1409 end 1410 ck_want eq t 20 28 1411 if ne get c_rtk op 2 1412 ck_want eq x get c_f 4 28 1413 end 1414 end 1415 note value v is defined before the use point (c_q 10 block, c_q 11 op position) 1416 fn ck_usedef v ulong to void 1417 vb = ulong get c_vb v 1418 b = get c_q 10 1419 if eq vb b 1420 ck_want le ulong get c_vp v get c_q 11 17 1421 ret 1422 end 1423 ck_want ck_dom vb b 18 1424 end 1425 note the ty field against the row's ty column 1426 fn ck_tycol o ulong op ulong to void 1427 c = ulong get c_rty op 1428 t = ck_ty o 1429 if eq c 0 1430 ck_want eq t 0 13 1431 ret 1432 end 1433 if and eq c 2 eq t 0 1434 ret 1435 end 1436 ck_want ne t 0 16 1437 x = ck_vtc t 1438 if ne x 0 1439 ck_fail x 1440 end 1441 if eq c 3 1442 ck_want ck_isint t 16 1443 end 1444 if and eq ck_kd t 6 ne get c_f 5 1 1445 ck_fail 22 1446 end 1447 end 1448 note kernel-only ops, ops kernels may not use, entry-block-only ops (EFFECT) 1449 fn ck_place o ulong op ulong j ulong to void 1450 k = get c_f 5 1451 if and ge op 111 le op 116 1452 ck_want ne k 1 22 1453 end 1454 if or or eq op 40 eq op 41 or eq op 44 eq op 45 1455 ck_want eq k 1 22 1456 end 1457 if or eq op 104 or eq op 105 eq op 106 1458 ck_want eq k 1 22 1459 end 1460 if or or eq op 64 eq op 66 or eq op 67 eq op 110 1461 ck_want ne k 1 22 1462 end 1463 if or eq op 41 eq op 50 1464 ck_want eq j 0 22 1465 end 1466 end 1467 note trap codes of checks and trap (CHECK_CODE), fact origins (NONCANONICAL) 1468 fn ck_code o ulong op ulong to void 1469 m = ck_im o 1470 if or eq op 65 eq op 82 1471 ck_want and ge m 1 le m 14 21 1472 ret 1473 end 1474 if and ge op 70 le op 81 1475 ck_want eq m ck_ccode op 21 1476 ret 1477 end 1478 if and ge op 90 le op 93 1479 ck_want le m 255 13 1480 end 1481 end 1482 fn ck_ccode op ulong to ulong 1483 if eq op 74 1484 ret 2 1485 end 1486 if eq op 77 1487 ret 7 1488 end 1489 if eq op 78 1490 ret 5 1491 end 1492 if or eq op 79 eq op 80 1493 ret 3 1494 end 1495 if eq op 81 1496 ret 4 1497 end 1498 ret 1 1499 end 1500 note ---- typing per row group (IR.md s7) ----------------------------------------------------------- 1501 fn ck_typing o ulong op ulong to void 1502 if le op 2 1503 ck_tconst o op 1504 ret 1505 end 1506 if and ge op 10 le op 28 1507 ck_tarith o op 1508 ret 1509 end 1510 if and ge op 30 le op 37 1511 ck_tcmp o op 1512 ret 1513 end 1514 if or eq op 42 eq op 43 1515 ck_tmem o op 1516 ret 1517 end 1518 if or and ge op 40 le op 45 eq op 46 1519 ck_tgpu o op 1520 ret 1521 end 1522 if and ge op 47 le op 59 1523 ck_tmem o op 1524 ret 1525 end 1526 if and ge op 60 le op 67 1527 ck_tctl o op 1528 ret 1529 end 1530 if and ge op 70 le op 82 1531 ck_tchk o op 1532 ret 1533 end 1534 if and ge op 90 le op 93 1535 ck_tfact o op 1536 ret 1537 end 1538 if and ge op 100 le op 106 1539 ck_tvops o op 1540 ret 1541 end 1542 if eq op 110 1543 ck_thost o 1544 end 1545 if and ge op 111 le op 116 1546 ck_tpool o op 1547 end 1548 end 1549 note canonical const bits for scalar type t (IR.md s7.2) 1550 fn ck_canon t ulong v ulong to bool 1551 w = mul ck_sb t 8 1552 if eq t 1 1553 ret le v 1 1554 end 1555 if eq w 64 1556 ret true 1557 end 1558 if ck_issgn t 1559 h = shl ulong 1 sub w 1 1560 ret lt add v h shl ulong 1 w 1561 end 1562 ret lt v shl ulong 1 w 1563 end 1564 fn ck_tconst o ulong op ulong to void 1565 t = ck_ty o 1566 if eq op 1 1567 ck_want or eq t 1 ck_isnum t 16 1568 ck_want ck_canon t ck_im o 13 1569 ret 1570 end 1571 ck_want eq ck_ta o 0 1 16 1572 ck_want eq ck_ta o 1 t 16 1573 ck_want eq ck_ta o 2 t 16 1574 end 1575 note every operand of op o from slot s0 on has type t 1576 fn ck_alltype o ulong s0 ulong t ulong to void 1577 for k ulong sub ck_na o s0 bound 128 1578 ck_want eq ck_ta o add s0 k t 16 1579 end 1580 end 1581 fn ck_tarith o ulong op ulong to void 1582 t = ck_ty o 1583 e = ck_el t 1584 ok = ck_isar e 1585 if eq op 14 1586 ok = ck_isint e 1587 end 1588 if and ge op 16 le op 19 1589 ok = or eq e 1 ck_isint e 1590 end 1591 if or eq op 20 eq op 21 1592 ok = ck_isint e 1593 end 1594 if or eq op 22 eq op 23 1595 ok = ck_isuns e 1596 end 1597 if and ge op 26 le op 28 1598 ok = ck_isflt e 1599 end 1600 ck_want ok 16 1601 ck_alltype o 0 t 1602 if eq op 28 1603 ck_fmathimm ck_im o 1604 end 1605 end 1606 fn ck_fmathimm m ulong to void 1607 fu = and m 255 1608 cl = and shr m 8 255 1609 n = and shr m 16 255 1610 ck_want le fu 7 13 1611 ck_want le cl 2 13 1612 ck_want eq shr m 25 0 13 1613 if eq cl 1 1614 ck_want ge n 1 13 1615 else 1616 ck_want eq n 0 13 1617 end 1618 end 1619 fn ck_tcmp o ulong op ulong to void 1620 t = ck_ty o 1621 if eq op 36 1622 ck_tconv o t 1623 ret 1624 end 1625 if eq op 37 1626 ck_tbits o t 1627 ret 1628 end 1629 s = ck_ta o 0 1630 ck_want eq ck_ta o 1 s 16 1631 e = ck_el s 1632 if or eq op 30 eq op 31 1633 ck_want or eq e 1 ck_isar e 16 1634 else 1635 ck_want ck_isar e 16 1636 end 1637 if eq ck_kd s 1 1638 ck_want eq ck_kd t 1 16 1639 ck_want eq ck_g1 t 1 16 1640 ck_want eq ck_g2 t ck_g2 s 16 1641 else 1642 ck_want eq t 1 16 1643 end 1644 end 1645 fn ck_tconv o ulong t ulong to void 1646 s = ck_ta o 0 1647 et = ck_el t 1648 es = ck_el s 1649 ck_want ck_isnum et 16 1650 ck_want ck_isnum es 16 1651 ck_want ne et es 16 1652 ck_want eq ck_kd s ck_kd t 16 1653 ck_want eq ck_lanes s ck_lanes t 16 1654 m = ck_im o 1655 if ck_isint et 1656 ck_want eq m 0 13 1657 else 1658 ck_want and le and m 3 1 eq shr m 3 0 13 1659 end 1660 end 1661 fn ck_tbits o ulong t ulong to void 1662 s = ck_ta o 0 1663 et = ck_el t 1664 es = ck_el s 1665 ck_want ck_isnum et 16 1666 ck_want ck_isnum es 16 1667 ck_want eq mul ck_sb et ck_lanes t mul ck_sb es ck_lanes s 16 1668 end 1669 fn ck_tgpu o ulong op ulong to void 1670 t = ck_ty o 1671 if eq op 40 1672 ck_want eq t 4 16 1673 ck_want le ck_im o 10 13 1674 end 1675 if eq op 41 1676 ck_want eq ck_kd t 4 16 1677 ck_want eq ck_g2 t 1 16 1678 ck_want eq ck_g3 t 2 16 1679 ck_want eq ck_kd ck_g1 t 2 16 1680 end 1681 if eq op 45 1682 ck_tshfl o t 1683 end 1684 if eq op 46 1685 ck_want ck_isflt ck_el t 16 1686 ck_alltype o 0 t 1687 end 1688 end 1689 note shfl v types (IR.md s7.7): u32, i32, f32 and u64, i64, f64 (ids 4, 8, 13 and 5, 9, 14) 1690 fn ck_shfty t ulong to bool 1691 if or eq t 4 eq t 8 1692 ret true 1693 end 1694 if or eq t 13 eq t 5 1695 ret true 1696 end 1697 ret or eq t 9 eq t 14 1698 end 1699 fn ck_tshfl o ulong t ulong to void 1700 ck_want ck_shfty t 16 1701 m = ck_im o 1702 ck_want and ge m 1 le m 4 13 1703 ck_want eq ck_ta o 0 t 16 1704 ck_want eq ck_ta o 1 4 16 1705 d = ck_cval ck_a o 1 1706 ck_want ne get c_q 15 0 16 1707 if le m 2 1708 ck_want ge d 1 16 1709 end 1710 ck_want le d 127 16 1711 sg = get c_f 7 1712 if ne sg 0 1713 ck_want lt d sg 16 1714 end 1715 end 1716 note the imm of the const defining value v into the result, c_q 15 = 1 when v is defined by a const 1717 fn ck_cval v ulong to ulong 1718 put c_q 15 0 1719 x = ulong get c_vo v 1720 if eq x 0 1721 ret 0 1722 end 1723 if ne ck_op sub x 1 1 1724 ret 0 1725 end 1726 put c_q 15 1 1727 ret ck_im sub x 1 1728 end 1729 note memory ops; r is slot 1 for token ops, slot 0 for len and fref 1730 fn ck_tmem o ulong op ulong to void 1731 t = ck_ty o 1732 if eq op 50 1733 ck_want eq ck_kd t 4 16 1734 ck_want eq ck_g2 t 1 16 1735 ck_want or eq ck_g3 t 0 eq ck_g3 t 4 16 1736 ret 1737 end 1738 if eq op 52 1739 ck_tgaddr o t 1740 ret 1741 end 1742 if eq op 53 1743 ck_want eq t 5 16 1744 ck_want ne ck_relt ck_ta o 0 0 16 1745 ret 1746 end 1747 if or eq op 55 or eq op 56 eq op 57 1748 ck_tfield o op t 1749 ret 1750 end 1751 r = ck_ta o 1 1752 e = ck_relt r 1753 ck_want ne e 0 16 1754 if or or eq op 43 eq op 47 or eq op 48 or eq op 51 eq op 59 1755 ck_want eq ck_g2 r 1 16 1756 end 1757 if eq op 51 1758 ck_want eq ck_ta o 2 e 16 1759 ret 1760 end 1761 if eq op 54 1762 ck_tslice o r e t 1763 ret 1764 end 1765 ck_want or eq ck_ta o 2 4 eq ck_ta o 2 5 16 1766 ck_tacc o op e t 1767 end 1768 fn ck_tacc o ulong op ulong e ulong t ulong to void 1769 if eq op 42 1770 ck_want eq t e 16 1771 ck_want or ne ck_sb e 0 eq ck_kd e 1 16 1772 end 1773 if eq op 43 1774 ck_want or ne ck_sb e 0 eq ck_kd e 1 16 1775 ck_want eq ck_ta o 3 e 16 1776 end 1777 if or eq op 47 eq op 48 1778 ck_tatom o op e t 1779 end 1780 if eq op 58 1781 ck_want ne ck_sb e 0 16 1782 ck_want eq ck_kd t 1 16 1783 ck_want eq ck_g1 t e 16 1784 end 1785 if eq op 59 1786 s = ck_ta o 3 1787 ck_want ne ck_sb e 0 16 1788 ck_want eq ck_kd s 1 16 1789 ck_want eq ck_g1 s e 16 1790 end 1791 end 1792 fn ck_tatom o ulong op ulong e ulong t ulong to void 1793 ck_want eq t e 16 1794 ck_want or or eq e 4 eq e 8 or or eq e 5 eq e 9 eq e 13 16 1795 m = ck_im o 1796 ck_want le and shr m 8 255 3 13 1797 ck_want le and shr m 16 255 1 13 1798 ck_want eq shr m 24 0 13 1799 ck_want eq ck_ta o 3 e 16 1800 if eq op 47 1801 ck_want le and m 255 6 13 1802 if eq e 13 1803 a = and m 255 1804 ck_want or or eq a 0 eq a 1 or eq a 2 eq a 6 16 1805 end 1806 else 1807 ck_want eq and m 255 0 13 1808 ck_want eq ck_ta o 4 e 16 1809 end 1810 end 1811 fn ck_tslice o ulong r ulong e ulong t ulong to void 1812 ck_want eq ck_ta o 2 5 16 1813 ck_want eq ck_ta o 3 5 16 1814 ck_want eq ck_kd t 5 16 1815 ck_want eq ck_g1 t e 16 1816 ck_want eq ck_g3 t ck_g3 r 16 1817 ck_want le ck_g2 t ck_g2 r 16 1818 end 1819 fn ck_tgaddr o ulong t ulong to void 1820 g = ck_im o 1821 ck_want lt g get c_n 2 24 1822 ck_want eq ck_kd t 4 16 1823 ck_want ne get c_gcl g 2 16 1824 ck_want eq ck_g1 t ulong get c_gty g 16 1825 ck_want eq ck_g3 t 0 16 1826 if eq get c_gcl g 1 1827 ck_want eq ck_g2 t 0 16 1828 end 1829 end 1830 note fload, fstore (r slot 1) and fref (r slot 0): REF to STRUCT, field index in imm 1831 fn ck_tfield o ulong op ulong t ulong to void 1832 s = ulong 1 1833 if eq op 57 1834 s = 0 1835 end 1836 r = ck_ta o s 1837 ck_want eq ck_kd r 4 16 1838 st = ck_g1 r 1839 ck_want eq ck_kd st 3 16 1840 x = ck_im o 1841 ck_want lt x ck_g2 st 16 1842 ft = ulong get c_xty add ck_g3 st x 1843 if eq op 55 1844 ck_want ne ck_sb ft 0 16 1845 ck_want eq t ft 16 1846 end 1847 if eq op 56 1848 ck_want ne ck_sb ft 0 16 1849 ck_want eq ck_g2 r 1 16 1850 ck_want eq ck_ta o 2 ft 16 1851 end 1852 if eq op 57 1853 ck_want eq ck_kd t 4 16 1854 ck_want eq ck_g1 t ft 16 1855 ck_want eq ck_g2 t ck_g2 r 16 1856 ck_want eq ck_g3 t ck_g3 r 16 1857 end 1858 end 1859 fn ck_tctl o ulong op ulong to void 1860 rs = get c_f 6 1861 if eq op 60 1862 ck_tbr o 1863 end 1864 if eq op 61 1865 ck_want eq ck_ta o 1 1 16 1866 end 1867 if eq op 62 1868 ck_want eq rs 0 16 1869 end 1870 if eq op 63 1871 ck_want ne rs 0 16 1872 ck_want eq ck_ta o 1 rs 16 1873 end 1874 if eq op 64 1875 ck_tcall o 2 1876 end 1877 if eq op 66 1878 ck_want eq ck_ta o 1 8 16 1879 end 1880 if eq op 67 1881 ck_want eq ck_ta o 2 4 16 1882 ck_want eq ck_ta o 3 4 16 1883 ck_want eq ck_ta o 4 4 16 1884 ck_tcall o 5 1885 end 1886 end 1887 note br: argument types equal the target's parameter types (BLOCK_ARITY) 1888 fn ck_tbr o ulong to void 1889 b = add get c_f 1 ck_a o 0 1890 p0 = ulong get c_bp0 b 1891 for k ulong sub ck_na o 1 bound 128 1892 ck_want eq ck_ta o add k 1 ulong get c_bpt add p0 k 19 1893 end 1894 end 1895 note call (arguments from slot 2) and launch (from slot 5): callee kind, count, types, result 1896 fn ck_tcall o ulong s0 ulong to void 1897 f = ck_a o 1 1898 k = ulong get c_fk f 1899 if eq s0 2 1900 ck_want ne k 1 22 1901 ck_want eq ck_ty o ulong get c_frs f 16 1902 else 1903 ck_want eq k 1 22 1904 end 1905 np = ulong get c_fnp f 1906 ck_want eq sub ck_na o s0 np 16 1907 p0 = ulong get c_fp0 f 1908 for j ulong np bound 64 1909 ck_want eq ck_ta o add s0 j ulong get c_fpt add p0 j 16 1910 end 1911 end 1912 fn ck_tchk o ulong op ulong to void 1913 a = ck_ta o 1 1914 if or eq op 70 or eq op 71 eq op 72 1915 ck_want ck_isint a 16 1916 ck_want eq ck_ta o 2 a 16 1917 end 1918 if or eq op 73 or eq op 74 eq op 77 1919 ck_want ck_isint a 16 1920 end 1921 if or eq op 75 eq op 76 1922 ck_want ck_issgn a 16 1923 ck_want eq ck_ta o 2 a 16 1924 end 1925 if eq op 78 1926 ck_want ck_isar a 16 1927 end 1928 if eq op 79 1929 ck_want ne ck_relt a 0 16 1930 ck_want or eq ck_ta o 2 4 eq ck_ta o 2 5 16 1931 ck_want eq ck_ta o 3 5 16 1932 end 1933 if eq op 80 1934 ck_want ne ck_relt a 0 16 1935 ck_want eq ck_ta o 2 5 16 1936 ck_want eq ck_ta o 3 5 16 1937 end 1938 if eq op 81 1939 ck_want eq a 5 16 1940 ck_want eq ck_ta o 2 5 16 1941 end 1942 if eq op 82 1943 ck_want eq a 1 16 1944 end 1945 end 1946 fn ck_tfact o ulong op ulong to void 1947 a = ck_ta o 0 1948 if eq op 90 1949 ck_want eq a 1 16 1950 ret 1951 end 1952 if eq op 91 1953 ck_trange o a 1954 ret 1955 end 1956 ck_want ne ck_relt a 0 16 1957 if eq op 92 1958 ck_want or eq ck_ta o 1 4 eq ck_ta o 1 5 16 1959 else 1960 ck_want eq ck_ta o 1 5 16 1961 end 1962 ck_want eq ck_ta o 2 5 16 1963 end 1964 fn ck_trange o ulong a ulong to void 1965 ck_want ck_isint a 16 1966 ck_want eq ck_ta o 1 a 16 1967 ck_want eq ck_ta o 2 a 16 1968 lo = ck_cval ck_a o 1 1969 ck_want ne get c_q 15 0 16 1970 hi = ck_cval ck_a o 2 1971 ck_want ne get c_q 15 0 16 1972 if ck_issgn a 1973 ck_want le long lo long hi 16 1974 else 1975 ck_want le lo hi 16 1976 end 1977 end 1978 fn ck_tvops o ulong op ulong to void 1979 t = ck_ty o 1980 if eq op 104 1981 ck_tmmald o t 1982 ret 1983 end 1984 if eq op 105 1985 ck_tmmast o 1986 ret 1987 end 1988 if eq op 106 1989 ck_tmma o t 1990 ret 1991 end 1992 if eq op 100 1993 ck_want eq ck_kd t 1 16 1994 ck_want eq ck_ta o 0 ck_g1 t 16 1995 ret 1996 end 1997 v = ck_ta o 0 1998 ck_want eq ck_kd v 1 16 1999 if eq op 101 2000 ck_want eq t ck_g1 v 16 2001 ck_want lt ck_im o ck_g2 v 16 2002 end 2003 if eq op 102 2004 ck_want eq v t 16 2005 ck_want eq ck_ta o 1 ck_g1 t 16 2006 ck_want lt ck_im o ck_g2 v 16 2007 end 2008 if eq op 103 2009 e = ck_g1 v 2010 ck_want eq t e 16 2011 m = ck_im o 2012 ck_want le m 5 13 2013 if ge m 3 2014 ck_want or eq e 1 ck_isint e 16 2015 else 2016 ck_want ck_isar e 16 2017 end 2018 end 2019 end 2020 fn ck_tmmald o ulong t ulong to void 2021 ck_want eq ck_kd t 6 16 2022 ck_want le ck_im o 1 13 2023 ck_want eq ck_relt ck_ta o 1 ck_g5 t 16 2024 ck_tmmidx o 2025 end 2026 fn ck_tmmidx o ulong to void 2027 ck_want or eq ck_ta o 2 4 eq ck_ta o 2 5 16 2028 ck_want eq ck_ta o 3 5 16 2029 ck_want eq ck_ta o 4 5 16 2030 end 2031 fn ck_tmmast o ulong to void 2032 r = ck_ta o 1 2033 d = ck_ta o 5 2034 ck_want le ck_im o 1 13 2035 ck_want eq ck_g2 r 1 16 2036 ck_want eq ck_kd d 6 16 2037 ck_want eq ck_g1 d 2 16 2038 ck_want eq ck_relt r ck_g5 d 16 2039 ck_tmmidx o 2040 end 2041 fn ck_tmma o ulong t ulong to void 2042 a = ck_ta o 0 2043 b = ck_ta o 1 2044 m = ck_im o 2045 ck_want or eq m 0 eq m 2 13 2046 ck_want and eq ck_kd t 6 eq ck_g1 t 2 16 2047 ck_want and eq ck_kd a 6 eq ck_g1 a 0 16 2048 ck_want and eq ck_kd b 6 eq ck_g1 b 1 16 2049 ck_want eq ck_ta o 2 t 16 2050 ck_want eq ck_g5 a ck_g5 b 16 2051 ck_tmmdim a t 2052 ck_tmmdim b t 2053 end 2054 fn ck_tmmdim a ulong t ulong to void 2055 ck_want eq ck_g2 a ck_g2 t 16 2056 ck_want eq ck_g3 a ck_g3 t 16 2057 ck_want eq ck_g4 a ck_g4 t 16 2058 end 2059 note host words (IR.md s7.11): word known, operand count and types per letter, slices covered 2060 fn ck_thost o ulong to void 2061 w = ck_im o 2062 ck_want lt w 256 22 2063 ck_want ne get c_hok w 0 22 2064 if eq get c_hcp w 1 2065 ck_want eq ck_ty o 0 16 2066 else 2067 ck_want eq ck_ty o 9 16 2068 end 2069 a = ulong get c_has w 2070 l = ulong get c_hal w 2071 c = ulong 0 2072 for i ulong l bound 16 2073 x = get c_hwt add a i 2074 c = add c 1 2075 if or eq x 114 or eq x 119 eq x 83 2076 c = add c 2 2077 end 2078 end 2079 ck_want eq sub ck_na o 1 c 16 2080 put c_q 13 0 2081 k = ulong 1 2082 for i ulong l bound 16 2083 k = ck_hlet o k ulong get c_hwt add a i 2084 end 2085 end 2086 fn ck_hlet o ulong k ulong x ulong to ulong 2087 t = ck_ta o k 2088 if eq x 105 2089 ck_want eq t 8 16 2090 end 2091 if eq x 108 2092 ck_want eq t 9 16 2093 end 2094 if eq x 76 2095 ck_want eq t 5 16 2096 end 2097 if eq x 117 2098 ck_want eq t 4 16 2099 put c_q 13 ck_cval ck_a o k 2100 ck_want ne get c_q 15 0 16 2101 end 2102 if or eq x 114 or eq x 119 eq x 83 2103 ck_hslice o k x 2104 ret add k 3 2105 end 2106 ret add k 1 2107 end 2108 fn ck_hslice o ulong k ulong x ulong to void 2109 r = ck_ta o k 2110 ck_want eq ck_relt r 2 16 2111 w = or eq x 119 and eq x 83 ne get c_q 13 15210 2112 if w 2113 ck_want eq ck_g2 r 1 16 2114 end 2115 ck_want eq ck_ta o add k 1 5 16 2116 ck_want eq ck_ta o add k 2 5 16 2117 ck_covq ck_a o k ck_a o add k 1 ck_a o add k 2 0 2118 put c_q 4 80 2119 put c_q 5 93 2120 put c_q 6 ck_a o 0 2121 ck_want ck_find 25 2122 end 2123 note ---- coverage and facts (IR.md s8, s7.10) ------------------------------------------------------- 2124 fn ck_covq r ulong x ulong y ulong m ulong to void 2125 put c_q 0 r 2126 put c_q 1 x 2127 put c_q 2 y 2128 put c_q 3 m 2129 end 2130 fn ck_cover o ulong op ulong to void 2131 if or or eq op 42 eq op 43 or eq op 47 eq op 48 2132 ck_covq ck_a o 1 ck_a o 2 1 1 2133 ck_covb o 2134 end 2135 if eq op 58 2136 ck_covq ck_a o 1 ck_a o 2 ck_lanes ck_ty o 1 2137 ck_covb o 2138 end 2139 if eq op 59 2140 ck_covq ck_a o 1 ck_a o 2 ck_lanes ck_ta o 3 1 2141 ck_covb o 2142 end 2143 if or eq op 104 eq op 105 2144 ck_covq ck_a o 1 ck_a o 2 ck_a o 4 0 2145 ck_covb o 2146 end 2147 if eq op 54 2148 ck_covq ck_a o 1 ck_a o 2 ck_a o 3 0 2149 put c_q 4 80 2150 put c_q 5 93 2151 put c_q 6 ck_a o 0 2152 ck_want ck_find 25 2153 end 2154 if and ge op 90 le op 93 2155 if eq ck_im o 0 2156 ck_facto o op 2157 end 2158 end 2159 end 2160 fn ck_covb o ulong to void 2161 put c_q 4 79 2162 put c_q 5 92 2163 put c_q 6 ck_a o 0 2164 ck_want ck_find 25 2165 end 2166 note origin 0 facts: dominated by the check with the same operands (no token rule; s7.10) 2167 fn ck_facto o ulong op ulong to void 2168 ck_want ne op 91 29 2169 put c_q 5 0 2170 put c_q 6 `4294967295` 2171 if eq op 90 2172 ck_covq ck_a o 0 0 0 2 2173 put c_q 4 82 2174 end 2175 if eq op 92 2176 ck_covq ck_a o 0 ck_a o 1 ck_a o 2 0 2177 put c_q 4 79 2178 end 2179 if eq op 93 2180 ck_covq ck_a o 0 ck_a o 1 ck_a o 2 0 2181 put c_q 4 80 2182 end 2183 ck_want ck_find 29 2184 end 2185 note search the list of r = c_q 0 for a covering op (c_q 4 check op, c_q 5 fact op or 0) 2186 fn ck_find to bool 2187 c = ulong get c_cvh get c_q 0 2188 while ne c 0 bound `4194305` 2189 if ck_cand sub c 1 2190 ret true 2191 end 2192 c = ulong get c_cvn sub c 1 2193 end 2194 ret false 2195 end 2196 fn ck_cand c ulong to bool 2197 op = ck_op c 2198 s = ulong 0 2199 if eq op get c_q 4 2200 s = 1 2201 else 2202 if or eq get c_q 5 0 ne op get c_q 5 2203 ret false 2204 end 2205 end 2206 if not ck_cmatch c s 2207 ret false 2208 end 2209 if not ck_cdom c 2210 ret false 2211 end 2212 if eq s 0 2213 ret true 2214 end 2215 ret ck_ctok c 2216 end 2217 note operands of candidate c (value operands from slot s) against c_q 1, 2 and mode c_q 3 2218 fn ck_cmatch c ulong s ulong to bool 2219 m = get c_q 3 2220 if eq m 2 2221 ret true 2222 end 2223 if le ck_na c add s 2 2224 ret false 2225 end 2226 if ne ck_a c add s 1 get c_q 1 2227 ret false 2228 end 2229 y = ck_a c add s 2 2230 if eq m 0 2231 ret eq y get c_q 2 2232 end 2233 if ge y get c_f 3 2234 ret false 2235 end 2236 e = ck_cval y 2237 if eq get c_q 15 0 2238 ret false 2239 end 2240 ret ge e get c_q 2 2241 end 2242 note rule 2: c dominates the use point 2243 fn ck_cdom c ulong to bool 2244 cb = ulong get c_opb c 2245 b = get c_q 10 2246 if eq cb b 2247 ret lt ulong get c_opp c get c_q 11 2248 end 2249 ret ck_dom cb b 2250 end 2251 note rule 3: the check's token is the access's token (c_q 6) or dominates its definition 2252 fn ck_ctok c ulong to bool 2253 t = get c_q 6 2254 if eq t `4294967295` 2255 ret true 2256 end 2257 tc = ulong get c_ov c 2258 if eq t tc 2259 ret true 2260 end 2261 cb = ulong get c_opb c 2262 tb = ulong get c_vb t 2263 if eq tb cb 2264 ret gt ulong get c_vp t ulong get c_opp c 2265 end 2266 ret ck_dom cb tb 2267 end 2268 note ---- main -------------------------------------------------------------------------------------- 2269 fn ck_slurp to ulong 2270 n = ulong 0 2271 while lt n len sh_dat bound `16777217` 2272 k = read 0 sh_dat n sub len sh_dat n 2273 if lt k 0 2274 ck_bad 27 n 2275 end 2276 if eq k 0 2277 ret n 2278 end 2279 n = add n ulong k 2280 end 2281 k = read 0 c_ob 0 1 2282 if gt k 0 2283 ck_bad 23 n 2284 end 2285 ret n 2286 end 2287 fn ck_istable to bool 2288 k = argread 1 c_ab 0 len c_ab 2289 if ne k 7 2290 ret false 2291 end 2292 for i ulong 7 2293 if ne get c_ab i get c_tx add 44 i 2294 ret false 2295 end 2296 end 2297 ret true 2298 end 2299 fn ck_accept n ulong to void 2300 sh_all n 2301 for j ulong 32 2302 b = uint get sh_dig j 2303 put c_ab mul j 2 sh_hexd shr b 4 2304 put c_ab add mul j 2 1 sh_hexd and b 15 2305 end 2306 ck_txt 3 1 2307 r = write 1 c_ab 0 64 2308 ck_txt 4 1 2309 ck_num get c_n 3 1 2310 ck_txt 5 1 2311 ck_num get c_n 4 1 2312 ck_txt 6 1 2313 ck_num get c_n 5 1 2314 ck_nl 1 2315 end 2316 fn main to int 2317 c = argcnt 2318 if gt c 1 2319 if and eq c 2 ck_istable 2320 r = write 1 c_hwt 0 sub len c_hwt c_hxn 2321 ret 0 2322 end 2323 ck_txt 8 2 2324 ck_nl 2 2325 ret 2 2326 end 2327 ck_rows 2328 ck_hosts 2329 n = ck_slurp 2330 put c_s 1 n 2331 ck_head 2332 ck_types 2333 ck_globs 2334 ck_funcs 2335 for f ulong get c_n 3 bound 65536 2336 ck_fn f 2337 end 2338 ck_accept n 2339 ret 0 2340 end 2341 2342 2343 note Class-2 pool globals never expose an address. Each access names the current storage. 2344 fn ck_tpool o ulong op ulong to void 2345 g = ck_im o 2346 ck_want lt g get c_n 2 24 2347 ck_want eq get c_gcl g 2 16 2348 t = ulong get c_gty g 2349 if eq op 112 2350 ck_want eq ck_ty o 5 16 2351 ret 2352 end 2353 if eq op 111 2354 ck_want eq ck_ty o 9 16 2355 ck_want eq ck_ta o 1 5 16 2356 ret 2357 end 2358 if eq op 113 2359 ck_want eq ck_ty o t 16 2360 ck_want eq ck_ta o 1 5 16 2361 ret 2362 end 2363 if eq op 114 2364 ck_want eq ck_ta o 1 5 16 2365 ck_want eq ck_ta o 2 t 16 2366 ret 2367 end 2368 ck_want eq ck_ty o 9 16 2369 ck_want eq ck_ta o 1 8 16 2370 ck_want eq ck_ta o 2 5 16 2371 ck_want eq ck_ta o 3 5 16 2372 ck_want eq t 2 16 2373 end