libclc: Use nextup and nextdown in place of nextafter (#188141)

Unfortunately it seems the optimizer isn't able to clean this
up, so this is a code quality improvement.
This commit is contained in:
Matt Arsenault 2026-03-24 08:06:01 +01:00 committed by GitHub
parent ef5658a289
commit 31aa52086f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View File

@ -118,8 +118,8 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_XCONCAT(__CLC_FUNCTION,
#else
__CLC_GENTYPE_SRC y = __CLC_XCONCAT(__clc_convert_, __CLC_GENTYPE_SRC)(r);
#endif
__CLC_GENTYPE sel = __clc_select(r, __clc_nextafter(r, __CLC_GENTYPE_INF),
__CLC_CONVERT_S_GENTYPE(y < x));
__CLC_GENTYPE sel =
__clc_select(r, __clc_nextup(r), __CLC_CONVERT_S_GENTYPE(y < x));
#if defined(__CLC_I2F) && (__CLC_FPSIZE == 16) && (__CLC_GENSIZE_SRC >= 16)
half dst_min = -0x1.ffcp+15h;
sel = __clc_max(sel, (__CLC_GENTYPE)dst_min);
@ -140,8 +140,7 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_XCONCAT(__CLC_FUNCTION,
#if defined(__CLC_I2F) && (__CLC_GENSIZE_SRC >= __CLC_FPSIZE)
c = c || __CLC_CONVERT_S_GENTYPE((__CLC_GENTYPE_SRC)__CLC_SRC_MAX == x);
#endif
__CLC_GENTYPE sel =
__clc_select(r, __clc_nextafter(r, -__CLC_GENTYPE_INF), c);
__CLC_GENTYPE sel = __clc_select(r, __clc_nextdown(r), c);
#if defined(__CLC_I2F) && (__CLC_FPSIZE == 16) && (__CLC_GENSIZE_SRC >= 16)
#if defined(__CLC_GEN_S) && (__CLC_GENSIZE_SRC == 16)
// short is 16 bits signed, so the maximum value rounded to negative infinity

View File

@ -11,6 +11,8 @@
#include "clc/float/definitions.h"
#include "clc/math/clc_fabs.h"
#include "clc/math/clc_nextafter.h"
#include "clc/math/clc_nextdown.h"
#include "clc/math/clc_nextup.h"
#include "clc/relational/clc_select.h"
#include "clc/shared/clc_clamp.h"

View File

@ -12,6 +12,8 @@
#include "clc/integer/clc_abs.h"
#include "clc/integer/definitions.h"
#include "clc/math/clc_nextafter.h"
#include "clc/math/clc_nextdown.h"
#include "clc/math/clc_nextup.h"
#include "clc/relational/clc_select.h"
#include "clc/shared/clc_clamp.h"
#include "clc/shared/clc_max.h"