[libclc] d780072 - libclc: Add fast version utility functions for div, sqrt and reciprocal (#185823)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 11 01:56:54 PDT 2026
Author: Matt Arsenault
Date: 2026-03-11T09:56:49+01:00
New Revision: d780072691899a39f692a5324c279aa4fc338a22
URL: https://github.com/llvm/llvm-project/commit/d780072691899a39f692a5324c279aa4fc338a22
DIFF: https://github.com/llvm/llvm-project/commit/d780072691899a39f692a5324c279aa4fc338a22.diff
LOG: libclc: Add fast version utility functions for div, sqrt and reciprocal (#185823)
Added:
libclc/clc/include/clc/math/clc_div_fast.h
libclc/clc/include/clc/math/clc_recip_fast.h
libclc/clc/include/clc/math/clc_sqrt_fast.h
libclc/clc/lib/generic/math/clc_div_fast.cl
libclc/clc/lib/generic/math/clc_div_fast.inc
libclc/clc/lib/generic/math/clc_recip_fast.cl
libclc/clc/lib/generic/math/clc_recip_fast.inc
libclc/clc/lib/generic/math/clc_sqrt_fast.cl
Modified:
libclc/clc/lib/generic/CMakeLists.txt
Removed:
################################################################################
diff --git a/libclc/clc/include/clc/math/clc_div_fast.h b/libclc/clc/include/clc/math/clc_div_fast.h
new file mode 100644
index 0000000000000..357bac4adc3d9
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_div_fast.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_DIV_FAST_H__
+#define __CLC_MATH_CLC_DIV_FAST_H__
+
+#define __CLC_FUNCTION __clc_div_fast
+#define __CLC_BODY <clc/shared/binary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_DIV_FAST_H__
diff --git a/libclc/clc/include/clc/math/clc_recip_fast.h b/libclc/clc/include/clc/math/clc_recip_fast.h
new file mode 100644
index 0000000000000..82890d606249a
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_recip_fast.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_RECIP_FAST_H__
+#define __CLC_MATH_CLC_RECIP_FAST_H__
+
+#define __CLC_FUNCTION __clc_recip_fast
+#define __CLC_BODY <clc/shared/unary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_RECIP_FAST_H__
diff --git a/libclc/clc/include/clc/math/clc_sqrt_fast.h b/libclc/clc/include/clc/math/clc_sqrt_fast.h
new file mode 100644
index 0000000000000..3d0f501979320
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_sqrt_fast.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_SQRT_FAST_H__
+#define __CLC_MATH_CLC_SQRT_FAST_H__
+
+#define __CLC_FUNCTION __clc_sqrt_fast
+#define __CLC_BODY <clc/shared/unary_decl.inc>
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_SQRT_FAST_H__
diff --git a/libclc/clc/lib/generic/CMakeLists.txt b/libclc/clc/lib/generic/CMakeLists.txt
index e2a551a03dca8..7d7286de11f85 100644
--- a/libclc/clc/lib/generic/CMakeLists.txt
+++ b/libclc/clc/lib/generic/CMakeLists.txt
@@ -73,6 +73,7 @@ libclc_configure_source_list(CLC_GENERIC_SOURCES
math/clc_cosh.cl
math/clc_cospi.cl
math/clc_div_cr.cl
+ math/clc_div_fast.cl
math/clc_ep_log.cl
math/clc_erf.cl
math/clc_erfc.cl
@@ -137,6 +138,7 @@ libclc_configure_source_list(CLC_GENERIC_SOURCES
math/clc_pow.cl
math/clc_pown.cl
math/clc_powr.cl
+ math/clc_recip_fast.cl
math/clc_remainder.cl
math/clc_remquo.cl
math/clc_rint.cl
@@ -150,6 +152,7 @@ libclc_configure_source_list(CLC_GENERIC_SOURCES
math/clc_sinpi.cl
math/clc_sqrt.cl
math/clc_sqrt_cr.cl
+ math/clc_sqrt_fast.cl
math/clc_tables.cl
math/clc_tan.cl
math/clc_tanh.cl
@@ -207,7 +210,9 @@ libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -fapprox-func
math/clc_native_sin.cl
math/clc_native_sqrt.cl
math/clc_native_tan.cl
-)
+ math/clc_div_fast.cl
+ math/clc_recip_fast.cl
+ math/clc_sqrt_fast.cl)
libclc_configure_source_options(${CMAKE_CURRENT_SOURCE_DIR} -cl-fp32-correctly-rounded-divide-sqrt
math/clc_div_cr.cl
diff --git a/libclc/clc/lib/generic/math/clc_div_fast.cl b/libclc/clc/lib/generic/math/clc_div_fast.cl
new file mode 100644
index 0000000000000..b5c477cfcb7c3
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_div_fast.cl
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+#include "clc/math/clc_div_fast.h"
+
+#define __CLC_FUNCTION __clc_div_fast
+#define __CLC_BODY <clc_div_fast.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/clc/lib/generic/math/clc_div_fast.inc b/libclc/clc/lib/generic/math/clc_div_fast.inc
new file mode 100644
index 0000000000000..c44fea15a0b20
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_div_fast.inc
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_div_fast(__CLC_GENTYPE x,
+ __CLC_GENTYPE y) {
+ return x / y;
+}
diff --git a/libclc/clc/lib/generic/math/clc_recip_fast.cl b/libclc/clc/lib/generic/math/clc_recip_fast.cl
new file mode 100644
index 0000000000000..779acf8078881
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_recip_fast.cl
@@ -0,0 +1,14 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/clc.h>
+
+#define __CLC_FUNCTION __clc_recip_fast
+#define __CLC_BODY <clc_recip_fast.inc>
+
+#include <clc/math/gentype.inc>
diff --git a/libclc/clc/lib/generic/math/clc_recip_fast.inc b/libclc/clc/lib/generic/math/clc_recip_fast.inc
new file mode 100644
index 0000000000000..dfe0f7dadd323
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_recip_fast.inc
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_recip_fast(__CLC_GENTYPE x) {
+ return ((__CLC_GENTYPE)1.0) / x;
+}
diff --git a/libclc/clc/lib/generic/math/clc_sqrt_fast.cl b/libclc/clc/lib/generic/math/clc_sqrt_fast.cl
new file mode 100644
index 0000000000000..89a478ac80908
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_sqrt_fast.cl
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/clc.h>
+
+#define __CLC_FUNCTION __clc_sqrt_fast
+#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_sqrt
+#define __CLC_BODY <clc/shared/unary_def.inc>
+
+#include <clc/math/gentype.inc>
More information about the cfe-commits
mailing list