[libclc] [libclc] Move __clc_(remainder|fmod|remquo) to the CLC library (PR #132054)

Fraser Cormack via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 08:41:51 PDT 2025


https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/132054

>From 1e16ff4926e47b6fd58761ea04ee0535d2112ae4 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Wed, 19 Mar 2025 14:52:09 +0000
Subject: [PATCH 1/3] [libclc] Move __clc_remainder to CLC library

It was already nominally in the CLC namespace; this commit just formally
moves it over.

Note that a fp16 version of __clc_remainder is now provided. It is
defined as forwarding on to the fp32 version. This makes a difference in
the OpenCL layer, where the fp16 remainder builtin will forward to the
fp16 __clc_remainder builtin, rather than directly forwarding onto the
fp32 __clc_remainder builtin.

No changes to the generated code for non-SPIR-V targets is observed.
---
 .../include/clc/math/binary_def_via_fp32.inc  | 13 +++++++++++
 libclc/clc/include/clc/math/clc_remainder.h   | 20 ++++++++++++++++
 libclc/clc/include/clc/math/gentype.inc       |  7 ++++--
 libclc/clc/lib/generic/SOURCES                |  1 +
 .../lib/generic}/math/clc_remainder.cl        | 23 +++++++++++++++----
 libclc/clspv/lib/SOURCES                      |  1 -
 libclc/generic/include/math/clc_remainder.h   |  4 ----
 libclc/generic/lib/SOURCES                    |  1 -
 libclc/generic/lib/math/clc_fmod.cl           |  1 -
 libclc/generic/lib/math/clc_remquo.cl         |  1 -
 libclc/generic/lib/math/remainder.cl          |  6 ++---
 libclc/spirv/lib/SOURCES                      |  1 -
 12 files changed, 61 insertions(+), 18 deletions(-)
 create mode 100644 libclc/clc/include/clc/math/binary_def_via_fp32.inc
 create mode 100644 libclc/clc/include/clc/math/clc_remainder.h
 rename libclc/{generic/lib => clc/lib/generic}/math/clc_remainder.cl (92%)
 delete mode 100644 libclc/generic/include/math/clc_remainder.h

diff --git a/libclc/clc/include/clc/math/binary_def_via_fp32.inc b/libclc/clc/include/clc/math/binary_def_via_fp32.inc
new file mode 100644
index 0000000000000..0b4108adb0610
--- /dev/null
+++ b/libclc/clc/include/clc/math/binary_def_via_fp32.inc
@@ -0,0 +1,13 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+                                                    __CLC_GENTYPE y) {
+  return __CLC_CONVERT_GENTYPE(
+      __CLC_FUNCTION(__CLC_CONVERT_FLOATN(x), __CLC_CONVERT_FLOATN(y)));
+}
diff --git a/libclc/clc/include/clc/math/clc_remainder.h b/libclc/clc/include/clc/math/clc_remainder.h
new file mode 100644
index 0000000000000..2a1c88297d260
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_remainder.h
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_MATH_CLC_REMAINDER_H__
+#define __CLC_MATH_CLC_REMAINDER_H__
+
+#define __CLC_FUNCTION __clc_remainder
+#define __CLC_BODY <clc/shared/binary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_REMAINDER_H__
diff --git a/libclc/clc/include/clc/math/gentype.inc b/libclc/clc/include/clc/math/gentype.inc
index c624f4d19bbcf..b2299f13cfa23 100644
--- a/libclc/clc/include/clc/math/gentype.inc
+++ b/libclc/clc/include/clc/math/gentype.inc
@@ -56,6 +56,7 @@
 #define __CLC_CONVERT_S_GENTYPE __CLC_XCONCAT(__clc_convert_, __CLC_S_GENTYPE)
 #define __CLC_CONVERT_U_GENTYPE __CLC_XCONCAT(__clc_convert_, __CLC_U_GENTYPE)
 
+#if (!defined(__HALF_ONLY) && !defined(__DOUBLE_ONLY))
 #define __CLC_SCALAR_GENTYPE float
 #define __CLC_FPSIZE 32
 #define __CLC_FP_LIT(x) x##F
