libclc: Use log intrinsic for half and float cases for amdgpu (#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.
This commit is contained in:
Matt Arsenault 2026-03-20 08:33:31 +01:00 committed by GitHub
parent a5de509e4e
commit edbe8277c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 137 additions and 0 deletions

View File

@ -18,6 +18,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

View File

@ -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
//
//===----------------------------------------------------------------------===//
#ifdef __CLC_SCALAR
#include "clc_log_base.inc"
#endif

View File

@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// 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_FUNCTION __clc_log
#define __CLC_FLOAT_ONLY
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log
#define __CLC_BODY "clc/shared/unary_def.inc"
#include "clc/math/gentype.inc"
#undef __CLC_IMPL_FUNCTION
#undef __CLC_FLOAT_ONLY
#define __CLC_HALF_ONLY
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log
#define __CLC_BODY "clc/shared/unary_def.inc"
#include "clc/math/gentype.inc"
#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_BODY "clc/shared/unary_def_scalarize_loop.inc"
#include "clc/math/gentype.inc"

View File

@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// 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_log10.h"
#include "clc/math/clc_mad.h"
#include "clc/relational/clc_isinf.h"
#define __CLC_FUNCTION __clc_log10
#define __CLC_FLOAT_ONLY
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log10
#define __CLC_BODY "clc/shared/unary_def.inc"
#include "clc/math/gentype.inc"
#undef __CLC_IMPL_FUNCTION
#undef __CLC_FLOAT_ONLY
#define __CLC_HALF_ONLY
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log10
#define __CLC_BODY "clc/shared/unary_def.inc"
#include "clc/math/gentype.inc"
#undef __CLC_IMPL_FUNCTION
#undef __CLC_HALF_ONLY
#define COMPILING_LOG10
#define __CLC_DOUBLE_ONLY
#define __CLC_BODY "clc_amdgpu_log.inc"
#include "clc/math/gentype.inc"
#define __CLC_DOUBLE_ONLY
#define __CLC_BODY "clc/shared/unary_def_scalarize_loop.inc"
#include "clc/math/gentype.inc"

View File

@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// 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_log2.h"
#include "clc/math/clc_mad.h"
#include "clc/relational/clc_isinf.h"
#define __CLC_FUNCTION __clc_log2
#define __CLC_FLOAT_ONLY
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log2
#define __CLC_BODY "clc/shared/unary_def.inc"
#include "clc/math/gentype.inc"
#undef __CLC_IMPL_FUNCTION
#undef __CLC_FLOAT_ONLY
#define __CLC_HALF_ONLY
#define __CLC_IMPL_FUNCTION(x) __builtin_elementwise_log2
#define __CLC_BODY "clc/shared/unary_def.inc"
#include "clc/math/gentype.inc"
#undef __CLC_IMPL_FUNCTION
#undef __CLC_HALF_ONLY
#define COMPILING_LOG2
#define __CLC_DOUBLE_ONLY
#define __CLC_BODY "clc_amdgpu_log.inc"
#include "clc/math/gentype.inc"
#define __CLC_DOUBLE_ONLY
#define __CLC_BODY "clc/shared/unary_def_scalarize_loop.inc"
#include "clc/math/gentype.inc"