upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/fmisc_diff.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/fmisc_diff.py')
-rw-r--r--tools/fmisc_diff.py61
1 files changed, 55 insertions, 6 deletions
diff --git a/tools/fmisc_diff.py b/tools/fmisc_diff.py
index b5196ae62..c674cd60a 100644
--- a/tools/fmisc_diff.py
+++ b/tools/fmisc_diff.py
@@ -33,9 +33,12 @@ Every rule was checked against an RDNA2 GPU (AMD Radeon iGPU, gfx1036, Windows d
33 33
34Not judged (the program is skipped with the reason, counted): a denormal operand or result (whether f32 denormals 34Not judged (the program is skipped with the reason, counted): a denormal operand or result (whether f32 denormals
35are flushed is the MODE question, SHADER-35), a NaN whose payload is later read as an integer (payloads are not 35are flushed is the MODE question, SHADER-35), a NaN whose payload is later read as an integer (payloads are not
36modelled), the clamp of a NaN and an output modifier whose result is a zero (tools/f32_fuzz.py measures both), and 36modelled), the clamp of a NaN and an output modifier whose result is a zero (tools/f32_fuzz.py measures both), an
37an output modifier on a signalling-NaN result (the translator's multiply quiets it, which a later v_cmp_class sees; 37output modifier on a signalling-NaN result (the translator's multiply quiets it, which a later v_cmp_class sees;
38whether the hardware does is not measured). 38whether the hardware does is not measured), and the class bits of a NaN that a float op computed (v_fmamk_f32 & co.:
39whether the hardware quiets a signalling NaN operand is payload-level and only partly measured - on gfx1036 under
40the game's MODE it mostly passes the NaN source through unchanged but sometimes quiets or flips its sign, so a
41v_cmp_class_f32 on the result cannot be judged).
39 42
40Known divergences (KNOWN_DIVERGENCES): by default the generator leaves out the forms where the translator is known to 43Known divergences (KNOWN_DIVERGENCES): by default the generator leaves out the forms where the translator is known to
41differ from the hardware, so that a run shows new problems only; --known puts them back (a hardware-only run always 44differ from the hardware, so that a run shows new problems only; --known puts them back (a hardware-only run always
@@ -450,12 +453,39 @@ def raw(tok, st):
450 return int(tok, 0) & M32 453 return int(tok, 0) & M32
451 454
452 455
456def _vreg(tok):
457 """The VGPR a source token reads, ignoring neg/abs modifiers; None for anything else."""
458 if tok.startswith("-") and not tok[1:2].isdigit():
459 tok = tok[1:]
460 tok = tok.strip("|")
461 m = re.fullmatch(r"v(\d+)", tok)
462 return int(m.group(1)) if m else None
463
464
453def ivalue(tok, st): 465def ivalue(tok, st):
454 if re.fullmatch(r"v\d+", tok) and int(tok[1:]) in st["nan"]: 466 if re.fullmatch(r"v\d+", tok) and int(tok[1:]) in st["nan"]:
455 raise Uncertain("a computed NaN read as an integer") 467 raise Uncertain("a computed NaN read as an integer")
456 return raw(tok, st) 468 return raw(tok, st)
457 469
458 470
471# Ops whose NaN output is the NaN input's word, unchanged (a pass-through or a bit move): the quiet bit a
472# v_cmp_class_f32 later reads is the input's, modelled exactly when the input's is (st["nanf"] does not propagate
473# through them, it only survives). v_fmamk_f32 is the one op here that makes a NaN from its operands: on gfx1036
474# under the game's MODE (IEEE off) the hardware mostly returns the NaN source's word but sometimes quiets a
475# signalling one, so a signalling-NaN operand - or an operand whose NaN quiet bit is already unmodelled - makes
476# the result's class bits unmodelled too.
477NAN_PASSTHROUGH = {"v_fract_f32", "v_frexp_mant_f32", "v_frexp_exp_i32_f32", "v_ldexp_f32"}
478
479
480def _nan_fuzzy(tok, w, st):
481 """Whether a NaN input to v_fmamk_f32 leaves the result's quiet bit unmodelled: the input is signalling, or
482 it is a register whose NaN quiet bit already is."""
483 if not is_nan(w):
484 return False
485 r = _vreg(tok)
486 return (r is not None and r in st["nanf"]) or not w & 0x400000
487
488
459def fvalue(tok, st): 489def fvalue(tok, st):
460 neg = tok.startswith("-") and not tok[1:2].isdigit() 490 neg = tok.startswith("-") and not tok[1:2].isdigit()
461 if neg: 491 if neg:
@@ -489,7 +519,9 @@ def out_mods(w, mods):
489 519
490def reference(lines): 520def reference(lines):
491 """Run the program; returns the four exported words. Raises Uncertain for what it does not judge.""" 521 """Run the program; returns the four exported words. Raises Uncertain for what it does not judge."""
492 st = {"v": {}, "s": {}, "nan": set()} # nan: VGPRs holding a computed NaN (payload not modelled) 522 st = {"v": {}, "s": {}, "nan": set(), "nanf": set()} # nan: VGPRs holding a computed NaN (payload not
523 # modelled); nanf: of those, the ones whose quiet bit is not modelled either (a v_fmamk_f32 NaN, or a
524 # pass-through of one): a later v_cmp_class_f32 on them is Uncertain, everything else still judges them.
493 for line in lines: 525 for line in lines:
494 op, _, rest = line.partition(" ") 526 op, _, rest = line.partition(" ")
495 args, mods = parse(rest) 527 args, mods = parse(rest)
@@ -499,6 +531,9 @@ def reference(lines):
499 if op.startswith("v_cmp_"): 531 if op.startswith("v_cmp_"):
500 a = fvalue(args[1], st) 532 a = fvalue(args[1], st)
501 if op.startswith("v_cmp_class_f32"): 533 if op.startswith("v_cmp_class_f32"):
534 r = _vreg(args[1])
535 if r is not None and r in st["nanf"]:
536 raise Uncertain("the class bits of a NaN whose quiet bit is not modelled")
502 bit = class_bits(a) & ivalue(args[2], st) 537 bit = class_bits(a) & ivalue(args[2], st)
503 else: 538 else:
504 bit = fcmp(op[len("v_cmp_"):].split("_f32")[0], a, fvalue(args[2], st)) 539 bit = fcmp(op[len("v_cmp_"):].split("_f32")[0], a, fvalue(args[2], st))
@@ -508,8 +543,11 @@ def reference(lines):
508 if op in ("v_mov_b32_e32", "v_cndmask_b32_e64"): 543 if op in ("v_mov_b32_e32", "v_cndmask_b32_e64"):
509 src = args[1] if op == "v_mov_b32_e32" else args[2 if raw(args[3], st) & 1 else 1] 544 src = args[1] if op == "v_mov_b32_e32" else args[2 if raw(args[3], st) & 1 else 1]
510 st["v"][d] = raw(src, st) 545 st["v"][d] = raw(src, st)
511 nan = re.fullmatch(r"v\d+", src) and int(src[1:]) in st["nan"] 546 r = _vreg(src)
547 nan = r is not None and r in st["nan"]
512 (st["nan"].add if nan else st["nan"].discard)(d) 548 (st["nan"].add if nan else st["nan"].discard)(d)
549 fuzzy = r is not None and r in st["nanf"]
550 (st["nanf"].add if fuzzy else st["nanf"].discard)(d)
513 continue 551 continue
514 base = op[:-4] if op.endswith(("_e32", "_e64")) else op 552 base = op[:-4] if op.endswith(("_e32", "_e64")) else op
515 if base not in OPS: 553 if base not in OPS:
@@ -524,7 +562,18 @@ def reference(lines):
524 if is_denorm(w): 562 if is_denorm(w):
525 raise Uncertain("denormal result") 563 raise Uncertain("denormal result")
526 w = out_mods(w, mods) 564 w = out_mods(w, mods)
527 (st["nan"].add if fout and is_nan(w) else st["nan"].discard)(d) 565 nan_out = fout and is_nan(w)
566 # Read the sources' nanf before d's own entry is replaced (d may alias a source).
567 if not nan_out:
568 fuzzy = False
569 elif base == "v_fmamk_f32":
570 fuzzy = any(_nan_fuzzy(t, v, st) for t, v in zip(args[1:4], vals))
571 elif base in NAN_PASSTHROUGH:
572 fuzzy = any(_vreg(t) in st["nanf"] for t, f in zip(args[1:], fin) if f)
573 else:
574 fuzzy = False
575 (st["nan"].add if nan_out else st["nan"].discard)(d)
576 (st["nanf"].add if fuzzy else st["nanf"].discard)(d)
528 st["v"][d] = w 577 st["v"][d] = w
529 return [st["v"].get(8 + i, 0) for i in range(4)] 578 return [st["v"].get(8 + i, 0) for i in range(4)]
530 579