Author: Fraser Cormack
Date: 2025-05-01T09:43:40+01:00
New Revision: 6c4dd8d1d2f1e81c2b309924afb255b58a31ceb2

URL: 
https://github.com/llvm/llvm-project/commit/6c4dd8d1d2f1e81c2b309924afb255b58a31ceb2
DIFF: 
https://github.com/llvm/llvm-project/commit/6c4dd8d1d2f1e81c2b309924afb255b58a31ceb2.diff

LOG: [libclc] Move minmag & maxmag to the CLC library (#137982)

Added: 
    libclc/clc/include/clc/math/clc_maxmag.h
    libclc/clc/include/clc/math/clc_minmag.h
    libclc/clc/lib/generic/math/clc_maxmag.cl
    libclc/clc/lib/generic/math/clc_maxmag.inc
    libclc/clc/lib/generic/math/clc_minmag.cl
    libclc/clc/lib/generic/math/clc_minmag.inc

Modified: 
    libclc/clc/lib/generic/SOURCES
    libclc/generic/lib/math/maxmag.cl
    libclc/generic/lib/math/minmag.cl

Removed: 
    libclc/generic/lib/math/maxmag.inc
    libclc/generic/lib/math/minmag.inc


################################################################################
diff  --git a/libclc/clc/include/clc/math/clc_maxmag.h 
b/libclc/clc/include/clc/math/clc_maxmag.h
new file mode 100644
index 0000000000000..857ad7867b05d
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_maxmag.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_MAXMAG_H__
+#define __CLC_MATH_CLC_MAXMAG_H__
+
+#define __CLC_BODY <clc/shared/binary_decl.inc>
+#define __CLC_FUNCTION __clc_maxmag
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_MAXMAG_H__

diff  --git a/libclc/clc/include/clc/math/clc_minmag.h 
b/libclc/clc/include/clc/math/clc_minmag.h
new file mode 100644
index 0000000000000..9615d029bfed2
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_minmag.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_MINMAG_H__
+#define __CLC_MATH_CLC_MINMAG_H__
+
+#define __CLC_BODY <clc/shared/binary_decl.inc>
+#define __CLC_FUNCTION __clc_minmag
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_MINMAG_H__

diff  --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index a69a0530a0ac0..4240e7b08e7d1 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -58,6 +58,8 @@ math/clc_log10.cl
 math/clc_log1p.cl
 math/clc_log2.cl
 math/clc_mad.cl
+math/clc_maxmag.cl
+math/clc_minmag.cl
 math/clc_modf.cl
 math/clc_nan.cl
 math/clc_native_cos.cl

diff  --git a/libclc/clc/lib/generic/math/clc_maxmag.cl 
b/libclc/clc/lib/generic/math/clc_maxmag.cl
new file mode 100644
index 0000000000000..e34fd5613c3f2
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_maxmag.cl
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/clc_convert.h>
+#include <clc/internal/clc.h>
+#include <clc/math/clc_fabs.h>
+#include <clc/math/clc_fmax.h>
+#include <clc/relational/clc_isequal.h>
+#include <clc/relational/clc_isgreater.h>
+#include <clc/relational/clc_isnan.h>
+#include <clc/relational/clc_select.h>
+
+#define __CLC_BODY <clc_maxmag.inc>
+#include <clc/math/gentype.inc>

diff  --git a/libclc/clc/lib/generic/math/clc_maxmag.inc 
b/libclc/clc/lib/generic/math/clc_maxmag.inc
new file mode 100644
index 0000000000000..0c346eeac8ae2
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_maxmag.inc
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_maxmag(__CLC_GENTYPE x,
+                                                  __CLC_GENTYPE y) {
+  const __CLC_GENTYPE res = __clc_select(
+      y, x,
+      __CLC_CONVERT_BIT_INTN(__clc_isgreater(__clc_fabs(x), __clc_fabs(y))));
+  return __clc_select(
+      res, __clc_fmax(x, y),
+      __CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y) ||
+                             __clc_isequal(__clc_fabs(x), __clc_fabs(y))));
+}

diff  --git a/libclc/clc/lib/generic/math/clc_minmag.cl 
b/libclc/clc/lib/generic/math/clc_minmag.cl
new file mode 100644
index 0000000000000..8529beb8d83f0
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_minmag.cl
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/clc_convert.h>
+#include <clc/internal/clc.h>
+#include <clc/math/clc_fabs.h>
+#include <clc/math/clc_fmin.h>
+#include <clc/relational/clc_isequal.h>
+#include <clc/relational/clc_isless.h>
+#include <clc/relational/clc_isnan.h>
+#include <clc/relational/clc_select.h>
+
+#define __CLC_BODY <clc_minmag.inc>
+#include <clc/math/gentype.inc>

