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 / head-to-head / lib.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/head-to-head/lib.om: pure-Omega paired GPU benchmark comparator and verification harness. |
| 3 | note Derived from gpu-head-to-head (paired A/B timing statistics, numerical parity gate with NaN/Inf |
| 4 | note refusal, IQR non-overlap comparison, bandwidth GB/s, control-mutant verification, deterministic |
| 5 | note PASS/FAIL/NOT_RUN verdict emission). Library unit: no om2 directive, no fn main. |
| 6 | |
| 7 | const H2H_VERDICT_PASS ulong 0 |
| 8 | const H2H_VERDICT_FAIL ulong 1 |
| 9 | const H2H_VERDICT_NOT_RUN ulong 2 |
| 10 | |
| 11 | const H2H_REASON_OK ulong 0 |
| 12 | const H2H_REASON_NO_PAIRS ulong 1 |
| 13 | const H2H_REASON_NO_ELEMS ulong 2 |
| 14 | const H2H_REASON_BAD_TIMING ulong 3 |
| 15 | const H2H_REASON_PARITY_FAIL ulong 4 |
| 16 | const H2H_REASON_MUTANT_NOT_RUN ulong 5 |
| 17 | const H2H_REASON_MUTANT_ESCAPED ulong 6 |
| 18 | const H2H_REASON_BAD_TOL ulong 7 |
| 19 | |
| 20 | const H2H_CALL_OVERLAPPING ulong 0 |
| 21 | const H2H_CALL_B_FASTER ulong 1 |
| 22 | const H2H_CALL_A_FASTER ulong 2 |
| 23 | |
| 24 | const H2H_MAX_SAMPLES ulong 4096 |
| 25 | const H2H_MAX_ELEMS ulong 65536 |
| 26 | |
| 27 | struct H2hTol atol f64 rtol f64 end |
| 28 | struct H2hParity ok ulong elem_n ulong mismatches ulong nan_cnt ulong inf_cnt ulong max_abs f64 max_rel f64 end |
| 29 | struct H2hStats ok ulong n ulong min_ns ulong q1_ns ulong med_ns f64 q3_ns ulong iqr_ns ulong p95_ns ulong max_ns ulong end |
| 30 | struct H2hSummary verdict ulong reason ulong bytes_moved ulong speedup f64 bw_a_gbps f64 bw_b_gbps f64 iqr_call ulong parity_ok ulong mutant_checked ulong mutant_caught ulong end |
| 31 | |
| 32 | text h2h_t_pass "PASS" |
| 33 | text h2h_t_fail "FAIL" |
| 34 | text h2h_t_notrun "NOT_RUN" |
| 35 | text h2h_t_verdict "VERDICT=" |
| 36 | text h2h_t_reason " REASON=" |
| 37 | text h2h_t_nl "\n" |
| 38 | text h2h_t_arma "ARM_A " |
| 39 | text h2h_t_armb "ARM_B " |
| 40 | text h2h_t_n "n=" |
| 41 | text h2h_t_min " min_ns=" |
| 42 | text h2h_t_q1 " q1_ns=" |
| 43 | text h2h_t_med " median_ns=" |
| 44 | text h2h_t_q3 " q3_ns=" |
| 45 | text h2h_t_iqr " iqr_ns=" |
| 46 | text h2h_t_p95 " p95_ns=" |
| 47 | text h2h_t_max " max_ns=" |
| 48 | text h2h_t_cmp "COMPARE speedup=" |
| 49 | text h2h_t_bwa " bw_a_gbps=" |
| 50 | text h2h_t_bwb " bw_b_gbps=" |
| 51 | text h2h_t_call " iqr_call=" |
| 52 | text h2h_t_call_ov "OVERLAPPING" |
| 53 | text h2h_t_call_bf "ARM_B_FASTER" |
| 54 | text h2h_t_call_af "ARM_A_FASTER" |
| 55 | text h2h_t_par "PARITY ok=" |
| 56 | text h2h_t_elems " elems=" |
| 57 | text h2h_t_mis " mismatches=" |
| 58 | text h2h_t_nan " nan=" |
| 59 | text h2h_t_inf " inf=" |
| 60 | text h2h_t_mabs " max_abs=" |
| 61 | text h2h_t_mrel " max_rel=" |
| 62 | text h2h_t_mut "MUTANT checked=" |
| 63 | text h2h_t_caught " caught=" |
| 64 | text h2h_t_nan_str "NaN" |
| 65 | text h2h_t_inf_str "Inf" |
| 66 | text h2h_t_ninf_str "-Inf" |
| 67 | text h2h_t_minus "-" |
| 68 | text h2h_t_dot "." |
| 69 | text h2h_t_r_ok "ok" |
| 70 | text h2h_t_r_nopairs "no_pairs" |
| 71 | text h2h_t_r_noelems "no_elems" |
| 72 | text h2h_t_r_badtime "bad_timing" |
| 73 | text h2h_t_r_parfail "parity_failed" |
| 74 | text h2h_t_r_mutnr "mutant_not_run" |
| 75 | text h2h_t_r_mutesc "mutant_escaped" |
| 76 | text h2h_t_r_badtol "bad_tolerance" |
| 77 | |
| 78 | fn h2h_write_all fd int buf view uchar * to bool |
| 79 | n = len buf |
| 80 | pos = ulong 0 |
| 81 | while lt pos n bound 65536 |
| 82 | k = write fd buf pos sub n pos |
| 83 | if le k 0 |
| 84 | ret false |
| 85 | end |
| 86 | pos = add pos ulong k |
| 87 | end |
| 88 | ret true |
| 89 | end |
| 90 | |
| 91 | fn h2h_write_u64 fd int v ulong to void |
| 92 | digits = new uchar 24 0 |
| 93 | if eq v 0 |
| 94 | put digits 0 uchar 48 |
| 95 | ok0 = h2h_write_all fd part digits 0 1 |
| 96 | if ok0 |
| 97 | ret |
| 98 | end |
| 99 | ret |
| 100 | end |
| 101 | tmp = new uchar 24 0 |
| 102 | cnt = ulong 0 |
| 103 | x = v |
| 104 | while gt x 0 bound 24 |
| 105 | d = rem x 10 |
| 106 | put tmp cnt uchar add 48 d |
| 107 | cnt = add cnt 1 |
| 108 | x = div x 10 |
| 109 | end |
| 110 | i = ulong 0 |
| 111 | while lt i cnt bound 24 |
| 112 | put digits i get tmp sub sub cnt 1 i |
| 113 | i = add i 1 |
| 114 | end |
| 115 | ok1 = h2h_write_all fd part digits 0 cnt |
| 116 | if ok1 |
| 117 | ret |
| 118 | end |
| 119 | end |
| 120 | |
| 121 | fn h2h_f64_is_nan x f64 to bool |
| 122 | bits = bitcast ulong x |
| 123 | exp = and shr bits 52 0x7ff |
| 124 | frac = and bits 0xfffffffffffff |
| 125 | ret and eq exp 0x7ff ne frac 0 |
| 126 | end |
| 127 | |
| 128 | fn h2h_f64_is_inf x f64 to bool |
| 129 | bits = bitcast ulong x |
| 130 | exp = and shr bits 52 0x7ff |
| 131 | frac = and bits 0xfffffffffffff |
| 132 | ret and eq exp 0x7ff eq frac 0 |
| 133 | end |
| 134 | |
| 135 | fn h2h_f64_is_finite x f64 to bool |
| 136 | bits = bitcast ulong x |
| 137 | exp = and shr bits 52 0x7ff |
| 138 | ret ne exp 0x7ff |
| 139 | end |
| 140 | |
| 141 | fn h2h_f64_is_neg x f64 to bool |
| 142 | bits = bitcast ulong x |
| 143 | ret ne shr bits 63 0 |
| 144 | end |
| 145 | |
| 146 | fn h2h_write_f64_6 fd int x f64 to void |
| 147 | if h2h_f64_is_nan x |
| 148 | okn = h2h_write_all fd h2h_t_nan_str |
| 149 | if okn |
| 150 | ret |
| 151 | end |
| 152 | ret |
| 153 | end |
| 154 | if h2h_f64_is_inf x |
| 155 | if h2h_f64_is_neg x |
| 156 | okni = h2h_write_all fd h2h_t_ninf_str |
| 157 | if okni |
| 158 | ret |
| 159 | end |
| 160 | else |
| 161 | okpi = h2h_write_all fd h2h_t_inf_str |
| 162 | if okpi |
| 163 | ret |
| 164 | end |
| 165 | end |
| 166 | ret |
| 167 | end |
| 168 | val = x |
| 169 | if lt val 0.0f64 |
| 170 | okm = h2h_write_all fd h2h_t_minus |
| 171 | if okm |
| 172 | val = neg val |
| 173 | else |
| 174 | val = neg val |
| 175 | end |
| 176 | end |
| 177 | scaled = ulong add mul val 1000000.0f64 0.5f64 |
| 178 | whole = div scaled 1000000 |
| 179 | frac = rem scaled 1000000 |
| 180 | h2h_write_u64 fd whole |
| 181 | okd = h2h_write_all fd h2h_t_dot |
| 182 | fbuf = new uchar 6 48 |
| 183 | p = ulong 5 |
| 184 | remf = frac |
| 185 | for k ulong 6 |
| 186 | d = rem remf 10 |
| 187 | put fbuf p uchar add 48 d |
| 188 | remf = div remf 10 |
| 189 | if gt p 0 |
| 190 | p = sub p 1 |
| 191 | end |
| 192 | end |
| 193 | okf = h2h_write_all fd part fbuf 0 6 |
| 194 | if and okd okf |
| 195 | ret |
| 196 | end |
| 197 | end |
| 198 | |
| 199 | fn h2h_tol_valid tol view H2hTol to bool |
| 200 | a = get tol atol |
| 201 | r = get tol rtol |
| 202 | if not h2h_f64_is_finite a |
| 203 | ret false |
| 204 | end |
| 205 | if not h2h_f64_is_finite r |
| 206 | ret false |
| 207 | end |
| 208 | if lt a 0.0f64 |
| 209 | ret false |
| 210 | end |
| 211 | if lt r 0.0f64 |
| 212 | ret false |
| 213 | end |
| 214 | ret true |
| 215 | end |
| 216 | |
| 217 | fn h2h_parity_step va f64 vb f64 tol view H2hTol res edit H2hParity to void |
| 218 | bad_nf = false |
| 219 | if h2h_f64_is_nan va |
| 220 | put res nan_cnt add get res nan_cnt 1 |
| 221 | bad_nf = true |
| 222 | end |
| 223 | if h2h_f64_is_nan vb |
| 224 | put res nan_cnt add get res nan_cnt 1 |
| 225 | bad_nf = true |
| 226 | end |
| 227 | if h2h_f64_is_inf va |
| 228 | put res inf_cnt add get res inf_cnt 1 |
| 229 | bad_nf = true |
| 230 | end |
| 231 | if h2h_f64_is_inf vb |
| 232 | put res inf_cnt add get res inf_cnt 1 |
| 233 | bad_nf = true |
| 234 | end |
| 235 | if bad_nf |
| 236 | put res mismatches add get res mismatches 1 |
| 237 | ret |
| 238 | end |
| 239 | diff = fabs sub va vb |
| 240 | scale = fmax fabs va fabs vb |
| 241 | rel = 0.0f64 |
| 242 | if gt scale 0.0f64 |
| 243 | rel = div diff scale |
| 244 | end |
| 245 | if gt diff get res max_abs |
| 246 | put res max_abs diff |
| 247 | end |
| 248 | if gt rel get res max_rel |
| 249 | put res max_rel rel |
| 250 | end |
| 251 | lim = add get tol atol mul get tol rtol scale |
| 252 | if gt diff lim |
| 253 | put res mismatches add get res mismatches 1 |
| 254 | end |
| 255 | end |
| 256 | |
| 257 | fn h2h_check_parity a view f64 * b view f64 * tol view H2hTol res edit H2hParity to void |
| 258 | put res ok ulong 0 |
| 259 | put res elem_n ulong 0 |
| 260 | put res mismatches ulong 0 |
| 261 | put res nan_cnt ulong 0 |
| 262 | put res inf_cnt ulong 0 |
| 263 | put res max_abs 0.0f64 |
| 264 | put res max_rel 0.0f64 |
| 265 | na = len a |
| 266 | if eq na 0 |
| 267 | ret |
| 268 | end |
| 269 | if ne na len b |
| 270 | ret |
| 271 | end |
| 272 | if gt na H2H_MAX_ELEMS |
| 273 | ret |
| 274 | end |
| 275 | if not h2h_tol_valid tol |
| 276 | ret |
| 277 | end |
| 278 | put res elem_n na |
| 279 | i = ulong 0 |
| 280 | while lt i na bound 65536 |
| 281 | h2h_parity_step get a i get b i tol res |
| 282 | i = add i 1 |
| 283 | end |
| 284 | if eq get res mismatches 0 |
| 285 | if eq get res nan_cnt 0 |
| 286 | if eq get res inf_cnt 0 |
| 287 | put res ok ulong 1 |
| 288 | end |
| 289 | end |
| 290 | end |
| 291 | end |
| 292 | |
| 293 | fn h2h_sort_u64 arr edit ulong * n ulong to void |
| 294 | i = ulong 1 |
| 295 | while lt i n bound 4096 |
| 296 | key = get arr i |
| 297 | j = i |
| 298 | while gt j 0 bound 4096 |
| 299 | prev = get arr sub j 1 |
| 300 | if gt prev key |
| 301 | put arr j prev |
| 302 | j = sub j 1 |
| 303 | else |
| 304 | break |
| 305 | end |
| 306 | end |
| 307 | put arr j key |
| 308 | i = add i 1 |
| 309 | end |
| 310 | end |
| 311 | |
| 312 | fn h2h_pct_idx n ulong pct ulong to ulong |
| 313 | num = add mul pct n 99 |
| 314 | rank = div num 100 |
| 315 | if eq rank 0 |
| 316 | ret ulong 0 |
| 317 | end |
| 318 | idx = sub rank 1 |
| 319 | if ge idx n |
| 320 | ret sub n 1 |
| 321 | end |
| 322 | ret idx |
| 323 | end |
| 324 | |
| 325 | fn h2h_compute_stats raw view ulong * scratch edit ulong * st edit H2hStats to bool |
| 326 | put st ok ulong 0 |
| 327 | put st n ulong 0 |
| 328 | put st min_ns ulong 0 |
| 329 | put st q1_ns ulong 0 |
| 330 | put st med_ns 0.0f64 |
| 331 | put st q3_ns ulong 0 |
| 332 | put st iqr_ns ulong 0 |
| 333 | put st p95_ns ulong 0 |
| 334 | put st max_ns ulong 0 |
| 335 | n = len raw |
| 336 | if eq n 0 |
| 337 | ret false |
| 338 | end |
| 339 | if gt n H2H_MAX_SAMPLES |
| 340 | ret false |
| 341 | end |
| 342 | if gt n len scratch |
| 343 | ret false |
| 344 | end |
| 345 | i = ulong 0 |
| 346 | while lt i n bound 4096 |
| 347 | v = get raw i |
| 348 | if eq v 0 |
| 349 | ret false |
| 350 | end |
| 351 | put scratch i v |
| 352 | i = add i 1 |
| 353 | end |
| 354 | h2h_sort_u64 scratch n |
| 355 | minv = get scratch 0 |
| 356 | maxv = get scratch sub n 1 |
| 357 | half = div n 2 |
| 358 | med = 0.0f64 |
| 359 | if eq rem n 2 1 |
| 360 | med = f64 get scratch half |
| 361 | else |
| 362 | lo = f64 get scratch sub half 1 |
| 363 | hi = f64 get scratch half |
| 364 | med = mul 0.5f64 add lo hi |
| 365 | end |
| 366 | q1 = get scratch h2h_pct_idx n 25 |
| 367 | q3 = get scratch h2h_pct_idx n 75 |
| 368 | p95 = get scratch h2h_pct_idx n 95 |
| 369 | put st ok ulong 1 |
| 370 | put st n n |
| 371 | put st min_ns minv |
| 372 | put st q1_ns q1 |
| 373 | put st med_ns med |
| 374 | put st q3_ns q3 |
| 375 | put st iqr_ns sub q3 q1 |
| 376 | put st p95_ns p95 |
| 377 | put st max_ns maxv |
| 378 | ret true |
| 379 | end |
| 380 | |
| 381 | fn h2h_iqr_call sa view H2hStats sb view H2hStats to ulong |
| 382 | if lt get sb q3_ns get sa q1_ns |
| 383 | ret H2H_CALL_B_FASTER |
| 384 | end |
| 385 | if lt get sa q3_ns get sb q1_ns |
| 386 | ret H2H_CALL_A_FASTER |
| 387 | end |
| 388 | ret H2H_CALL_OVERLAPPING |
| 389 | end |
| 390 | |
| 391 | fn h2h_speedup med_a f64 med_b f64 to f64 |
| 392 | if le med_b 0.0f64 |
| 393 | ret 0.0f64 |
| 394 | end |
| 395 | if not h2h_f64_is_finite med_a |
| 396 | ret 0.0f64 |
| 397 | end |
| 398 | if not h2h_f64_is_finite med_b |
| 399 | ret 0.0f64 |
| 400 | end |
| 401 | ret div med_a med_b |
| 402 | end |
| 403 | |
| 404 | fn h2h_bw_gbps bytes_moved ulong med_ns f64 to f64 |
| 405 | if le med_ns 0.0f64 |
| 406 | ret 0.0f64 |
| 407 | end |
| 408 | if not h2h_f64_is_finite med_ns |
| 409 | ret 0.0f64 |
| 410 | end |
| 411 | note bytes per nanosecond equals decimal GB/s (1e9 bytes/s) |
| 412 | ret div f64 bytes_moved med_ns |
| 413 | end |
| 414 | |
| 415 | fn h2h_make_wrong_kernel_mutant ref_a view f64 * dst edit f64 * to ulong |
| 416 | n = len ref_a |
| 417 | if gt n len dst |
| 418 | ret ulong 0 |
| 419 | end |
| 420 | if gt n H2H_MAX_ELEMS |
| 421 | ret ulong 0 |
| 422 | end |
| 423 | note Deliberate wrong-kernel control: poisons output like coldstart --skip-run / offset error |
| 424 | i = ulong 0 |
| 425 | while lt i n bound 65536 |
| 426 | v = get ref_a i |
| 427 | put dst i add neg v 1337.25f64 |
| 428 | i = add i 1 |
| 429 | end |
| 430 | ret n |
| 431 | end |
| 432 | |
| 433 | fn h2h_verify_mutant ref_a view f64 * mut_b view f64 * tol view H2hTol mres edit H2hParity to bool |
| 434 | na = len ref_a |
| 435 | nb = len mut_b |
| 436 | if or eq na 0 ne na nb |
| 437 | ret false |
| 438 | end |
| 439 | if not h2h_tol_valid tol |
| 440 | ret false |
| 441 | end |
| 442 | h2h_check_parity ref_a mut_b tol mres |
| 443 | note Control succeeds only when the deliberate wrong kernel FAILS parity |
| 444 | ret eq get mres ok 0 |
| 445 | end |
| 446 | |
| 447 | fn h2h_finalize_summary sa view H2hStats sb view H2hStats par view H2hParity mchk ulong mcaught ulong sum edit H2hSummary to void |
| 448 | put sum verdict H2H_VERDICT_NOT_RUN |
| 449 | put sum reason H2H_REASON_OK |
| 450 | put sum speedup 0.0f64 |
| 451 | put sum bw_a_gbps 0.0f64 |
| 452 | put sum bw_b_gbps 0.0f64 |
| 453 | put sum iqr_call H2H_CALL_OVERLAPPING |
| 454 | put sum parity_ok get par ok |
| 455 | put sum mutant_checked mchk |
| 456 | put sum mutant_caught mcaught |
| 457 | if or eq get sa n 0 eq get sb n 0 |
| 458 | if or eq get sa ok 0 eq get sb ok 0 |
| 459 | put sum verdict H2H_VERDICT_NOT_RUN |
| 460 | put sum reason H2H_REASON_NO_PAIRS |
| 461 | ret |
| 462 | end |
| 463 | end |
| 464 | if or eq get sa ok 0 eq get sb ok 0 |
| 465 | put sum verdict H2H_VERDICT_FAIL |
| 466 | put sum reason H2H_REASON_BAD_TIMING |
| 467 | ret |
| 468 | end |
| 469 | if ne get sa n get sb n |
| 470 | put sum verdict H2H_VERDICT_FAIL |
| 471 | put sum reason H2H_REASON_BAD_TIMING |
| 472 | ret |
| 473 | end |
| 474 | bm = get sum bytes_moved |
| 475 | put sum speedup h2h_speedup get sa med_ns get sb med_ns |
| 476 | put sum bw_a_gbps h2h_bw_gbps bm get sa med_ns |
| 477 | put sum bw_b_gbps h2h_bw_gbps bm get sb med_ns |
| 478 | put sum iqr_call h2h_iqr_call sa sb |
| 479 | if eq get par elem_n 0 |
| 480 | put sum verdict H2H_VERDICT_NOT_RUN |
| 481 | put sum reason H2H_REASON_NO_ELEMS |
| 482 | ret |
| 483 | end |
| 484 | if eq get par ok 0 |
| 485 | put sum verdict H2H_VERDICT_FAIL |
| 486 | put sum reason H2H_REASON_PARITY_FAIL |
| 487 | ret |
| 488 | end |
| 489 | if eq mchk 0 |
| 490 | put sum verdict H2H_VERDICT_NOT_RUN |
| 491 | put sum reason H2H_REASON_MUTANT_NOT_RUN |
| 492 | ret |
| 493 | end |
| 494 | if eq mcaught 0 |
| 495 | put sum verdict H2H_VERDICT_FAIL |
| 496 | put sum reason H2H_REASON_MUTANT_ESCAPED |
| 497 | ret |
| 498 | end |
| 499 | put sum verdict H2H_VERDICT_PASS |
| 500 | put sum reason H2H_REASON_OK |
| 501 | end |
| 502 | |
| 503 | fn h2h_write_reason fd int reason ulong to void |
| 504 | ok = false |
| 505 | if eq reason H2H_REASON_OK |
| 506 | ok = h2h_write_all fd h2h_t_r_ok |
| 507 | else |
| 508 | if eq reason H2H_REASON_NO_PAIRS |
| 509 | ok = h2h_write_all fd h2h_t_r_nopairs |
| 510 | else |
| 511 | if eq reason H2H_REASON_NO_ELEMS |
| 512 | ok = h2h_write_all fd h2h_t_r_noelems |
| 513 | else |
| 514 | if eq reason H2H_REASON_BAD_TIMING |
| 515 | ok = h2h_write_all fd h2h_t_r_badtime |
| 516 | else |
| 517 | if eq reason H2H_REASON_PARITY_FAIL |
| 518 | ok = h2h_write_all fd h2h_t_r_parfail |
| 519 | else |
| 520 | if eq reason H2H_REASON_MUTANT_NOT_RUN |
| 521 | ok = h2h_write_all fd h2h_t_r_mutnr |
| 522 | else |
| 523 | if eq reason H2H_REASON_MUTANT_ESCAPED |
| 524 | ok = h2h_write_all fd h2h_t_r_mutesc |
| 525 | else |
| 526 | ok = h2h_write_all fd h2h_t_r_badtol |
| 527 | end |
| 528 | end |
| 529 | end |
| 530 | end |
| 531 | end |
| 532 | end |
| 533 | end |
| 534 | if ok |
| 535 | ret |
| 536 | end |
| 537 | end |
| 538 | |
| 539 | fn h2h_write_stats_line fd int is_b ulong st view H2hStats to void |
| 540 | ok = false |
| 541 | if eq is_b 0 |
| 542 | ok = h2h_write_all fd h2h_t_arma |
| 543 | else |
| 544 | ok = h2h_write_all fd h2h_t_armb |
| 545 | end |
| 546 | ok = and ok h2h_write_all fd h2h_t_n |
| 547 | h2h_write_u64 fd get st n |
| 548 | ok = and ok h2h_write_all fd h2h_t_min |
| 549 | h2h_write_u64 fd get st min_ns |
| 550 | ok = and ok h2h_write_all fd h2h_t_q1 |
| 551 | h2h_write_u64 fd get st q1_ns |
| 552 | ok = and ok h2h_write_all fd h2h_t_med |
| 553 | h2h_write_f64_6 fd get st med_ns |
| 554 | ok = and ok h2h_write_all fd h2h_t_q3 |
| 555 | h2h_write_u64 fd get st q3_ns |
| 556 | ok = and ok h2h_write_all fd h2h_t_iqr |
| 557 | h2h_write_u64 fd get st iqr_ns |
| 558 | ok = and ok h2h_write_all fd h2h_t_p95 |
| 559 | h2h_write_u64 fd get st p95_ns |
| 560 | ok = and ok h2h_write_all fd h2h_t_max |
| 561 | h2h_write_u64 fd get st max_ns |
| 562 | ok = and ok h2h_write_all fd h2h_t_nl |
| 563 | if ok |
| 564 | ret |
| 565 | end |
| 566 | end |
| 567 | |
| 568 | fn h2h_emit_report fd int sa view H2hStats sb view H2hStats par view H2hParity sum view H2hSummary to void |
| 569 | ok = h2h_write_all fd h2h_t_verdict |
| 570 | v = get sum verdict |
| 571 | if eq v H2H_VERDICT_PASS |
| 572 | ok = and ok h2h_write_all fd h2h_t_pass |
| 573 | else |
| 574 | if eq v H2H_VERDICT_FAIL |
| 575 | ok = and ok h2h_write_all fd h2h_t_fail |
| 576 | else |
| 577 | ok = and ok h2h_write_all fd h2h_t_notrun |
| 578 | end |
| 579 | end |
| 580 | ok = and ok h2h_write_all fd h2h_t_reason |
| 581 | h2h_write_reason fd get sum reason |
| 582 | ok = and ok h2h_write_all fd h2h_t_nl |
| 583 | h2h_write_stats_line fd 0 sa |
| 584 | h2h_write_stats_line fd 1 sb |
| 585 | ok = and ok h2h_write_all fd h2h_t_cmp |
| 586 | h2h_write_f64_6 fd get sum speedup |
| 587 | ok = and ok h2h_write_all fd h2h_t_bwa |
| 588 | h2h_write_f64_6 fd get sum bw_a_gbps |
| 589 | ok = and ok h2h_write_all fd h2h_t_bwb |
| 590 | h2h_write_f64_6 fd get sum bw_b_gbps |
| 591 | ok = and ok h2h_write_all fd h2h_t_call |
| 592 | ic = get sum iqr_call |
| 593 | if eq ic H2H_CALL_B_FASTER |
| 594 | ok = and ok h2h_write_all fd h2h_t_call_bf |
| 595 | else |
| 596 | if eq ic H2H_CALL_A_FASTER |
| 597 | ok = and ok h2h_write_all fd h2h_t_call_af |
| 598 | else |
| 599 | ok = and ok h2h_write_all fd h2h_t_call_ov |
| 600 | end |
| 601 | end |
| 602 | ok = and ok h2h_write_all fd h2h_t_nl |
| 603 | ok = and ok h2h_write_all fd h2h_t_par |
| 604 | h2h_write_u64 fd get par ok |
| 605 | ok = and ok h2h_write_all fd h2h_t_elems |
| 606 | h2h_write_u64 fd get par elem_n |
| 607 | ok = and ok h2h_write_all fd h2h_t_mis |
| 608 | h2h_write_u64 fd get par mismatches |
| 609 | ok = and ok h2h_write_all fd h2h_t_nan |
| 610 | h2h_write_u64 fd get par nan_cnt |
| 611 | ok = and ok h2h_write_all fd h2h_t_inf |
| 612 | h2h_write_u64 fd get par inf_cnt |
| 613 | ok = and ok h2h_write_all fd h2h_t_mabs |
| 614 | h2h_write_f64_6 fd get par max_abs |
| 615 | ok = and ok h2h_write_all fd h2h_t_mrel |
| 616 | h2h_write_f64_6 fd get par max_rel |
| 617 | ok = and ok h2h_write_all fd h2h_t_nl |
| 618 | ok = and ok h2h_write_all fd h2h_t_mut |
| 619 | h2h_write_u64 fd get sum mutant_checked |
| 620 | ok = and ok h2h_write_all fd h2h_t_caught |
| 621 | h2h_write_u64 fd get sum mutant_caught |
| 622 | ok = and ok h2h_write_all fd h2h_t_nl |
| 623 | if ok |
| 624 | ret |
| 625 | end |
| 626 | end |
| 627 | |
| 628 | fn h2h_is_ws b uchar to bool |
| 629 | ret or eq b 32 or eq b 9 eq b 13 |
| 630 | end |
| 631 | |
| 632 | fn h2h_skip_ws buf view uchar * pos ulong endpos ulong to ulong |
| 633 | p = pos |
| 634 | while lt p endpos bound 1024 |
| 635 | if not h2h_is_ws get buf p |
| 636 | break |
| 637 | end |
| 638 | p = add p 1 |
| 639 | end |
| 640 | ret p |
| 641 | end |
| 642 | |
| 643 | fn h2h_next_tok_end buf view uchar * pos ulong endpos ulong to ulong |
| 644 | p = pos |
| 645 | while lt p endpos bound 1024 |
| 646 | if h2h_is_ws get buf p |
| 647 | break |
| 648 | end |
| 649 | p = add p 1 |
| 650 | end |
| 651 | ret p |
| 652 | end |
| 653 | |
| 654 | fn h2h_tok_eq buf view uchar * s ulong e ulong lit view uchar * to bool |
| 655 | ln = len lit |
| 656 | if ne sub e s ln |
| 657 | ret false |
| 658 | end |
| 659 | i = ulong 0 |
| 660 | while lt i ln bound 64 |
| 661 | if ne get buf add s i get lit i |
| 662 | ret false |
| 663 | end |
| 664 | i = add i 1 |
| 665 | end |
| 666 | ret true |
| 667 | end |
| 668 | |
| 669 | fn h2h_parse_u64_ok buf view uchar * s ulong e ulong to bool |
| 670 | if ge s e |
| 671 | ret false |
| 672 | end |
| 673 | if gt sub e s 20 |
| 674 | ret false |
| 675 | end |
| 676 | i = s |
| 677 | while lt i e bound 24 |
| 678 | c = get buf i |
| 679 | if or lt c 48 gt c 57 |
| 680 | ret false |
| 681 | end |
| 682 | i = add i 1 |
| 683 | end |
| 684 | ret true |
| 685 | end |
| 686 | |
| 687 | fn h2h_parse_u64_val buf view uchar * s ulong e ulong to ulong |
| 688 | acc = ulong 0 |
| 689 | i = s |
| 690 | while lt i e bound 24 |
| 691 | d = ulong sub get buf i 48 |
| 692 | acc = add mul acc 10 d |
| 693 | i = add i 1 |
| 694 | end |
| 695 | ret acc |
| 696 | end |
| 697 | |
| 698 | fn h2h_parse_f64_ok buf view uchar * s ulong e ulong to bool |
| 699 | if ge s e |
| 700 | ret false |
| 701 | end |
| 702 | if gt sub e s 32 |
| 703 | ret false |
| 704 | end |
| 705 | i = s |
| 706 | if or eq get buf i 45 eq get buf i 43 |
| 707 | i = add i 1 |
| 708 | end |
| 709 | if ge i e |
| 710 | ret false |
| 711 | end |
| 712 | digits = ulong 0 |
| 713 | dots = ulong 0 |
| 714 | while lt i e bound 32 |
| 715 | c = get buf i |
| 716 | if and ge c 48 le c 57 |
| 717 | digits = add digits 1 |
| 718 | else |
| 719 | if eq c 46 |
| 720 | dots = add dots 1 |
| 721 | if gt dots 1 |
| 722 | ret false |
| 723 | end |
| 724 | else |
| 725 | if or eq c 101 eq c 69 |
| 726 | if eq digits 0 |
| 727 | ret false |
| 728 | end |
| 729 | i = add i 1 |
| 730 | if lt i e |
| 731 | if or eq get buf i 45 eq get buf i 43 |
| 732 | i = add i 1 |
| 733 | end |
| 734 | end |
| 735 | edig = ulong 0 |
| 736 | while lt i e bound 16 |
| 737 | ec = get buf i |
| 738 | if or lt ec 48 gt ec 57 |
| 739 | ret false |
| 740 | end |
| 741 | edig = add edig 1 |
| 742 | i = add i 1 |
| 743 | end |
| 744 | ret gt edig 0 |
| 745 | else |
| 746 | ret false |
| 747 | end |
| 748 | end |
| 749 | end |
| 750 | i = add i 1 |
| 751 | end |
| 752 | ret gt digits 0 |
| 753 | end |
| 754 | |
| 755 | fn h2h_pow10_f64 exp int to f64 |
| 756 | res = 1.0f64 |
| 757 | if gt exp 0 |
| 758 | e = ulong exp |
| 759 | if gt e 300 |
| 760 | e = ulong 300 |
| 761 | end |
| 762 | i = ulong 0 |
| 763 | while lt i e bound 301 |
| 764 | res = mul res 10.0f64 |
| 765 | i = add i 1 |
| 766 | end |
| 767 | else |
| 768 | if lt exp 0 |
| 769 | e = ulong neg exp |
| 770 | if gt e 300 |
| 771 | e = ulong 300 |
| 772 | end |
| 773 | i = ulong 0 |
| 774 | while lt i e bound 301 |
| 775 | res = div res 10.0f64 |
| 776 | i = add i 1 |
| 777 | end |
| 778 | end |
| 779 | end |
| 780 | ret res |
| 781 | end |
| 782 | |
| 783 | fn h2h_parse_exp buf view uchar * pos ulong e ulong to int |
| 784 | i = pos |
| 785 | sgn = int 1 |
| 786 | if lt i e |
| 787 | if eq get buf i 45 |
| 788 | sgn = int -1 |
| 789 | i = add i 1 |
| 790 | else |
| 791 | if eq get buf i 43 |
| 792 | i = add i 1 |
| 793 | end |
| 794 | end |
| 795 | end |
| 796 | ev = int 0 |
| 797 | while lt i e bound 16 |
| 798 | ed = int sub get buf i 48 |
| 799 | ev = add mul ev 10 ed |
| 800 | i = add i 1 |
| 801 | end |
| 802 | ret mul sgn ev |
| 803 | end |
| 804 | |
| 805 | fn h2h_parse_f64_val buf view uchar * s ulong e ulong to f64 |
| 806 | i = s |
| 807 | is_neg = false |
| 808 | if eq get buf i 45 |
| 809 | is_neg = true |
| 810 | i = add i 1 |
| 811 | else |
| 812 | if eq get buf i 43 |
| 813 | i = add i 1 |
| 814 | end |
| 815 | end |
| 816 | val = 0.0f64 |
| 817 | frac_div = 1.0f64 |
| 818 | in_frac = false |
| 819 | exp_total = int 0 |
| 820 | while lt i e bound 32 |
| 821 | c = get buf i |
| 822 | if and ge c 48 le c 57 |
| 823 | d = f64 sub c 48 |
| 824 | if in_frac |
| 825 | frac_div = mul frac_div 10.0f64 |
| 826 | val = add val div d frac_div |
| 827 | else |
| 828 | val = add mul val 10.0f64 d |
| 829 | end |
| 830 | else |
| 831 | if eq c 46 |
| 832 | in_frac = true |
| 833 | else |
| 834 | if or eq c 101 eq c 69 |
| 835 | exp_total = h2h_parse_exp buf add i 1 e |
| 836 | break |
| 837 | end |
| 838 | end |
| 839 | end |
| 840 | i = add i 1 |
| 841 | end |
| 842 | if ne exp_total 0 |
| 843 | val = mul val h2h_pow10_f64 exp_total |
| 844 | end |
| 845 | if is_neg |
| 846 | val = neg val |
| 847 | end |
| 848 | ret val |
| 849 | end |