@@ -119,7 +120,9 @@
 #undef __CLC_FPSIZE
 #undef __CLC_SCALAR_GENTYPE
 
-#ifndef __FLOAT_ONLY
+#endif
+
+#if (!defined(__HALF_ONLY) && !defined(__FLOAT_ONLY))
 #ifdef cl_khr_fp64
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
@@ -188,7 +191,7 @@
 #endif
 #endif
 
-#ifndef __FLOAT_ONLY
+#if (!defined(__FLOAT_ONLY) && !defined(__DOUBLE_ONLY))
 #ifdef cl_khr_fp16
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index f7688d0442253..a4ce61fdcda43 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -32,6 +32,7 @@ math/clc_mad.cl
 math/clc_modf.cl
 math/clc_nan.cl
 math/clc_nextafter.cl
+math/clc_remainder.cl
 math/clc_rint.cl
 math/clc_round.cl
 math/clc_rsqrt.cl
diff --git a/libclc/generic/lib/math/clc_remainder.cl b/libclc/clc/lib/generic/math/clc_remainder.cl
similarity index 92%
rename from libclc/generic/lib/math/clc_remainder.cl
rename to libclc/clc/lib/generic/math/clc_remainder.cl
index e7ab4c653fd28..c79d271c624e2 100644
--- a/libclc/generic/lib/math/clc_remainder.cl
+++ b/libclc/clc/lib/generic/math/clc_remainder.cl
@@ -6,17 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
 #include <clc/clc_convert.h>
 #include <clc/clcmacro.h>
 #include <clc/integer/clc_clz.h>
+#include <clc/internal/clc.h>
 #include <clc/math/clc_floor.h>
 #include <clc/math/clc_fma.h>
-#include <clc/math/clc_subnormal_config.h>
+#include <clc/math/clc_ldexp.h>
+#include <clc/math/clc_remainder.h>
 #include <clc/math/clc_trunc.h>
 #include <clc/math/math.h>
 #include <clc/shared/clc_max.h>
-#include <math/clc_remainder.h>
 
 _CLC_DEF _CLC_OVERLOAD float __clc_remainder(float x, float y) {
   int ux = __clc_as_int(x);
@@ -77,6 +77,9 @@ _CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_remainder, float,
                       float);
 
 #ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
 _CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y) {
   ulong ux = __clc_as_ulong(x);
   ulong ax = ux & ~SIGNBIT_DP64;
@@ -104,7 +107,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y) {
   // but it doesn't matter - it just means that we'll go round
   // the loop below one extra time.
   int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
-  double w = ldexp(dy, ntimes * 53);
+  double w = __clc_ldexp(dy, ntimes * 53);
   w = ntimes == 0 ? dy : w;
   double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
 
@@ -207,3 +210,15 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y) {
 _CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, double, __clc_remainder, double,
                       double);
 #endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// Forward the half version of this builtin onto the float one
+#define __HALF_ONLY
+#define __CLC_FUNCTION __clc_remainder
+#define __CLC_BODY <clc/math/binary_def_via_fp32.inc>
+#include <clc/math/gentype.inc>
+
+#endif
diff --git a/libclc/clspv/lib/SOURCES b/libclc/clspv/lib/SOURCES
index fa9e68f6985ea..0a56588947aa3 100644
--- a/libclc/clspv/lib/SOURCES
+++ b/libclc/clspv/lib/SOURCES
@@ -21,7 +21,6 @@ subnormal_config.cl
 ../../generic/lib/math/clc_pow.cl
 ../../generic/lib/math/clc_pown.cl
 ../../generic/lib/math/clc_powr.cl
-../../generic/lib/math/clc_remainder.cl
 ../../generic/lib/math/clc_remquo.cl
 ../../generic/lib/math/clc_rootn.cl
 ../../generic/lib/math/clc_tan.cl