diff  --git a/libclc/clc/lib/generic/math/clc_minmag.inc 
b/libclc/clc/lib/generic/math/clc_minmag.inc
new file mode 100644
index 0000000000000..2b9236fedfeb2
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_minmag.inc
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_minmag(__CLC_GENTYPE x,
+                                                  __CLC_GENTYPE y) {
+  const __CLC_GENTYPE res = __clc_select(
+      y, x, __CLC_CONVERT_BIT_INTN(__clc_isless(__clc_fabs(x), 
__clc_fabs(y))));
+  return __clc_select(
+      res, __clc_fmin(x, y),
+      __CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y) ||
+                             __clc_isequal(__clc_fabs(x), __clc_fabs(y))));
+}

diff  --git a/libclc/generic/lib/math/maxmag.cl 
b/libclc/generic/lib/math/maxmag.cl
index cbc12d5cf4bf9..720fc027177ac 100644
--- a/libclc/generic/lib/math/maxmag.cl
+++ b/libclc/generic/lib/math/maxmag.cl
@@ -7,7 +7,8 @@
 
//===----------------------------------------------------------------------===//
 
 #include <clc/clc.h>
-#include <clc/utils.h>
+#include <clc/math/clc_maxmag.h>
 
-#define __CLC_BODY <maxmag.inc>
+#define FUNCTION maxmag
+#define __CLC_BODY <clc/shared/binary_def.inc>
 #include <clc/math/gentype.inc>

diff  --git a/libclc/generic/lib/math/maxmag.inc 
b/libclc/generic/lib/math/maxmag.inc
deleted file mode 100644
index 94149c2989915..0000000000000
--- a/libclc/generic/lib/math/maxmag.inc
+++ /dev/null
@@ -1,22 +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
-//
-//===----------------------------------------------------------------------===//
-
-#if __CLC_FPSIZE == 64
-#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_long, __CLC_VECSIZE)
-#elif __CLC_FPSIZE == 32
-#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_int, __CLC_VECSIZE)
-#elif __CLC_FPSIZE == 16
-#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_short, __CLC_VECSIZE)
-#endif
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE maxmag(__CLC_GENTYPE x, __CLC_GENTYPE y) {
-  const __CLC_GENTYPE res = select(y, x, __CLC_CONVERT_NATN(isgreater(fabs(x), 
fabs(y))));
-  return select(res, fmax(x, y), __CLC_CONVERT_NATN(isnan(x) | isnan(y) | 
isequal(fabs(x), fabs(y))));
-}
-
-#undef __CLC_CONVERT_NATN

diff  --git a/libclc/generic/lib/math/minmag.cl 
b/libclc/generic/lib/math/minmag.cl
index f41852ceda412..37536584f8f85 100644
--- a/libclc/generic/lib/math/minmag.cl
+++ b/libclc/generic/lib/math/minmag.cl
@@ -7,7 +7,8 @@
 
//===----------------------------------------------------------------------===//
 
 #include <clc/clc.h>
-#include <clc/utils.h>
+#include <clc/math/clc_minmag.h>
 
-#define __CLC_BODY <minmag.inc>
+#define FUNCTION minmag
+#define __CLC_BODY <clc/shared/binary_def.inc>
 #include <clc/math/gentype.inc>

diff  --git a/libclc/generic/lib/math/minmag.inc 
b/libclc/generic/lib/math/minmag.inc
deleted file mode 100644
index 7a4a00735be78..0000000000000
--- a/libclc/generic/lib/math/minmag.inc
+++ /dev/null
@@ -1,30 +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
-//
-//===----------------------------------------------------------------------===//
-
-#ifdef __CLC_SCALAR
-#define __CLC_VECSIZE
-#endif
-
-#if __CLC_FPSIZE == 64
-#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_long, __CLC_VECSIZE)
-#elif __CLC_FPSIZE == 32
-#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_int, __CLC_VECSIZE)
-#elif __CLC_FPSIZE == 16
-#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_short, __CLC_VECSIZE)
-#endif
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE minmag(__CLC_GENTYPE x, __CLC_GENTYPE y) {
-  const __CLC_GENTYPE res = select(y, x, __CLC_CONVERT_NATN(isless(fabs(x), 
fabs(y))));
-  return select(res, fmin(x, y), __CLC_CONVERT_NATN(isnan(x) | isnan(y) | 
isequal(fabs(x), fabs(y))));
-}
-
-#undef __CLC_CONVERT_NATN
-
-#ifdef __CLC_SCALAR
-#undef __CLC_VECSIZE
-#endif


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to