[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)
https://github.com/frasercrmck closed https://github.com/llvm/llvm-project/pull/140871 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/140871 >From 3e070b23eea6ac3a9514d0cd5c9785e220d5f5e1 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 21 May 2025 10:39:12 +0100 Subject: [PATCH 1/3] [libclc] Move all remquo address spaces to CLC library Previously the OpenCL address space overloads of remquo would call into the one and only 'private' CLC remquo. This was an outlier compared with the other pointer-argumented maths builtins. This commit moves the definitions of all address space overloads to the CLC library to give more control over each address space to CLC implementers. There are some minor changes to the generated bytecode but it's simply moving IR instructions around. --- libclc/clc/include/clc/math/clc_remquo.h | 4 +- libclc/clc/include/clc/math/remquo_decl.inc | 8 +- libclc/clc/lib/generic/math/clc_remquo.cl | 266 + libclc/clc/lib/generic/math/clc_remquo.inc| 271 ++ .../opencl/include/clc/opencl/math/remquo.h | 12 - libclc/opencl/lib/generic/math/remquo.cl | 12 - libclc/opencl/lib/generic/math/remquo.inc | 17 +- 7 files changed, 300 insertions(+), 290 deletions(-) create mode 100644 libclc/clc/lib/generic/math/clc_remquo.inc diff --git a/libclc/clc/include/clc/math/clc_remquo.h b/libclc/clc/include/clc/math/clc_remquo.h index 5dea818013c68..48a8844a6e384 100644 --- a/libclc/clc/include/clc/math/clc_remquo.h +++ b/libclc/clc/include/clc/math/clc_remquo.h @@ -10,12 +10,10 @@ #define __CLC_MATH_CLC_REMQUO_H__ #define __CLC_FUNCTION __clc_remquo - #define __CLC_BODY -#define __CLC_ADDRESS_SPACE private + #include -#undef __CLC_ADDRESS_SPACE #undef __CLC_FUNCTION #endif // __CLC_MATH_CLC_REMQUO_H__ diff --git a/libclc/clc/include/clc/math/remquo_decl.inc b/libclc/clc/include/clc/math/remquo_decl.inc index ecd703042a964..0b650795909b0 100644 --- a/libclc/clc/include/clc/math/remquo_decl.inc +++ b/libclc/clc/include/clc/math/remquo_decl.inc @@ -7,4 +7,10 @@ //===--===// _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( -__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q); +__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q); + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( +__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q); + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( +__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q); diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl b/libclc/clc/lib/generic/math/clc_remquo.cl index 9fa94c1c290b8..2f3b6f0339e17 100644 --- a/libclc/clc/lib/generic/math/clc_remquo.cl +++ b/libclc/clc/lib/generic/math/clc_remquo.cl @@ -18,262 +18,14 @@ #include #include -_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y, - __private int *quo) { - x = __clc_flush_denormal_if_not_supported(x); - y = __clc_flush_denormal_if_not_supported(y); - int ux = __clc_as_int(x); - int ax = ux & EXSIGNBIT_SP32; - float xa = __clc_as_float(ax); - int sx = ux ^ ax; - int ex = ax >> EXPSHIFTBITS_SP32; +#define __CLC_ADDRESS_SPACE private +#include +#undef __CLC_ADDRESS_SPACE - int uy = __clc_as_int(y); - int ay = uy & EXSIGNBIT_SP32; - float ya = __clc_as_float(ay); - int sy = uy ^ ay; - int ey = ay >> EXPSHIFTBITS_SP32; +#define __CLC_ADDRESS_SPACE global +#include +#undef __CLC_ADDRESS_SPACE - float xr = __clc_as_float(0x3f80 | (ax & 0x007f)); - float yr = __clc_as_float(0x3f80 | (ay & 0x007f)); - int c; - int k = ex - ey; - - uint q = 0; - - while (k > 0) { -c = xr >= yr; -q = (q << 1) | c; -xr -= c ? yr : 0.0f; -xr += xr; ---k; - } - - c = xr > yr; - q = (q << 1) | c; - xr -= c ? yr : 0.0f; - - int lt = ex < ey; - - q = lt ? 0 : q; - xr = lt ? xa : xr; - yr = lt ? ya : yr; - - c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1)); - xr -= c ? yr : 0.0f; - q += c; - - float s = __clc_as_float(ey << EXPSHIFTBITS_SP32); - xr *= lt ? 1.0f : s; - - int qsgn = sx == sy ? 1 : -1; - int quot = (q & 0x7f) * qsgn; - - c = ax == ay; - quot = c ? qsgn : quot; - xr = c ? 0.0f : xr; - - xr = __clc_as_float(sx ^ __clc_as_int(xr)); - - c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 | - ay == 0; - quot = c ? 0 : quot; - xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr; - - *quo = quot; - - return xr; -} -// remquo signature is special, we don't have macro for this -#define __VEC_REMQUO(TYPE, VEC_SIZE, HALF_VEC_SIZE) \ - _CLC_DEF _CLC_OVERLOAD TYPE##VEC_SIZE __clc_remquo( \ - TYPE##VEC_SIZE x, TYPE##VEC_SIZE y, __private int##VEC_SIZE *quo) { \ -int##HALF_VEC_SIZE lo, hi; \ -TYPE##VEC_SIZE ret;
[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)
https://github.com/arsenm approved this pull request. https://github.com/llvm/llvm-project/pull/140871 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/140871 >From 3e070b23eea6ac3a9514d0cd5c9785e220d5f5e1 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 21 May 2025 10:39:12 +0100 Subject: [PATCH 1/2] [libclc] Move all remquo address spaces to CLC library Previously the OpenCL address space overloads of remquo would call into the one and only 'private' CLC remquo. This was an outlier compared with the other pointer-argumented maths builtins. This commit moves the definitions of all address space overloads to the CLC library to give more control over each address space to CLC implementers. There are some minor changes to the generated bytecode but it's simply moving IR instructions around. --- libclc/clc/include/clc/math/clc_remquo.h | 4 +- libclc/clc/include/clc/math/remquo_decl.inc | 8 +- libclc/clc/lib/generic/math/clc_remquo.cl | 266 + libclc/clc/lib/generic/math/clc_remquo.inc| 271 ++ .../opencl/include/clc/opencl/math/remquo.h | 12 - libclc/opencl/lib/generic/math/remquo.cl | 12 - libclc/opencl/lib/generic/math/remquo.inc | 17 +- 7 files changed, 300 insertions(+), 290 deletions(-) create mode 100644 libclc/clc/lib/generic/math/clc_remquo.inc diff --git a/libclc/clc/include/clc/math/clc_remquo.h b/libclc/clc/include/clc/math/clc_remquo.h index 5dea818013c68..48a8844a6e384 100644 --- a/libclc/clc/include/clc/math/clc_remquo.h +++ b/libclc/clc/include/clc/math/clc_remquo.h @@ -10,12 +10,10 @@ #define __CLC_MATH_CLC_REMQUO_H__ #define __CLC_FUNCTION __clc_remquo - #define __CLC_BODY -#define __CLC_ADDRESS_SPACE private + #include -#undef __CLC_ADDRESS_SPACE #undef __CLC_FUNCTION #endif // __CLC_MATH_CLC_REMQUO_H__ diff --git a/libclc/clc/include/clc/math/remquo_decl.inc b/libclc/clc/include/clc/math/remquo_decl.inc index ecd703042a964..0b650795909b0 100644 --- a/libclc/clc/include/clc/math/remquo_decl.inc +++ b/libclc/clc/include/clc/math/remquo_decl.inc @@ -7,4 +7,10 @@ //===--===// _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( -__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q); +__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q); + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( +__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q); + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( +__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q); diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl b/libclc/clc/lib/generic/math/clc_remquo.cl index 9fa94c1c290b8..2f3b6f0339e17 100644 --- a/libclc/clc/lib/generic/math/clc_remquo.cl +++ b/libclc/clc/lib/generic/math/clc_remquo.cl @@ -18,262 +18,14 @@ #include #include -_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y, - __private int *quo) { - x = __clc_flush_denormal_if_not_supported(x); - y = __clc_flush_denormal_if_not_supported(y); - int ux = __clc_as_int(x); - int ax = ux & EXSIGNBIT_SP32; - float xa = __clc_as_float(ax); - int sx = ux ^ ax; - int ex = ax >> EXPSHIFTBITS_SP32; +#define __CLC_ADDRESS_SPACE private +#include +#undef __CLC_ADDRESS_SPACE - int uy = __clc_as_int(y); - int ay = uy & EXSIGNBIT_SP32; - float ya = __clc_as_float(ay); - int sy = uy ^ ay; - int ey = ay >> EXPSHIFTBITS_SP32; +#define __CLC_ADDRESS_SPACE global +#include +#undef __CLC_ADDRESS_SPACE - float xr = __clc_as_float(0x3f80 | (ax & 0x007f)); - float yr = __clc_as_float(0x3f80 | (ay & 0x007f)); - int c; - int k = ex - ey; - - uint q = 0; - - while (k > 0) { -c = xr >= yr; -q = (q << 1) | c; -xr -= c ? yr : 0.0f; -xr += xr; ---k; - } - - c = xr > yr; - q = (q << 1) | c; - xr -= c ? yr : 0.0f; - - int lt = ex < ey; - - q = lt ? 0 : q; - xr = lt ? xa : xr; - yr = lt ? ya : yr; - - c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1)); - xr -= c ? yr : 0.0f; - q += c; - - float s = __clc_as_float(ey << EXPSHIFTBITS_SP32); - xr *= lt ? 1.0f : s; - - int qsgn = sx == sy ? 1 : -1; - int quot = (q & 0x7f) * qsgn; - - c = ax == ay; - quot = c ? qsgn : quot; - xr = c ? 0.0f : xr; - - xr = __clc_as_float(sx ^ __clc_as_int(xr)); - - c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 | - ay == 0; - quot = c ? 0 : quot; - xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr; - - *quo = quot; - - return xr; -} -// remquo signature is special, we don't have macro for this -#define __VEC_REMQUO(TYPE, VEC_SIZE, HALF_VEC_SIZE) \ - _CLC_DEF _CLC_OVERLOAD TYPE##VEC_SIZE __clc_remquo( \ - TYPE##VEC_SIZE x, TYPE##VEC_SIZE y, __private int##VEC_SIZE *quo) { \ -int##HALF_VEC_SIZE lo, hi; \ -TYPE##VEC_SIZE ret;
[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions inc,cl,h -- libclc/clc/lib/generic/math/clc_remquo.inc libclc/clc/include/clc/math/clc_remquo.h libclc/clc/include/clc/math/remquo_decl.inc libclc/clc/lib/generic/math/clc_remquo.cl libclc/opencl/include/clc/opencl/math/remquo.h libclc/opencl/lib/generic/math/remquo.cl libclc/opencl/lib/generic/math/remquo.inc `` View the diff from clang-format here. ``diff diff --git a/libclc/clc/include/clc/math/remquo_decl.inc b/libclc/clc/include/clc/math/remquo_decl.inc index 0b6507959..7f2af2915 100644 --- a/libclc/clc/include/clc/math/remquo_decl.inc +++ b/libclc/clc/include/clc/math/remquo_decl.inc @@ -6,11 +6,14 @@ // //===--===// -_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( -__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q); +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x, + __CLC_GENTYPE y, + private __CLC_INTN *q); -_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( -__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q); +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x, + __CLC_GENTYPE y, + global __CLC_INTN *q); -_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( -__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q); +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x, + __CLC_GENTYPE y, + local __CLC_INTN *q); diff --git a/libclc/clc/lib/generic/math/clc_remquo.inc b/libclc/clc/lib/generic/math/clc_remquo.inc index 7563bae24..28f51c4e2 100644 --- a/libclc/clc/lib/generic/math/clc_remquo.inc +++ b/libclc/clc/lib/generic/math/clc_remquo.inc @@ -218,7 +218,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remquo(double x, double y, quo = c ? 0 : quo; ret = c ? x : ret; - c &= (yexp<1023 & 2.0 * dx> dy) | (dx > 0.5 * dy); + c &= (yexp < 1023 & 2.0 * dx > dy) | (dx > 0.5 * dy); quo = c ? qsgn : quo; // we could use a conversion here instead since qsgn = +-1 p = qsgn == 1 ? -1.0 : 1.0; `` https://github.com/llvm/llvm-project/pull/140871 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)
https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/140871 Previously the OpenCL address space overloads of remquo would call into the one and only 'private' CLC remquo. This was an outlier compared with the other pointer-argumented maths builtins. This commit moves the definitions of all address space overloads to the CLC library to give more control over each address space to CLC implementers. There are some minor changes to the generated bytecode but it's simply moving IR instructions around. >From 3e070b23eea6ac3a9514d0cd5c9785e220d5f5e1 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 21 May 2025 10:39:12 +0100 Subject: [PATCH] [libclc] Move all remquo address spaces to CLC library Previously the OpenCL address space overloads of remquo would call into the one and only 'private' CLC remquo. This was an outlier compared with the other pointer-argumented maths builtins. This commit moves the definitions of all address space overloads to the CLC library to give more control over each address space to CLC implementers. There are some minor changes to the generated bytecode but it's simply moving IR instructions around. --- libclc/clc/include/clc/math/clc_remquo.h | 4 +- libclc/clc/include/clc/math/remquo_decl.inc | 8 +- libclc/clc/lib/generic/math/clc_remquo.cl | 266 + libclc/clc/lib/generic/math/clc_remquo.inc| 271 ++ .../opencl/include/clc/opencl/math/remquo.h | 12 - libclc/opencl/lib/generic/math/remquo.cl | 12 - libclc/opencl/lib/generic/math/remquo.inc | 17 +- 7 files changed, 300 insertions(+), 290 deletions(-) create mode 100644 libclc/clc/lib/generic/math/clc_remquo.inc diff --git a/libclc/clc/include/clc/math/clc_remquo.h b/libclc/clc/include/clc/math/clc_remquo.h index 5dea818013c68..48a8844a6e384 100644 --- a/libclc/clc/include/clc/math/clc_remquo.h +++ b/libclc/clc/include/clc/math/clc_remquo.h @@ -10,12 +10,10 @@ #define __CLC_MATH_CLC_REMQUO_H__ #define __CLC_FUNCTION __clc_remquo - #define __CLC_BODY -#define __CLC_ADDRESS_SPACE private + #include -#undef __CLC_ADDRESS_SPACE #undef __CLC_FUNCTION #endif // __CLC_MATH_CLC_REMQUO_H__ diff --git a/libclc/clc/include/clc/math/remquo_decl.inc b/libclc/clc/include/clc/math/remquo_decl.inc index ecd703042a964..0b650795909b0 100644 --- a/libclc/clc/include/clc/math/remquo_decl.inc +++ b/libclc/clc/include/clc/math/remquo_decl.inc @@ -7,4 +7,10 @@ //===--===// _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( -__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q); +__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q); + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( +__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q); + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION( +__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q); diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl b/libclc/clc/lib/generic/math/clc_remquo.cl index 9fa94c1c290b8..2f3b6f0339e17 100644 --- a/libclc/clc/lib/generic/math/clc_remquo.cl +++ b/libclc/clc/lib/generic/math/clc_remquo.cl @@ -18,262 +18,14 @@ #include #include -_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y, - __private int *quo) { - x = __clc_flush_denormal_if_not_supported(x); - y = __clc_flush_denormal_if_not_supported(y); - int ux = __clc_as_int(x); - int ax = ux & EXSIGNBIT_SP32; - float xa = __clc_as_float(ax); - int sx = ux ^ ax; - int ex = ax >> EXPSHIFTBITS_SP32; +#define __CLC_ADDRESS_SPACE private +#include +#undef __CLC_ADDRESS_SPACE - int uy = __clc_as_int(y); - int ay = uy & EXSIGNBIT_SP32; - float ya = __clc_as_float(ay); - int sy = uy ^ ay; - int ey = ay >> EXPSHIFTBITS_SP32; +#define __CLC_ADDRESS_SPACE global +#include +#undef __CLC_ADDRESS_SPACE - float xr = __clc_as_float(0x3f80 | (ax & 0x007f)); - float yr = __clc_as_float(0x3f80 | (ay & 0x007f)); - int c; - int k = ex - ey; - - uint q = 0; - - while (k > 0) { -c = xr >= yr; -q = (q << 1) | c; -xr -= c ? yr : 0.0f; -xr += xr; ---k; - } - - c = xr > yr; - q = (q << 1) | c; - xr -= c ? yr : 0.0f; - - int lt = ex < ey; - - q = lt ? 0 : q; - xr = lt ? xa : xr; - yr = lt ? ya : yr; - - c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1)); - xr -= c ? yr : 0.0f; - q += c; - - float s = __clc_as_float(ey << EXPSHIFTBITS_SP32); - xr *= lt ? 1.0f : s; - - int qsgn = sx == sy ? 1 : -1; - int quot = (q & 0x7f) * qsgn; - - c = ax == ay; - quot = c ? qsgn : quot; - xr = c ? 0.0f : xr; - - xr = __clc_as_float(sx ^ __clc_as_int(xr)); - - c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 | - ay == 0; - quot = c ? 0 : quot; - xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr; - - *quo = quot; - - return xr; -} -//