https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/199626
>From 63c9b2f723c60612b1124e10611340957b404fe5 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Tue, 26 May 2026 10:18:43 +0200 Subject: [PATCH 1/4] [libclc] Use float sw_fma for spirv*-mesa-mesa3d targets This partially reverts 39f3d72b72fd, which changes almost all targets to use __builtin_elementwise_fma. The same revert was done for clspv in 1d719edd9935. --- libclc/clc/lib/generic/CMakeLists.txt | 1 + libclc/clc/lib/generic/math/clc_fma.cl | 15 +++++++++++++++ .../{spirv/vulkan => generic}/math/clc_sw_fma.cl | 4 ++++ libclc/clc/lib/spirv/vulkan/CMakeLists.txt | 1 - libclc/opencl/lib/spirv/vulkan/CMakeLists.txt | 1 - libclc/opencl/lib/spirv/vulkan/math/fma.cl | 16 ---------------- 6 files changed, 20 insertions(+), 18 deletions(-) rename libclc/clc/lib/{spirv/vulkan => generic}/math/clc_sw_fma.cl (99%) delete mode 100644 libclc/opencl/lib/spirv/vulkan/math/fma.cl diff --git a/libclc/clc/lib/generic/CMakeLists.txt b/libclc/clc/lib/generic/CMakeLists.txt index 40261545fce91..ec6effecfa7da 100644 --- a/libclc/clc/lib/generic/CMakeLists.txt +++ b/libclc/clc/lib/generic/CMakeLists.txt @@ -163,6 +163,7 @@ libclc_add_sources(${LIBCLC_CLC_TARGET} FILES math/clc_sqrt.cl math/clc_sqrt_cr.cl math/clc_sqrt_fast.cl + math/clc_sw_fma.cl math/clc_tables.cl math/clc_tan.cl math/clc_tanh.cl diff --git a/libclc/clc/lib/generic/math/clc_fma.cl b/libclc/clc/lib/generic/math/clc_fma.cl index 2ac63927623dd..f44fc97fe35ce 100644 --- a/libclc/clc/lib/generic/math/clc_fma.cl +++ b/libclc/clc/lib/generic/math/clc_fma.cl @@ -9,9 +9,24 @@ #include "clc/internal/clc.h" #include "clc/math/clc_fma.h" #include "clc/math/math.h" +#include "clc/internal/math/clc_sw_fma.h" #define __CLC_FUNCTION __clc_fma #define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_fma + +#define __CLC_DOUBLE_ONLY #define __CLC_BODY "clc/shared/ternary_def.inc" +#include "clc/math/gentype.inc" +#define __CLC_HALF_ONLY +#define __CLC_BODY "clc/shared/ternary_def.inc" +#include "clc/math/gentype.inc" + +#ifdef __SPIRV__ +#undef __CLC_IMPL_FUNCTION +#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma +#endif + +#define __CLC_FLOAT_ONLY +#define __CLC_BODY "clc/shared/ternary_def.inc" #include "clc/math/gentype.inc" diff --git a/libclc/clc/lib/spirv/vulkan/math/clc_sw_fma.cl b/libclc/clc/lib/generic/math/clc_sw_fma.cl similarity index 99% rename from libclc/clc/lib/spirv/vulkan/math/clc_sw_fma.cl rename to libclc/clc/lib/generic/math/clc_sw_fma.cl index e73f53e6bcd76..adb0fc799d4da 100644 --- a/libclc/clc/lib/spirv/vulkan/math/clc_sw_fma.cl +++ b/libclc/clc/lib/generic/math/clc_sw_fma.cl @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#ifdef __SPIRV__ + // This version is derived from the generic fma software implementation // (__clc_sw_fma), but avoids the use of ulong in favor of uint2. The logic has // been updated as appropriate. @@ -273,3 +275,5 @@ _CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) { #define __CLC_FUNCTION __clc_sw_fma #define __CLC_BODY "clc/shared/ternary_def_scalarize.inc" #include "clc/math/gentype.inc" + +#endif // __SPIRV__ diff --git a/libclc/clc/lib/spirv/vulkan/CMakeLists.txt b/libclc/clc/lib/spirv/vulkan/CMakeLists.txt index 499ce274a500c..fe94346ed1530 100644 --- a/libclc/clc/lib/spirv/vulkan/CMakeLists.txt +++ b/libclc/clc/lib/spirv/vulkan/CMakeLists.txt @@ -1,4 +1,3 @@ libclc_add_sources(${LIBCLC_CLC_TARGET} FILES integer/clc_mul_hi.cl - math/clc_sw_fma.cl ) diff --git a/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt b/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt index d04959027f0de..723d1aefa0e40 100644 --- a/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt +++ b/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt @@ -5,7 +5,6 @@ libclc_add_sources(${LIBCLC_OPENCL_TARGET} FILES conversion/convert_float2int.cl conversion/convert_int2float.cl conversion/convert_integer.cl - math/fma.cl shared/vstore_half.cl ) diff --git a/libclc/opencl/lib/spirv/vulkan/math/fma.cl b/libclc/opencl/lib/spirv/vulkan/math/fma.cl deleted file mode 100644 index ab955a9a38ac6..0000000000000 --- a/libclc/opencl/lib/spirv/vulkan/math/fma.cl +++ /dev/null @@ -1,16 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "clc/internal/math/clc_sw_fma.h" - -#define __CLC_FLOAT_ONLY -#define __CLC_FUNCTION fma -#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma -#define __CLC_BODY "clc/shared/ternary_def.inc" - -#include "clc/math/gentype.inc" >From 758aa576d16f2c5595fb0127169619c9277d7ed5 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Tue, 26 May 2026 10:31:09 +0200 Subject: [PATCH 2/4] clang-format --- libclc/clc/lib/generic/math/clc_fma.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libclc/clc/lib/generic/math/clc_fma.cl b/libclc/clc/lib/generic/math/clc_fma.cl index f44fc97fe35ce..6d7ea232f3f8e 100644 --- a/libclc/clc/lib/generic/math/clc_fma.cl +++ b/libclc/clc/lib/generic/math/clc_fma.cl @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "clc/internal/clc.h" +#include "clc/internal/math/clc_sw_fma.h" #include "clc/math/clc_fma.h" #include "clc/math/math.h" -#include "clc/internal/math/clc_sw_fma.h" #define __CLC_FUNCTION __clc_fma #define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_fma >From e0e09049ae21440cc79ff5ef0f263e8e85375ec2 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Tue, 26 May 2026 11:48:04 +0200 Subject: [PATCH 3/4] add math/fma.cl to clspv/mesa target sources --- libclc/opencl/lib/spirv/CMakeLists.txt | 1 + libclc/opencl/lib/spirv/vulkan/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/libclc/opencl/lib/spirv/CMakeLists.txt b/libclc/opencl/lib/spirv/CMakeLists.txt index ea35940f60d70..53e92de020699 100644 --- a/libclc/opencl/lib/spirv/CMakeLists.txt +++ b/libclc/opencl/lib/spirv/CMakeLists.txt @@ -46,6 +46,7 @@ libclc_add_sources(${LIBCLC_OPENCL_TARGET} math/expm1.cl math/exp2.cl math/exp10.cl + math/fma.cl math/fmod.cl math/fract.cl math/frexp.cl diff --git a/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt b/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt index 723d1aefa0e40..4b0773bba6088 100644 --- a/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt +++ b/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt @@ -35,6 +35,7 @@ libclc_add_sources(${LIBCLC_OPENCL_TARGET} math/exp10.cl math/expm1.cl math/fdim.cl + math/fma.cl math/fmod.cl math/fract.cl math/frexp.cl >From 90f4bda4c5898fb4cf3e9657370f1feaeca873b8 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Tue, 26 May 2026 12:26:32 +0200 Subject: [PATCH 4/4] only enable float type fma for clspv/mesa --- libclc/clc/lib/generic/CMakeLists.txt | 1 - libclc/clc/lib/generic/math/clc_fma.cl | 15 --------------- libclc/clc/lib/spirv/CMakeLists.txt | 1 + .../lib/{generic => spirv}/math/clc_sw_fma.cl | 4 ---- libclc/opencl/lib/spirv/CMakeLists.txt | 4 ++++ libclc/opencl/lib/spirv/math/fma.cl | 16 ++++++++++++++++ libclc/opencl/lib/spirv/vulkan/CMakeLists.txt | 2 +- libclc/opencl/lib/spirv/vulkan/math/fma.cl | 16 ++++++++++++++++ 8 files changed, 38 insertions(+), 21 deletions(-) rename libclc/clc/lib/{generic => spirv}/math/clc_sw_fma.cl (99%) create mode 100644 libclc/opencl/lib/spirv/math/fma.cl create mode 100644 libclc/opencl/lib/spirv/vulkan/math/fma.cl diff --git a/libclc/clc/lib/generic/CMakeLists.txt b/libclc/clc/lib/generic/CMakeLists.txt index ec6effecfa7da..40261545fce91 100644 --- a/libclc/clc/lib/generic/CMakeLists.txt +++ b/libclc/clc/lib/generic/CMakeLists.txt @@ -163,7 +163,6 @@ libclc_add_sources(${LIBCLC_CLC_TARGET} FILES math/clc_sqrt.cl math/clc_sqrt_cr.cl math/clc_sqrt_fast.cl - math/clc_sw_fma.cl math/clc_tables.cl math/clc_tan.cl math/clc_tanh.cl diff --git a/libclc/clc/lib/generic/math/clc_fma.cl b/libclc/clc/lib/generic/math/clc_fma.cl index 6d7ea232f3f8e..2ac63927623dd 100644 --- a/libclc/clc/lib/generic/math/clc_fma.cl +++ b/libclc/clc/lib/generic/math/clc_fma.cl @@ -7,26 +7,11 @@ //===----------------------------------------------------------------------===// #include "clc/internal/clc.h" -#include "clc/internal/math/clc_sw_fma.h" #include "clc/math/clc_fma.h" #include "clc/math/math.h" #define __CLC_FUNCTION __clc_fma #define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_fma - -#define __CLC_DOUBLE_ONLY #define __CLC_BODY "clc/shared/ternary_def.inc" -#include "clc/math/gentype.inc" -#define __CLC_HALF_ONLY -#define __CLC_BODY "clc/shared/ternary_def.inc" -#include "clc/math/gentype.inc" - -#ifdef __SPIRV__ -#undef __CLC_IMPL_FUNCTION -#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma -#endif - -#define __CLC_FLOAT_ONLY -#define __CLC_BODY "clc/shared/ternary_def.inc" #include "clc/math/gentype.inc" diff --git a/libclc/clc/lib/spirv/CMakeLists.txt b/libclc/clc/lib/spirv/CMakeLists.txt index 5f361c95c4003..0e8abc2ba38d0 100644 --- a/libclc/clc/lib/spirv/CMakeLists.txt +++ b/libclc/clc/lib/spirv/CMakeLists.txt @@ -5,5 +5,6 @@ endif() libclc_add_sources(${LIBCLC_CLC_TARGET} FILES math/clc_fmax.cl math/clc_fmin.cl + math/clc_sw_fma.cl subnormal_config.cl ) diff --git a/libclc/clc/lib/generic/math/clc_sw_fma.cl b/libclc/clc/lib/spirv/math/clc_sw_fma.cl similarity index 99% rename from libclc/clc/lib/generic/math/clc_sw_fma.cl rename to libclc/clc/lib/spirv/math/clc_sw_fma.cl index adb0fc799d4da..e73f53e6bcd76 100644 --- a/libclc/clc/lib/generic/math/clc_sw_fma.cl +++ b/libclc/clc/lib/spirv/math/clc_sw_fma.cl @@ -6,8 +6,6 @@ // //===----------------------------------------------------------------------===// -#ifdef __SPIRV__ - // This version is derived from the generic fma software implementation // (__clc_sw_fma), but avoids the use of ulong in favor of uint2. The logic has // been updated as appropriate. @@ -275,5 +273,3 @@ _CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) { #define __CLC_FUNCTION __clc_sw_fma #define __CLC_BODY "clc/shared/ternary_def_scalarize.inc" #include "clc/math/gentype.inc" - -#endif // __SPIRV__ diff --git a/libclc/opencl/lib/spirv/CMakeLists.txt b/libclc/opencl/lib/spirv/CMakeLists.txt index 53e92de020699..96fe7ab229678 100644 --- a/libclc/opencl/lib/spirv/CMakeLists.txt +++ b/libclc/opencl/lib/spirv/CMakeLists.txt @@ -4,6 +4,10 @@ if(LIBCLC_TARGET_OS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBCLC_TARGET_OS}) endif() # Non-Vulkan SPIR-V uses a curated subset of generic builtins. +libclc_add_sources(${LIBCLC_OPENCL_TARGET} FILES + math/fma.cl +) + libclc_add_sources(${LIBCLC_OPENCL_TARGET} BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../generic FILES diff --git a/libclc/opencl/lib/spirv/math/fma.cl b/libclc/opencl/lib/spirv/math/fma.cl new file mode 100644 index 0000000000000..ab955a9a38ac6 --- /dev/null +++ b/libclc/opencl/lib/spirv/math/fma.cl @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "clc/internal/math/clc_sw_fma.h" + +#define __CLC_FLOAT_ONLY +#define __CLC_FUNCTION fma +#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma +#define __CLC_BODY "clc/shared/ternary_def.inc" + +#include "clc/math/gentype.inc" diff --git a/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt b/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt index 4b0773bba6088..d04959027f0de 100644 --- a/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt +++ b/libclc/opencl/lib/spirv/vulkan/CMakeLists.txt @@ -5,6 +5,7 @@ libclc_add_sources(${LIBCLC_OPENCL_TARGET} FILES conversion/convert_float2int.cl conversion/convert_int2float.cl conversion/convert_integer.cl + math/fma.cl shared/vstore_half.cl ) @@ -35,7 +36,6 @@ libclc_add_sources(${LIBCLC_OPENCL_TARGET} math/exp10.cl math/expm1.cl math/fdim.cl - math/fma.cl math/fmod.cl math/fract.cl math/frexp.cl diff --git a/libclc/opencl/lib/spirv/vulkan/math/fma.cl b/libclc/opencl/lib/spirv/vulkan/math/fma.cl new file mode 100644 index 0000000000000..ab955a9a38ac6 --- /dev/null +++ b/libclc/opencl/lib/spirv/vulkan/math/fma.cl @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "clc/internal/math/clc_sw_fma.h" + +#define __CLC_FLOAT_ONLY +#define __CLC_FUNCTION fma +#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma +#define __CLC_BODY "clc/shared/ternary_def.inc" + +#include "clc/math/gentype.inc" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
