Skip to content

Commit ddc48fe

Browse files
authored
[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.
1 parent 4a4d41e commit ddc48fe

16 files changed

+141
-12
lines changed

libclc/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,20 +266,22 @@ set_source_files_properties(
266266
# CLC builtins
267267
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
268268
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_divide.cl
269+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp10.cl
269270
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp2.cl
270271
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp.cl
271272
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log10.cl
272273
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log2.cl
273274
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log.cl
275+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_powr.cl
274276
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_recip.cl
275277
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_rsqrt.cl
276278
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sin.cl
277279
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sqrt.cl
280+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_tan.cl
278281
# Target-specific CLC builtins
279282
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp2.cl
280283
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp.cl
281284
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_log10.cl
282-
# Target-specific OpenCL builtins
283285
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/r600/math/clc_native_rsqrt.cl
284286
# OpenCL builtins
285287
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_cos.cl
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_MATH_CLC_NATIVE_EXP10_H__
10+
#define __CLC_MATH_CLC_NATIVE_EXP10_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_exp10
14+
#define __CLC_BODY <clc/shared/unary_decl.inc>
15+
16+
#include <clc/math/gentype.inc>
17+
18+
#undef __CLC_BODY
19+
#undef __CLC_FUNCTION
20+
#undef __FLOAT_ONLY
21+
22+
#endif // __CLC_MATH_CLC_NATIVE_EXP10_H__
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_MATH_CLC_NATIVE_POWR_H__
10+
#define __CLC_MATH_CLC_NATIVE_POWR_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_powr
14+
#define __CLC_BODY <clc/shared/binary_decl.inc>
15+
16+
#include <clc/math/gentype.inc>
17+
18+
#undef __CLC_BODY
19+
#undef __CLC_FUNCTION
20+
#undef __FLOAT_ONLY
21+
22+
#endif // __CLC_MATH_CLC_NATIVE_POWR_H__
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_MATH_CLC_NATIVE_TAN_H__
10+
#define __CLC_MATH_CLC_NATIVE_TAN_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_tan
14+
#define __CLC_BODY <clc/shared/unary_decl.inc>
15+
16+
#include <clc/math/gentype.inc>
17+
18+
#undef __CLC_BODY
19+
#undef __CLC_FUNCTION
20+
#undef __FLOAT_ONLY
21+
22+
#endif // __CLC_MATH_CLC_NATIVE_TAN_H__

libclc/clc/lib/generic/SOURCES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ math/clc_nan.cl
5858
math/clc_native_cos.cl
5959
math/clc_native_divide.cl
6060
math/clc_native_exp.cl
61+
math/clc_native_exp10.cl
6162
math/clc_native_exp2.cl
6263
math/clc_native_log.cl
6364
math/clc_native_log10.cl
6465
math/clc_native_log2.cl
66+
math/clc_native_powr.cl
6567
math/clc_native_rsqrt.cl
6668
math/clc_native_recip.cl
6769
math/clc_native_sin.cl
6870
math/clc_native_sqrt.cl
71+
math/clc_native_tan.cl
6972
math/clc_nextafter.cl
7073
math/clc_pow.cl
7174
math/clc_pown.cl
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/float/definitions.h>
10+
#include <clc/internal/clc.h>
11+
#include <clc/math/clc_native_exp2.h>
12+
13+
#define __FLOAT_ONLY
14+
#define __CLC_BODY <clc_native_exp10.inc>
15+
16+
#include <clc/math/gentype.inc>

libclc/generic/lib/math/native_exp10.inc renamed to libclc/clc/lib/generic/math/clc_native_exp10.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_exp10(__CLC_GENTYPE val) {
10-
return native_exp2(val * M_LOG210_F);
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_exp10(__CLC_GENTYPE val) {
10+
return __clc_native_exp2(val * M_LOG210_F);
1111
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_native_exp2.h>
11+
#include <clc/math/clc_native_log2.h>
12+
13+
#define __FLOAT_ONLY
14+
#define __CLC_BODY <clc_native_powr.inc>
15+
16+
#include <clc/math/gentype.inc>

libclc/generic/lib/math/native_powr.inc renamed to libclc/clc/lib/generic/math/clc_native_powr.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_powr(__CLC_GENTYPE x, __CLC_GENTYPE y) {
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_powr(__CLC_GENTYPE x,
10+
__CLC_GENTYPE y) {
1011
// x^y == 2^{log2 x^y} == 2^{y * log2 x}
1112
// for x < 0 propagate nan created by log2
12-
return native_exp2(y * native_log2(x));
13+
return __clc_native_exp2(y * __clc_native_log2(x));
1314
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_native_cos.h>
11+
#include <clc/math/clc_native_sin.h>
12+
13+
#define __FLOAT_ONLY
14+
#define __CLC_BODY <clc_native_tan.inc>
15+
16+
#include <clc/math/gentype.inc>

libclc/generic/lib/math/native_tan.inc renamed to libclc/clc/lib/generic/math/clc_native_tan.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_tan(__CLC_GENTYPE val) {
10-
return native_sin(val) / native_cos(val);
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_tan(__CLC_GENTYPE val) {
10+
return __clc_native_sin(val) / __clc_native_cos(val);
1111
}

libclc/generic/include/clc/math/native_divide.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#define __CLC_BODY <clc/math/binary_decl_tt.inc>
9+
#define __CLC_BODY <clc/shared/binary_decl.inc>
1010
#define __CLC_FUNCTION native_divide
1111

1212
#include <clc/math/gentype.inc>

libclc/generic/include/clc/math/native_powr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#define __CLC_BODY <clc/math/binary_decl_tt.inc>
9+
#define __CLC_BODY <clc/shared/binary_decl.inc>
1010
#define __CLC_FUNCTION native_powr
1111

1212
#include <clc/math/gentype.inc>

libclc/generic/lib/math/native_exp10.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc.h>
10+
#include <clc/math/clc_native_exp10.h>
1011

11-
#define __CLC_BODY <native_exp10.inc>
1212
#define __FLOAT_ONLY
13+
#define FUNCTION native_exp10
14+
#define __CLC_BODY <clc/shared/unary_def.inc>
15+
1316
#include <clc/math/gentype.inc>

libclc/generic/lib/math/native_powr.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc.h>
10+
#include <clc/math/clc_native_powr.h>
1011

11-
#define __CLC_BODY <native_powr.inc>
1212
#define __FLOAT_ONLY
13+
#define FUNCTION native_powr
14+
#define __CLC_BODY <clc/shared/binary_def.inc>
15+
1316
#include <clc/math/gentype.inc>

libclc/generic/lib/math/native_tan.cl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc.h>
10+
#include <clc/math/clc_native_tan.h>
1011

11-
#define __CLC_BODY <native_tan.inc>
1212
#define __FLOAT_ONLY
13+
#define FUNCTION native_tan
14+
#define __CLC_BODY <clc/shared/unary_def.inc>
15+
1316
#include <clc/math/gentype.inc>

0 commit comments

Comments
 (0)