diff --git a/libclc/generic/include/math/clc_remainder.h b/libclc/generic/include/math/clc_remainder.h
deleted file mode 100644
index db084cf1c26a0..0000000000000
--- a/libclc/generic/include/math/clc_remainder.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#define __CLC_FUNCTION __clc_remainder
-#define __CLC_BODY <clc/math/binary_decl_tt.inc>
-#include <clc/math/gentype.inc>
-#undef __CLC_FUNCTION
diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES
index 15aafee79dfec..dab5424c984ed 100644
--- a/libclc/generic/lib/SOURCES
+++ b/libclc/generic/lib/SOURCES
@@ -164,7 +164,6 @@ math/clc_pown.cl
 math/pown.cl
 math/clc_powr.cl
 math/powr.cl
-math/clc_remainder.cl
 math/remainder.cl
 math/clc_remquo.cl
 math/remquo.cl
diff --git a/libclc/generic/lib/math/clc_fmod.cl b/libclc/generic/lib/math/clc_fmod.cl
index f8cb09d1ee111..64809879eba80 100644
--- a/libclc/generic/lib/math/clc_fmod.cl
+++ b/libclc/generic/lib/math/clc_fmod.cl
@@ -16,7 +16,6 @@
 #include <clc/math/clc_trunc.h>
 #include <clc/math/math.h>
 #include <clc/shared/clc_max.h>
-#include <math/clc_remainder.h>
 
 _CLC_DEF _CLC_OVERLOAD float __clc_fmod(float x, float y) {
   int ux = __clc_as_int(x);
diff --git a/libclc/generic/lib/math/clc_remquo.cl b/libclc/generic/lib/math/clc_remquo.cl
index 61c7fae29bc00..3de549efc32bf 100644
--- a/libclc/generic/lib/math/clc_remquo.cl
+++ b/libclc/generic/lib/math/clc_remquo.cl
@@ -16,7 +16,6 @@
 #include <clc/math/clc_trunc.h>
 #include <clc/math/math.h>
 #include <clc/shared/clc_max.h>
-#include <math/clc_remainder.h>
 
 _CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y,
                                           __private int *quo) {
diff --git a/libclc/generic/lib/math/remainder.cl b/libclc/generic/lib/math/remainder.cl
index 0a22ee8be2dd8..7692c54fa4398 100644
--- a/libclc/generic/lib/math/remainder.cl
+++ b/libclc/generic/lib/math/remainder.cl
@@ -1,6 +1,6 @@
 #include <clc/clc.h>
-#include <math/clc_remainder.h>
+#include <clc/math/clc_remainder.h>
 
-#define __CLC_FUNC remainder
-#define __CLC_BODY <clc_sw_binary.inc>
+#define FUNCTION remainder
+#define __CLC_BODY <clc/shared/binary_def.inc>
 #include <clc/math/gentype.inc>
diff --git a/libclc/spirv/lib/SOURCES b/libclc/spirv/lib/SOURCES
index 8378587d52bf3..ff68b410ec819 100644
--- a/libclc/spirv/lib/SOURCES
+++ b/libclc/spirv/lib/SOURCES
@@ -66,7 +66,6 @@ math/fma.cl
 ../../generic/lib/math/pown.cl
 ../../generic/lib/math/clc_powr.cl
 ../../generic/lib/math/powr.cl
-../../generic/lib/math/clc_remainder.cl
 ../../generic/lib/math/remainder.cl
 ../../generic/lib/math/clc_remquo.cl
 ../../generic/lib/math/remquo.cl

>From df190223d3fbeb525b10a35e8b61f1d607a67657 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Wed, 19 Mar 2025 15:01:04 +0000
Subject: [PATCH 2/3] [libclc] Move __clc_fmod to the CLC library

---
 libclc/clc/include/clc/math/clc_fmod.h        | 20 ++++++++++++++++++
 libclc/clc/lib/generic/SOURCES                |  1 +
 .../lib => clc/lib/generic}/math/clc_fmod.cl  | 21 ++++++++++++++++---
 libclc/clspv/lib/SOURCES                      |  1 -
 libclc/generic/include/math/clc_fmod.h        |  4 ----
 libclc/generic/lib/SOURCES                    |  1 -
 libclc/generic/lib/math/fmod.cl               |  6 +++---
 libclc/spirv/lib/SOURCES                      |  1 -
 8 files changed, 42 insertions(+), 13 deletions(-)
 create mode 100644 libclc/clc/include/clc/math/clc_fmod.h
 rename libclc/{generic/lib => clc/lib/generic}/math/clc_fmod.cl (91%)
 delete mode 100644 libclc/generic/include/math/clc_fmod.h

