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

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 19 09:58:35 PDT 2026


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

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.

>From ada9bce92242f1515e33ba06e8e406d3756bf0a0 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 19 Mar 2026 17:02:44 +0100
Subject: [PATCH] libclc: Use log intrinsic for half and float cases for amdgpu

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.
---
 libclc/clc/lib/amdgpu/CMakeLists.txt          |  3 ++
 libclc/clc/lib/amdgpu/math/clc_amdgpu_log.inc |  4 ++
 libclc/clc/lib/amdgpu/math/clc_log.cl         | 44 +++++++++++++++++++
 3 files changed, 51 insertions(+)
 create mode 100644 libclc/clc/lib/amdgpu/math/clc_amdgpu_log.inc
 create mode 100644 libclc/clc/lib/amdgpu/math/clc_log.cl

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"



More information about the llvm-branch-commits mailing list