rust-lang / rust-lang/stdarch

nvptx: Incorrect use of LLVM intrinsics for f16x2_min/max(_nan)

Open
#2,056 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
694
Forks
336
Avg merge
5d 14h
Merged PRs (30d)
9

Description

The nvptx intrinsics f16x2_min/f16x2_max/f16x2_min_nan/f16x2_max_nan are currently being mapped to the LLVM intrinsics minnum/minimum/maxnum/maximum, respectively (in some cases this is indirected via simd_fmin/simd_fmax, which are documented to correspond to minnum nsz/maxnum nsz, but we currently don't actually emit the nsz attribute). See here for an overview of the LLVM float min/max operations.

This is incorrect:

  • According to the docs, the behavior for signed zeros is defined by (a < b) ? a : b, i.e., when both operands compare equal, the 2nd operand is returned. That's not what any of the LLVM intrinsics does: they either treat -0.0 as smaller than +0.0 (that's the default), or return either value non-deterministically (when the nsz attribute is present). [This means it is actually a bug that LLVM uses the min.f16x2 nvptx operation for lowering minnum...]
  • According to the docs, assuming that isNaN checks for both QNaN and SNaN, if exactly one input is any NaN, the other input is returned for f16x2_min/f16x2_max. In contrast, minnum/maxnum say that when an input is SNaN, the return value is a NaN or the other input. The LLVM variant with the correct NaN semantics is minimumnum/maximumnum.

Cc @kjetilkjeka @folkertdev

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the nvptx mappings for f16x2_min, f16x2_max, f16x2_min_nan, and f16x2_max_nan, including any simd_fmin or simd_fmax indirection. Read the LLVM floating-point min/max documentation and NVIDIA's half-precision min/max documentation first; done means the mappings preserve the documented signed-zero and NaN behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.