diff --git a/libclc/clc/include/clc/math/clc_fmod.h b/libclc/clc/include/clc/math/clc_fmod.h
new file mode 100644
index 0000000000000..59778fd0f6129
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_fmod.h
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_MATH_CLC_FMOD_H__
+#define __CLC_MATH_CLC_FMOD_H__
+
+#define __CLC_FUNCTION __clc_fmod
+#define __CLC_BODY <clc/shared/binary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_FMOD_H__
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index a4ce61fdcda43..f00f977c479fc 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -21,6 +21,7 @@ math/clc_ceil.cl
 math/clc_copysign.cl
 math/clc_fabs.cl
 math/clc_fma.cl
+math/clc_fmod.cl
 math/clc_floor.cl
 math/clc_frexp.cl
 math/clc_hypot.cl
diff --git a/libclc/generic/lib/math/clc_fmod.cl b/libclc/clc/lib/generic/math/clc_fmod.cl
similarity index 91%
rename from libclc/generic/lib/math/clc_fmod.cl
rename to libclc/clc/lib/generic/math/clc_fmod.cl
index 64809879eba80..6af84a14f3d1a 100644
--- a/libclc/generic/lib/math/clc_fmod.cl
+++ b/libclc/clc/lib/generic/math/clc_fmod.cl
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
 #include <clc/clc_convert.h>
 #include <clc/clcmacro.h>
 #include <clc/integer/clc_clz.h>
+#include <clc/internal/clc.h>
 #include <clc/math/clc_floor.h>
 #include <clc/math/clc_fma.h>
-#include <clc/math/clc_subnormal_config.h>
+#include <clc/math/clc_ldexp.h>
 #include <clc/math/clc_trunc.h>
 #include <clc/math/math.h>
 #include <clc/shared/clc_max.h>
