[llvm-branch-commits] [libclc] libclc: Use log intrinsic for half and float cases for amdgpu (PR #187538)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 19 09:59:57 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

This is pretty verbose and ugly. We're pulling the base implementation
in for the double cases, and scalarizing it. Also fully defining the
half and float cases to directly use the intrinsic, for all vector
types. It would be much more convenient if we had linker based overrides
for the generic implementations, rather than per source file.

---
Full diff: https://github.com/llvm/llvm-project/pull/187538.diff


3 Files Affected:

- (modified) libclc/clc/lib/amdgpu/CMakeLists.txt (+3) 
- (added) libclc/clc/lib/amdgpu/math/clc_amdgpu_log.inc (+4) 
- (added) libclc/clc/lib/amdgpu/math/clc_log.cl (+44) 


``````````diff
diff --git a/libclc/clc/lib/amdgpu/CMakeLists.txt b/libclc/clc/lib/amdgpu/CMakeLists.txt
index a2a30c2941d6b..b28ae8f66ff22 100644
--- a/libclc/clc/lib/amdgpu/CMakeLists.txt
+++ b/libclc/clc/lib/amdgpu/CMakeLists.txt
@@ -17,6 +17,9 @@ libclc_configure_source_list(CLC_AMDGPU_SOURCES
   math/clc_half_sqrt.cl
   math/clc_get_twobypi_bits.cl
   math/clc_ldexp.cl
+  math/clc_log.cl
+  math/clc_log10.cl
+  math/clc_log2.cl
   math/clc_log2_fast.cl
   math/clc_native_exp.cl
   math/clc_native_exp2.cl
diff --git a/libclc/clc/lib/amdgpu/math/clc_amdgpu_log.inc b/libclc/clc/lib/amdgpu/math/clc_amdgpu_log.inc
new file mode 100644
index 0000000000000..bed0edc8e1478
--- /dev/null
+++ b/libclc/clc/lib/amdgpu/math/clc_amdgpu_log.inc
@@ -0,0 +1,4 @@
+
+#ifdef __CLC_SCALAR
+#include "clc_log_base.inc"
+#endif
diff --git a/libclc/clc/lib/amdgpu/math/clc_log.cl b/libclc/clc/lib/amdgpu/math/clc_log.cl
new file mode 100644
index 0000000000000..44448e5d746cb
--- /dev/null
+++ b/libclc/clc/lib/amdgpu/math/clc_log.cl
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/float/definitions.h"
+#include "clc/math/clc_ep.h"
+#include "clc/math/clc_frexp.h"
+#include "clc/math/clc_ldexp.h"
+#include "clc/math/clc_log.h"
+#include "clc/math/clc_mad.h"
+#include "clc/relational/clc_isinf.h"
+
+#define __CLC_FLOAT_ONLY
+#define __CLC_FUNCTION __clc_log
+#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log
+#define __CLC_BODY "clc/shared/unary_def.inc"
+#include "clc/math/gentype.inc"
+#undef __CLC_FUNCTION
+#undef __CLC_IMPL_FUNCTION
+#undef __CLC_FLOAT_ONLY
+
+#define __CLC_HALF_ONLY
+#define __CLC_FUNCTION __clc_log
+#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log
+#define __CLC_BODY "clc/shared/unary_def.inc"
+#include "clc/math/gentype.inc"
+#undef __CLC_FUNCTION
+#undef __CLC_IMPL_FUNCTION
+#undef __CLC_HALF_ONLY
+
+#define COMPILING_LOG
+#define __CLC_DOUBLE_ONLY
+#define __CLC_BODY "clc_amdgpu_log.inc"
+#include "clc/math/gentype.inc"
+
+#define __CLC_DOUBLE_ONLY
+#define __CLC_FUNCTION __clc_log
+#define __CLC_BODY "clc/shared/unary_def_scalarize_loop.inc"
+#include "clc/math/gentype.inc"

``````````

</details>


https://github.com/llvm/llvm-project/pull/187538


More information about the llvm-branch-commits mailing list