[libclc] [libclc] Use float sw_fma for spirv*-mesa-mesa3d targets (PR #199626)
Wenju He via cfe-commits
cfe-commits at lists.llvm.org
Tue May 26 02:48:21 PDT 2026
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 <wenju.he at intel.com>
Date: Tue, 26 May 2026 10:18:43 +0200
Subject: [PATCH 1/3] [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 <wenju.he at intel.com>
Date: Tue, 26 May 2026 10:31:09 +0200
Subject: [PATCH 2/3] 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 <wenju.he at intel.com>
Date: Tue, 26 May 2026 11:48:04 +0200
Subject: [PATCH 3/3] 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
More information about the cfe-commits
mailing list