[libclc] Move native_(exp10|powr|tan) to CLC library (#134080)

These are the three remaining native builtins not yet ported.

There are elementwise versions of exp10 and tan which correspond to the
intrinsics, which may be preferable to the current versions which route
through other native builtins. Those could be changed in a follow-up if
desired.
This commit is contained in:
Fraser Cormack 2025-04-02 17:37:17 +01:00 committed by GitHub
parent 4a4d41e723
commit ddc48fefe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 141 additions and 12 deletions

View File

@ -266,20 +266,22 @@ set_source_files_properties(
# CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_divide.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp10.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log10.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_powr.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_recip.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_rsqrt.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sin.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sqrt.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_tan.cl
# Target-specific CLC builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp2.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp.cl
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_log10.cl
# Target-specific OpenCL builtins
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/r600/math/clc_native_rsqrt.cl
# OpenCL builtins
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_cos.cl

View File

@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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_NATIVE_EXP10_H__
#define __CLC_MATH_CLC_NATIVE_EXP10_H__
#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_exp10
#define __CLC_BODY <clc/shared/unary_decl.inc>
#include <clc/math/gentype.inc>
#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY
#endif // __CLC_MATH_CLC_NATIVE_EXP10_H__

View File

@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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_NATIVE_POWR_H__
#define __CLC_MATH_CLC_NATIVE_POWR_H__
#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_powr
#define __CLC_BODY <clc/shared/binary_decl.inc>
#include <clc/math/gentype.inc>
#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY
#endif // __CLC_MATH_CLC_NATIVE_POWR_H__

View File

@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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_NATIVE_TAN_H__
#define __CLC_MATH_CLC_NATIVE_TAN_H__
#define __FLOAT_ONLY
#define __CLC_FUNCTION __clc_native_tan
#define __CLC_BODY <clc/shared/unary_decl.inc>
#include <clc/math/gentype.inc>
#undef __CLC_BODY
#undef __CLC_FUNCTION
#undef __FLOAT_ONLY
#endif // __CLC_MATH_CLC_NATIVE_TAN_H__

View File

@ -58,14 +58,17 @@ math/clc_nan.cl
math/clc_native_cos.cl
math/clc_native_divide.cl
math/clc_native_exp.cl
math/clc_native_exp10.cl
math/clc_native_exp2.cl
math/clc_native_log.cl
math/clc_native_log10.cl
math/clc_native_log2.cl
math/clc_native_powr.cl
math/clc_native_rsqrt.cl
math/clc_native_recip.cl
math/clc_native_sin.cl
math/clc_native_sqrt.cl
math/clc_native_tan.cl
math/clc_nextafter.cl
math/clc_pow.cl
math/clc_pown.cl

View File

@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// 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/float/definitions.h>
#include <clc/internal/clc.h>
#include <clc/math/clc_native_exp2.h>
#define __FLOAT_ONLY
#define __CLC_BODY <clc_native_exp10.inc>
#include <clc/math/gentype.inc>

View File

@ -6,6 +6,6 @@
//
//===----------------------------------------------------------------------===//
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_exp10(__CLC_GENTYPE val) {
return native_exp2(val * M_LOG210_F);
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_exp10(__CLC_GENTYPE val) {
return __clc_native_exp2(val * M_LOG210_F);
}

View File

@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// 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>
#include <clc/math/clc_native_exp2.h>
#include <clc/math/clc_native_log2.h>
#define __FLOAT_ONLY
#define __CLC_BODY <clc_native_powr.inc>
#include <clc/math/gentype.inc>

View File

@ -6,8 +6,9 @@
//
//===----------------------------------------------------------------------===//
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_powr(__CLC_GENTYPE x, __CLC_GENTYPE y) {
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_powr(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
// x^y == 2^{log2 x^y} == 2^{y * log2 x}
// for x < 0 propagate nan created by log2
return native_exp2(y * native_log2(x));
return __clc_native_exp2(y * __clc_native_log2(x));
}

View File

@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// 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>
#include <clc/math/clc_native_cos.h>
#include <clc/math/clc_native_sin.h>
#define __FLOAT_ONLY
#define __CLC_BODY <clc_native_tan.inc>
#include <clc/math/gentype.inc>

View File

@ -6,6 +6,6 @@
//
//===----------------------------------------------------------------------===//
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_tan(__CLC_GENTYPE val) {
return native_sin(val) / native_cos(val);
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_tan(__CLC_GENTYPE val) {
return __clc_native_sin(val) / __clc_native_cos(val);
}

View File

@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#define __CLC_BODY <clc/math/binary_decl_tt.inc>
#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION native_divide
#include <clc/math/gentype.inc>

View File

@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#define __CLC_BODY <clc/math/binary_decl_tt.inc>
#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION native_powr
#include <clc/math/gentype.inc>

View File

@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
#include <clc/math/clc_native_exp10.h>
#define __CLC_BODY <native_exp10.inc>
#define __FLOAT_ONLY
#define FUNCTION native_exp10
#define __CLC_BODY <clc/shared/unary_def.inc>
#include <clc/math/gentype.inc>

View File

@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
#include <clc/math/clc_native_powr.h>
#define __CLC_BODY <native_powr.inc>
#define __FLOAT_ONLY
#define FUNCTION native_powr
#define __CLC_BODY <clc/shared/binary_def.inc>
#include <clc/math/gentype.inc>

View File

@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
#include <clc/math/clc_native_tan.h>
#define __CLC_BODY <native_tan.inc>
#define __FLOAT_ONLY
#define FUNCTION native_tan
#define __CLC_BODY <clc/shared/unary_def.inc>
#include <clc/math/gentype.inc>