Skip to content

perf(shader): pick the f32 NaN result with one quiet and one fallback select - #5343

Closed
ErenYeager1836 wants to merge 1 commit into
boykopovar:mainfrom
ErenYeager1836:carry/shader-f32-nan-result-once
Closed

ErenYeager1836 wants to merge 1 commit into
boykopovar:mainfrom
ErenYeager1836:carry/shader-f32-nan-result-once

Conversation

@ErenYeager1836

Copy link
Copy Markdown
Contributor

What

nanResultF32 selects AMD-compliant NaN results for f32 add, sub, subrev, mul, fma, v_div_fmas_f32, and v_fma_mix_f32 (returning the first NaN source quieted in IEEE mode, else fallback default NaN 0xffc00000). Previously, every source performed an independent integer and, comparison, quiet or, and select.

  • Streamlines the candidate chain to carry raw source bits, replacing the accumulator when product is 0 * inf.
  • Uses a single quiet operation and one final select between the eligible NaN candidate and the fallback, cutting redundant IR instructions across all floating point operations.
  • Validated against existing agc_driver_f32_arithmetic_nan test cases.

Carried from @karanvora2599 with author attribution preserved.

Tested

agc_driver_f32_arithmetic_nan in AgcDriver execution suite. Passes conventions check.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

… select

nanResultF32 gives the f32 add, sub, subrev, mul and fma forms, the legacy
mul, mad and fma forms, v_div_fmas_f32 and v_fma_mix_f32 with f32 sources
the AMD NaN result: the first NaN source, quieted in IEEE mode, else the
default NaN 0xffc00000 when the result is NaN, else the result. It started
from the fallback and then, for each source, tested it for NaN with an
integer and and compare, quieted it with its own or, and selected it. The
addend's test was also combined with the inverse of the invalid-product
flag.

The chain now carries only source bits. The addend starts it, replaced by 0
when the product is 0 * inf. Each earlier source that FPIsNan32 finds NaN
takes its place. One quiet and one select then choose between that source,
when it is NaN, and the fallback. The candidate is NaN exactly when some
eligible source is, and it is then the first one, so every result is the
same.

agc_driver_f32_arithmetic_nan already checks the source order and the 0 *
inf product with a NaN addend for every form.
@ErenYeager1836

Copy link
Copy Markdown
Contributor Author

Closing in favor of earlier open PR #4287 by @karanvora2599.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants