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/7] [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/7] 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/7] 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/7] 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"

>From 94fbe38cc4b7dd1ee6aded740c2a8aff3e1e6343 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Tue, 26 May 2026 12:38:54 +0200
Subject: [PATCH 5/7] remove duplicate math/fma.cl

---
 libclc/opencl/lib/spirv/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libclc/opencl/lib/spirv/CMakeLists.txt 
b/libclc/opencl/lib/spirv/CMakeLists.txt
index 96fe7ab229678..6e9e28e59caa1 100644
--- a/libclc/opencl/lib/spirv/CMakeLists.txt
+++ b/libclc/opencl/lib/spirv/CMakeLists.txt
@@ -50,7 +50,6 @@ 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

>From 7196d52498f22f11f807f6b2b066fb5a8f943fb1 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Wed, 27 May 2026 00:42:17 +0200
Subject: [PATCH 6/7] SPIRV: use sw_fma in float fma

---
 libclc/clc/include/clc/math/clc_fma.h  |  2 ++
 libclc/clc/lib/generic/math/clc_fma.cl |  2 --
 libclc/clc/lib/spirv/CMakeLists.txt    |  1 +
 libclc/clc/lib/spirv/math/clc_fma.cl   | 29 ++++++++++++++++++++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 libclc/clc/lib/spirv/math/clc_fma.cl

diff --git a/libclc/clc/include/clc/math/clc_fma.h 
b/libclc/clc/include/clc/math/clc_fma.h
index e8aad41e021b4..5cb775bb6408a 100644
--- a/libclc/clc/include/clc/math/clc_fma.h
+++ b/libclc/clc/include/clc/math/clc_fma.h
@@ -9,6 +9,8 @@
 #ifndef __CLC_MATH_CLC_FMA_H__
 #define __CLC_MATH_CLC_FMA_H__
 
+#include "clc/internal/clc.h"
+
 #define __CLC_FUNCTION __clc_fma
 #define __CLC_BODY "clc/shared/ternary_decl.inc"
 
diff --git a/libclc/clc/lib/generic/math/clc_fma.cl 
b/libclc/clc/lib/generic/math/clc_fma.cl
index 2ac63927623dd..52a9ec844d60b 100644
--- a/libclc/clc/lib/generic/math/clc_fma.cl
+++ b/libclc/clc/lib/generic/math/clc_fma.cl
@@ -6,9 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#include "clc/internal/clc.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
diff --git a/libclc/clc/lib/spirv/CMakeLists.txt 
b/libclc/clc/lib/spirv/CMakeLists.txt
index 0e8abc2ba38d0..edcfc8e2404e9 100644
--- a/libclc/clc/lib/spirv/CMakeLists.txt
+++ b/libclc/clc/lib/spirv/CMakeLists.txt
@@ -3,6 +3,7 @@ if(LIBCLC_TARGET_OS AND EXISTS 
${CMAKE_CURRENT_SOURCE_DIR}/${LIBCLC_TARGET_OS})
 endif()
 
 libclc_add_sources(${LIBCLC_CLC_TARGET} FILES
+  math/clc_fma.cl
   math/clc_fmax.cl
   math/clc_fmin.cl
   math/clc_sw_fma.cl
diff --git a/libclc/clc/lib/spirv/math/clc_fma.cl 
b/libclc/clc/lib/spirv/math/clc_fma.cl
new file mode 100644
index 0000000000000..bb5d282b873ce
--- /dev/null
+++ b/libclc/clc/lib/spirv/math/clc_fma.cl
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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"
+#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"
+
+#undef __CLC_IMPL_FUNCTION
+#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma
+
+#define __CLC_FLOAT_ONLY
+#define __CLC_BODY "clc/shared/ternary_def.inc"
+#include "clc/math/gentype.inc"

>From df37c6250728f7d5855d5ecbe8cac5f03140a159 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Thu, 28 May 2026 02:53:02 +0200
Subject: [PATCH 7/7] add back __clc_runtime_has_hw_fma32 for mesa

---
 .../clc/include/clc/internal/math/clc_sw_fma.h  |  2 ++
 libclc/clc/include/clc/math/math.h              |  7 +++++++
 libclc/clc/lib/spirv/CMakeLists.txt             |  1 +
 libclc/clc/lib/spirv/math/clc_fma.cl            | 17 +----------------
 libclc/clc/lib/spirv/math/clc_fma.inc           | 16 ++++++++++++++++
 .../lib/spirv/math/clc_runtime_has_hw_fma32.cl  | 11 +++++++++++
 libclc/opencl/lib/generic/math/fma.cl           |  1 -
 libclc/opencl/lib/spirv/math/fma.cl             |  3 +--
 8 files changed, 39 insertions(+), 19 deletions(-)
 create mode 100644 libclc/clc/lib/spirv/math/clc_fma.inc
 create mode 100644 libclc/clc/lib/spirv/math/clc_runtime_has_hw_fma32.cl

diff --git a/libclc/clc/include/clc/internal/math/clc_sw_fma.h 
b/libclc/clc/include/clc/internal/math/clc_sw_fma.h
index 55718f26b0376..763a5cd97499f 100644
--- a/libclc/clc/include/clc/internal/math/clc_sw_fma.h
+++ b/libclc/clc/include/clc/internal/math/clc_sw_fma.h
@@ -9,6 +9,8 @@
 #ifndef __CLC_INTERNAL_MATH_CLC_SW_FMA_H__
 #define __CLC_INTERNAL_MATH_CLC_SW_FMA_H__
 
+#include "clc/internal/clc.h"
+
 #define __CLC_FUNCTION __clc_sw_fma
 #define __CLC_FLOAT_ONLY
 #define __CLC_BODY "clc/shared/ternary_decl.inc"
diff --git a/libclc/clc/include/clc/math/math.h 
b/libclc/clc/include/clc/math/math.h
index 950e8055c98c9..f9aa6e41c16af 100644
--- a/libclc/clc/include/clc/math/math.h
+++ b/libclc/clc/include/clc/math/math.h
@@ -44,6 +44,13 @@
 #define __CLC_FAST_FMA_F64 0
 #endif
 
+#ifdef CLC_SPIRV
+bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void);
+#define __CLC_HAVE_HW_FMA32() __clc_runtime_has_hw_fma32()
+#else
+#define __CLC_HAVE_HW_FMA32() (1)
+#endif
+
 #define HAVE_BITALIGN() (0)
 
 #define MATH_DIVIDE(X, Y) ((X) / (Y))
diff --git a/libclc/clc/lib/spirv/CMakeLists.txt 
b/libclc/clc/lib/spirv/CMakeLists.txt
index edcfc8e2404e9..11d39189891ce 100644
--- a/libclc/clc/lib/spirv/CMakeLists.txt
+++ b/libclc/clc/lib/spirv/CMakeLists.txt
@@ -6,6 +6,7 @@ libclc_add_sources(${LIBCLC_CLC_TARGET} FILES
   math/clc_fma.cl
   math/clc_fmax.cl
   math/clc_fmin.cl
+  math/clc_runtime_has_hw_fma32.cl
   math/clc_sw_fma.cl
   subnormal_config.cl
 )
diff --git a/libclc/clc/lib/spirv/math/clc_fma.cl 
b/libclc/clc/lib/spirv/math/clc_fma.cl
index bb5d282b873ce..22d04323e5c7a 100644
--- a/libclc/clc/lib/spirv/math/clc_fma.cl
+++ b/libclc/clc/lib/spirv/math/clc_fma.cl
@@ -10,20 +10,5 @@
 #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"
-
-#undef __CLC_IMPL_FUNCTION
-#define __CLC_IMPL_FUNCTION(x) __clc_sw_fma
-
-#define __CLC_FLOAT_ONLY
-#define __CLC_BODY "clc/shared/ternary_def.inc"
+#define __CLC_BODY "clc_fma.inc"
 #include "clc/math/gentype.inc"
diff --git a/libclc/clc/lib/spirv/math/clc_fma.inc 
b/libclc/clc/lib/spirv/math/clc_fma.inc
new file mode 100644
index 0000000000000..b23b6433d2922
--- /dev/null
+++ b/libclc/clc/lib/spirv/math/clc_fma.inc
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_fma(__CLC_GENTYPE a, __CLC_GENTYPE 
b,
+                                               __CLC_GENTYPE c) {
+#if __CLC_FPSIZE == 32
+  if (!__CLC_HAVE_HW_FMA32())
+    return __clc_sw_fma(a, b, c);
+#endif
+  return __builtin_elementwise_fma(a, b, c);
+}
diff --git a/libclc/clc/lib/spirv/math/clc_runtime_has_hw_fma32.cl 
b/libclc/clc/lib/spirv/math/clc_runtime_has_hw_fma32.cl
new file mode 100644
index 0000000000000..4b223a4d379b2
--- /dev/null
+++ b/libclc/clc/lib/spirv/math/clc_runtime_has_hw_fma32.cl
@@ -0,0 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void) {
+  return false;
+}
diff --git a/libclc/opencl/lib/generic/math/fma.cl 
b/libclc/opencl/lib/generic/math/fma.cl
index efb3c1ae4193d..281ee83b9af69 100644
--- a/libclc/opencl/lib/generic/math/fma.cl
+++ b/libclc/opencl/lib/generic/math/fma.cl
@@ -7,7 +7,6 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clc/math/clc_fma.h"
-#include "clc/math/math.h"
 
 #define __CLC_FUNCTION fma
 #define __CLC_BODY "clc/shared/ternary_def.inc"
diff --git a/libclc/opencl/lib/spirv/math/fma.cl 
b/libclc/opencl/lib/spirv/math/fma.cl
index ab955a9a38ac6..b5a44af97c4d9 100644
--- a/libclc/opencl/lib/spirv/math/fma.cl
+++ b/libclc/opencl/lib/spirv/math/fma.cl
@@ -6,11 +6,10 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#include "clc/internal/math/clc_sw_fma.h"
+#include "clc/math/clc_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

Reply via email to