Output bit pattern mismatch between dynamic argument (arg) and kernel const for unary operator-(__half2) with QNaN payload

Issue Summary:

We identified a clear behavioral discrepancy in CUDA’s unary negation operator (operator-) defined in cuda_fp16.h. For the exact same QNaN payload input (0x7f557e01), the output bit pattern diverges drastically depending on whether the value is passed as a dynamic kernel argument (arg) or defined as a kernel const:

  • Path A: Dynamic Argument (-arg)

    • Output Bit Pattern: 0x7fff7fff

    • Analysis: The QNaN payload is canonicalized and lost (0x7e01 and 0x7f55 are replaced by 0x7fff).

  • Path B: In-kernel Constant (-const)

    • Output Bit Pattern: 0xff55fe01

    • Analysis: The original NaN payload is preserved, and only the sign bit is flipped (0x7e01 $\rightarrow$ 0xfe01, 0x7f55 $\rightarrow$ 0xff55).

This divergence violates the compiler invariant where $f(arg)$ must equal $f(const)$ for identical input binary representation.
Compiler Explorer: Compiler Explorer
Questions for NVIDIA:

  1. Why does dynamic argument evaluation canonicalize NaN payloads to 0x7fff7fff, while const evaluation preserves the payload by only flipping the sign bit (0xff55fe01)?

  2. Which output pattern is the intended IEEE-754 / CUDA specification for cuda_fp16.h’s operator-(__half2)?