[all-commits] [llvm/llvm-project] 1509b4: [libclc] Improve nextafter behaviour around zero (...

Fraser Cormack via All-commits all-commits at lists.llvm.org
Wed Feb 19 02:24:35 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1509b46ea5617402634270a01e840356ef935436
      https://github.com/llvm/llvm-project/commit/1509b46ea5617402634270a01e840356ef935436
  Author: Fraser Cormack <fraser at codeplay.com>
  Date:   2025-02-19 (Wed, 19 Feb 2025)

  Changed paths:
    M libclc/clc/lib/generic/math/clc_nextafter.cl

  Log Message:
  -----------
  [libclc] Improve nextafter behaviour around zero (#127469)

This commit improves the behaviour of (__clc_)nextafter around zero.
Specifically, the nextafter value of very small negative numbers in the
positive direction is now negative zero. Previously we'd return positive
zero.

This behaviour is not required as far as OpenCL is concerned: at least,
the CTS isn't testing for it. However, this change does bring our
implementation into bit-equivalence with (libstdc++'s implementation of)
std::nextafter, tested on all possible values of 32-bit float towards
both positive and negative INFINITY.

Furthermore, since the implementation of libclc's floating-point 'rtp'
and 'rtz' conversions use __clc_nextafter, the previous behaviour was
resulting in CTS validation issues. For example, when converting float
-0x1.000002p-25 to half, rounding towards zero or positive infinity,
nextafter was returning +0.0, whereas the correct conversion requires us
to return -0.0.

We could work around this issue in the conversion functions, but since
the change to nextafter is small enough and the behaviour around zero
matches libstdc++, the fix feels at home there.

This commit also converts several variables to unsigned types to avoid
undefined behaviour surrounding signed underflow on the subtractions.
It also converts some variables to be kept in floating-point types, using
fabs to get the absolute value rather than by bit-hacking.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list