@@ -66,6 +66,9 @@ _CLC_DEF _CLC_OVERLOAD float __clc_fmod(float x, float y) {
 _CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_fmod, float, float);
 
 #ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
 _CLC_DEF _CLC_OVERLOAD double __clc_fmod(double x, double y) {
   ulong ux = __clc_as_ulong(x);
   ulong ax = ux & ~SIGNBIT_DP64;
@@ -91,7 +94,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_fmod(double x, double y) {
   // but it doesn't matter - it just means that we'll go round
   // the loop below one extra time.
   int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
-  double w = ldexp(dy, ntimes * 53);
+  double w = __clc_ldexp(dy, ntimes * 53);
   w = ntimes == 0 ? dy : w;
   double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
 
@@ -170,3 +173,15 @@ _CLC_DEF _CLC_OVERLOAD double __clc_fmod(double x, double y) {
 _CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, double, __clc_fmod, double,
                       double);
 #endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// Forward the half version of this builtin onto the float one
+#define __HALF_ONLY
+#define __CLC_FUNCTION __clc_fmod
+#define __CLC_BODY <clc/math/binary_def_via_fp32.inc>
+#include <clc/math/gentype.inc>
+
+#endif
diff --git a/libclc/clspv/lib/SOURCES b/libclc/clspv/lib/SOURCES
index 0a56588947aa3..b4b6964fad1fa 100644
--- a/libclc/clspv/lib/SOURCES
+++ b/libclc/clspv/lib/SOURCES
@@ -17,7 +17,6 @@ subnormal_config.cl
 ../../generic/lib/math/atanpi.cl
 ../../generic/lib/math/cbrt.cl
 ../../generic/lib/math/clc_exp10.cl
-../../generic/lib/math/clc_fmod.cl
 ../../generic/lib/math/clc_pow.cl
 ../../generic/lib/math/clc_pown.cl
 ../../generic/lib/math/clc_powr.cl
diff --git a/libclc/generic/include/math/clc_fmod.h b/libclc/generic/include/math/clc_fmod.h
deleted file mode 100644
index 0409785ee500a..0000000000000
--- a/libclc/generic/include/math/clc_fmod.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#define __CLC_FUNCTION __clc_fmod
-#define __CLC_BODY <clc/math/binary_decl_tt.inc>
-#include <clc/math/gentype.inc>
-#undef __CLC_FUNCTION
diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES
index dab5424c984ed..3ccb4a3702eef 100644
--- a/libclc/generic/lib/SOURCES
+++ b/libclc/generic/lib/SOURCES
@@ -109,7 +109,6 @@ math/floor.cl
 math/fma.cl
 math/fmax.cl
 math/fmin.cl
-math/clc_fmod.cl
 math/fmod.cl
 math/fract.cl
 math/frexp.cl
diff --git a/libclc/generic/lib/math/fmod.cl b/libclc/generic/lib/math/fmod.cl
index fac3fc6eb995d..19d0d7a293357 100644
--- a/libclc/generic/lib/math/fmod.cl
+++ b/libclc/generic/lib/math/fmod.cl
@@ -1,6 +1,6 @@
 #include <clc/clc.h>
-#include <math/clc_fmod.h>
+#include <clc/math/clc_fmod.h>
 
-#define __CLC_FUNC fmod
-#define __CLC_BODY <clc_sw_binary.inc>
+#define FUNCTION fmod
+#define __CLC_BODY <clc/shared/binary_def.inc>
 #include <clc/math/gentype.inc>
diff --git a/libclc/spirv/lib/SOURCES b/libclc/spirv/lib/SOURCES
index ff68b410ec819..deaa8b972da9e 100644
--- a/libclc/spirv/lib/SOURCES
+++ b/libclc/spirv/lib/SOURCES
@@ -42,7 +42,6 @@ subnormal_config.cl
 ../../generic/lib/math/clc_exp10.cl
 ../../generic/lib/math/exp10.cl
 math/fma.cl
-../../generic/lib/math/clc_fmod.cl
 ../../generic/lib/math/fmod.cl
 ../../generic/lib/math/fract.cl
 ../../generic/lib/math/frexp.cl

>From 3d3b659bdef69496b2c3b79aa3868c92da6f3a5e Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Wed, 19 Mar 2025 15:17:27 +0000
Subject: [PATCH 3/3] [libclc] Move clc_remquo

---
 libclc/clc/include/clc/math/clc_remquo.h      | 22 +++++++++++++++++++
 libclc/clc/include/clc/math/remquo_decl.inc   | 10 +++++++++
 libclc/clc/lib/generic/SOURCES                |  1 +
 .../lib/generic}/math/clc_remquo.cl           |  8 +++++--
 libclc/clspv/lib/SOURCES                      |  1 -
 libclc/generic/include/clc/math/remquo.h      |  6 ++---
 libclc/generic/include/clc/math/remquo.inc    |  1 -
 libclc/generic/include/math/clc_remquo.h      |  8 -------
 libclc/generic/lib/SOURCES                    |  1 -
 libclc/generic/lib/math/remquo.cl             |  2 +-
 libclc/generic/lib/math/remquo.inc            |  3 ++-
 libclc/spirv/lib/SOURCES                      |  1 -
 12 files changed, 45 insertions(+), 19 deletions(-)
 create mode 100644 libclc/clc/include/clc/math/clc_remquo.h
 create mode 100644 libclc/clc/include/clc/math/remquo_decl.inc
 rename libclc/{generic/lib => clc/lib/generic}/math/clc_remquo.cl (98%)
 delete mode 100644 libclc/generic/include/clc/math/remquo.inc
 delete mode 100644 libclc/generic/include/math/clc_remquo.h

diff --git a/libclc/clc/include/clc/math/clc_remquo.h b/libclc/clc/include/clc/math/clc_remquo.h
new file mode 100644
index 0000000000000..6588342cf81b3
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_remquo.h
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_MATH_CLC_REMQUO_H__
+#define __CLC_MATH_CLC_REMQUO_H__
+
+#define __CLC_FUNCTION __clc_remquo
+
+#define __CLC_BODY <clc/math/remquo_decl.inc>
+#define __CLC_ADDRESS_SPACE private
+#include <clc/math/gentype.inc>
+
+#undef __CLC_ADDRESS_SPACE
+#undef __CLC_BODY
+#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
new file mode 100644
index 0000000000000..ecd703042a964
--- /dev/null
+++ b/libclc/clc/include/clc/math/remquo_decl.inc
@@ -0,0 +1,10 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+    __CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q);
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index f00f977c479fc..87869d8972f30 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -34,6 +34,7 @@ math/clc_modf.cl
 math/clc_nan.cl
 math/clc_nextafter.cl
 math/clc_remainder.cl
