From 2dfb29a9b2f63e8dcbace2bf9b73ecc770f62b4d Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Mon, 24 Feb 2025 15:41:31 +0000 Subject: [PATCH] [libclc] Move nan to the CLC library (#128521) --- libclc/clc/include/clc/math/clc_nan.h | 12 ++++++++++++ libclc/clc/include/clc/math/clc_nan.inc | 1 + libclc/clc/lib/generic/SOURCES | 1 + libclc/clc/lib/generic/math/clc_nan.cl | 5 +++++ libclc/clc/lib/generic/math/clc_nan.inc | 15 +++++++++++++++ libclc/generic/lib/math/nan.cl | 5 ++--- libclc/generic/lib/math/nan.inc | 14 +------------- 7 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 libclc/clc/include/clc/math/clc_nan.h create mode 100644 libclc/clc/include/clc/math/clc_nan.inc create mode 100644 libclc/clc/lib/generic/math/clc_nan.cl create mode 100644 libclc/clc/lib/generic/math/clc_nan.inc diff --git a/libclc/clc/include/clc/math/clc_nan.h b/libclc/clc/include/clc/math/clc_nan.h new file mode 100644 index 0000000000000..cfea9efa23bf4 --- /dev/null +++ b/libclc/clc/include/clc/math/clc_nan.h @@ -0,0 +1,12 @@ +#ifndef __CLC_MATH_CLC_NAN_H__ +#define __CLC_MATH_CLC_NAN_H__ + +#define __CLC_FUNCTION __clc_nan +#define __CLC_BODY + +#include + +#undef __CLC_BODY +#undef __CLC_FUNCTION + +#endif // __CLC_MATH_CLC_NAN_H__ diff --git a/libclc/clc/include/clc/math/clc_nan.inc b/libclc/clc/include/clc/math/clc_nan.inc new file mode 100644 index 0000000000000..7972d6c02c830 --- /dev/null +++ b/libclc/clc/include/clc/math/clc_nan.inc @@ -0,0 +1 @@ +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_nan(__CLC_U_GENTYPE code); diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES index 0ab563df6a274..54b0cd23f1650 100644 --- a/libclc/clc/lib/generic/SOURCES +++ b/libclc/clc/lib/generic/SOURCES @@ -25,6 +25,7 @@ math/clc_floor.cl math/clc_frexp.cl math/clc_mad.cl math/clc_modf.cl +math/clc_nan.cl math/clc_nextafter.cl math/clc_rint.cl math/clc_sw_fma.cl diff --git a/libclc/clc/lib/generic/math/clc_nan.cl b/libclc/clc/lib/generic/math/clc_nan.cl new file mode 100644 index 0000000000000..69501b886f606 --- /dev/null +++ b/libclc/clc/lib/generic/math/clc_nan.cl @@ -0,0 +1,5 @@ +#include +#include + +#define __CLC_BODY +#include diff --git a/libclc/clc/lib/generic/math/clc_nan.inc b/libclc/clc/lib/generic/math/clc_nan.inc new file mode 100644 index 0000000000000..7125af6f82910 --- /dev/null +++ b/libclc/clc/lib/generic/math/clc_nan.inc @@ -0,0 +1,15 @@ +#if __CLC_FPSIZE == 64 +#define NAN_MASK 0x7ff0000000000000ul +#elif __CLC_FPSIZE == 32 +#define NAN_MASK 0x7fc00000 +#elif __CLC_FPSIZE == 16 +#define NAN_MASK 0x7e00 +#endif + +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_nan(__CLC_U_GENTYPE code) { + const __CLC_U_GENTYPE mask = NAN_MASK; + const __CLC_U_GENTYPE res = code | mask; + return __CLC_AS_GENTYPE(res); +} + +#undef NAN_MASK diff --git a/libclc/generic/lib/math/nan.cl b/libclc/generic/lib/math/nan.cl index 5ec60d4521fc0..048bf59103d68 100644 --- a/libclc/generic/lib/math/nan.cl +++ b/libclc/generic/lib/math/nan.cl @@ -1,6 +1,5 @@ -#include -#include +#include +#include -#define __OPENCL_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE) #define __CLC_BODY #include diff --git a/libclc/generic/lib/math/nan.inc b/libclc/generic/lib/math/nan.inc index ded7f45072a93..0d04c0eb41537 100644 --- a/libclc/generic/lib/math/nan.inc +++ b/libclc/generic/lib/math/nan.inc @@ -1,15 +1,3 @@ -#if __CLC_FPSIZE == 64 -#define NAN_MASK 0x7ff0000000000000ul -#elif __CLC_FPSIZE == 32 -#define NAN_MASK 0x7fc00000 -#elif __CLC_FPSIZE == 16 -#define NAN_MASK 0x7e00 -#endif - _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_U_GENTYPE code) { - const __CLC_U_GENTYPE mask = NAN_MASK; - const __CLC_U_GENTYPE res = code | mask; - return __OPENCL_AS_GENTYPE(res); + return __clc_nan(code); } - -#undef NAN_MASK