From 31aa52086fb2208f451be9e22197ae1a63cdc4af Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 24 Mar 2026 08:06:01 +0100 Subject: [PATCH] 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. --- libclc/clc/lib/generic/conversion/clc_convert_float.inc | 7 +++---- .../clc/lib/generic/conversion/clc_convert_float2float.cl | 2 ++ libclc/clc/lib/generic/conversion/clc_convert_int2float.cl | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libclc/clc/lib/generic/conversion/clc_convert_float.inc b/libclc/clc/lib/generic/conversion/clc_convert_float.inc index 19e0e3eb78c7..52244b2b6862 100644 --- a/libclc/clc/lib/generic/conversion/clc_convert_float.inc +++ b/libclc/clc/lib/generic/conversion/clc_convert_float.inc @@ -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 diff --git a/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl b/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl index aa5dbaf1ab73..5280e528ffd5 100644 --- a/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl +++ b/libclc/clc/lib/generic/conversion/clc_convert_float2float.cl @@ -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" diff --git a/libclc/clc/lib/generic/conversion/clc_convert_int2float.cl b/libclc/clc/lib/generic/conversion/clc_convert_int2float.cl index 33e81a95a5f6..4090c43f272e 100644 --- a/libclc/clc/lib/generic/conversion/clc_convert_int2float.cl +++ b/libclc/clc/lib/generic/conversion/clc_convert_int2float.cl @@ -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"