+math/clc_remquo.cl
 math/clc_rint.cl
 math/clc_round.cl
 math/clc_rsqrt.cl
diff --git a/libclc/generic/lib/math/clc_remquo.cl b/libclc/clc/lib/generic/math/clc_remquo.cl
similarity index 98%
rename from libclc/generic/lib/math/clc_remquo.cl
rename to libclc/clc/lib/generic/math/clc_remquo.cl
index 3de549efc32bf..9fa94c1c290b8 100644
--- a/libclc/generic/lib/math/clc_remquo.cl
+++ b/libclc/clc/lib/generic/math/clc_remquo.cl
@@ -6,12 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
 #include <clc/clc_convert.h>
 #include <clc/clcmacro.h>
 #include <clc/integer/clc_clz.h>
+#include <clc/internal/clc.h>
 #include <clc/math/clc_floor.h>
 #include <clc/math/clc_fma.h>
+#include <clc/math/clc_ldexp.h>
 #include <clc/math/clc_subnormal_config.h>
 #include <clc/math/clc_trunc.h>
 #include <clc/math/math.h>
@@ -115,6 +116,9 @@ __VEC_REMQUO(float, 8, 4)
 __VEC_REMQUO(float, 16, 8)
 
 #ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
 _CLC_DEF _CLC_OVERLOAD double __clc_remquo(double x, double y,
                                            __private int *pquo) {
   ulong ux = __clc_as_ulong(x);
@@ -143,7 +147,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remquo(double x, double y,
   // but it doesn't matter - it just means that we'll go round
   // the loop below one extra time.
   int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
-  double w = ldexp(dy, ntimes * 53);
+  double w = __clc_ldexp(dy, ntimes * 53);
   w = ntimes == 0 ? dy : w;
   double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
 
diff --git a/libclc/clspv/lib/SOURCES b/libclc/clspv/lib/SOURCES
index b4b6964fad1fa..4354cb6f4b32c 100644
--- a/libclc/clspv/lib/SOURCES
+++ b/libclc/clspv/lib/SOURCES
@@ -20,7 +20,6 @@ subnormal_config.cl
 ../../generic/lib/math/clc_pow.cl
 ../../generic/lib/math/clc_pown.cl
 ../../generic/lib/math/clc_powr.cl
-../../generic/lib/math/clc_remquo.cl
 ../../generic/lib/math/clc_rootn.cl
 ../../generic/lib/math/clc_tan.cl
 ../../generic/lib/math/clc_tanpi.cl
diff --git a/libclc/generic/include/clc/math/remquo.h b/libclc/generic/include/clc/math/remquo.h
index 7daf82fc34b33..ceae6dfc407b4 100644
--- a/libclc/generic/include/clc/math/remquo.h
+++ b/libclc/generic/include/clc/math/remquo.h
@@ -1,16 +1,16 @@
 #define __CLC_FUNCTION remquo
 
-#define __CLC_BODY <clc/math/remquo.inc>
+#define __CLC_BODY <clc/math/remquo_decl.inc>
 #define __CLC_ADDRESS_SPACE global
 #include <clc/math/gentype.inc>
 #undef __CLC_ADDRESS_SPACE
 
-#define __CLC_BODY <clc/math/remquo.inc>
+#define __CLC_BODY <clc/math/remquo_decl.inc>
 #define __CLC_ADDRESS_SPACE local
 #include <clc/math/gentype.inc>
 #undef __CLC_ADDRESS_SPACE
 
-#define __CLC_BODY <clc/math/remquo.inc>
+#define __CLC_BODY <clc/math/remquo_decl.inc>
 #define __CLC_ADDRESS_SPACE private
 #include <clc/math/gentype.inc>
 #undef __CLC_ADDRESS_SPACE
diff --git a/libclc/generic/include/clc/math/remquo.inc b/libclc/generic/include/clc/math/remquo.inc
deleted file mode 100644
index 42c7b6789f5fc..0000000000000
--- a/libclc/generic/include/clc/math/remquo.inc
+++ /dev/null
@@ -1 +0,0 @@
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q);
diff --git a/libclc/generic/include/math/clc_remquo.h b/libclc/generic/include/math/clc_remquo.h
deleted file mode 100644
index ed57ec98edf40..0000000000000
--- a/libclc/generic/include/math/clc_remquo.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#define __CLC_FUNCTION __clc_remquo
-
-#define __CLC_BODY <clc/math/remquo.inc>
-#define __CLC_ADDRESS_SPACE private
-#include <clc/math/gentype.inc>
-#undef __CLC_ADDRESS_SPACE
-
-#undef __CLC_FUNCTION
diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES
index 3ccb4a3702eef..afa4bacb7825e 100644
--- a/libclc/generic/lib/SOURCES
+++ b/libclc/generic/lib/SOURCES
@@ -164,7 +164,6 @@ math/pown.cl
 math/clc_powr.cl
 math/powr.cl
 math/remainder.cl
-math/clc_remquo.cl
 math/remquo.cl
 math/rint.cl
 math/clc_rootn.cl
diff --git a/libclc/generic/lib/math/remquo.cl b/libclc/generic/lib/math/remquo.cl
index fc29b366b36ed..2a580427f251f 100644
--- a/libclc/generic/lib/math/remquo.cl
+++ b/libclc/generic/lib/math/remquo.cl
@@ -1,5 +1,5 @@
 #include <clc/clc.h>
-#include <math/clc_remquo.h>
+#include <clc/math/clc_remquo.h>
 
 #define __CLC_BODY <remquo.inc>
 #define __CLC_ADDRESS_SPACE global
diff --git a/libclc/generic/lib/math/remquo.inc b/libclc/generic/lib/math/remquo.inc
index c1de78a5e7f9c..88aed4b32c4ad 100644
--- a/libclc/generic/lib/math/remquo.inc
+++ b/libclc/generic/lib/math/remquo.inc
@@ -1,4 +1,5 @@
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE remquo(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q) {
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE remquo(__CLC_GENTYPE x, __CLC_GENTYPE y,
+                                            __CLC_ADDRESS_SPACE __CLC_INTN *q) {
   __CLC_INTN local_q;
   __CLC_GENTYPE ret = __clc_remquo(x, y, &local_q);
   *q = local_q;
diff --git a/libclc/spirv/lib/SOURCES b/libclc/spirv/lib/SOURCES
index deaa8b972da9e..0ede4a23dfbb0 100644
--- a/libclc/spirv/lib/SOURCES
+++ b/libclc/spirv/lib/SOURCES
@@ -66,7 +66,6 @@ math/fma.cl
 ../../generic/lib/math/clc_powr.cl
 ../../generic/lib/math/powr.cl
 ../../generic/lib/math/remainder.cl
-../../generic/lib/math/clc_remquo.cl
 ../../generic/lib/math/remquo.cl
 ../../generic/lib/math/clc_rootn.cl
 ../../generic/lib/math/rootn.cl



More information about the cfe-commits mailing list