Skip to content

Commit ad48fff

Browse files
authored
[libclc] Move several 'native' builtins to CLC library (llvm#129679)
This commit moves the 'native' builtins that use asm statements to generate LLVM intrinsics to the CLC library. In doing so it converts them to use the appropriate elementwise builtin to generate the same intrinsic; there are no codegen changes to any target except to AMDGPU targets where `native_log` is no longer custom implemented and instead used the clang elementwise builtin. This work forms part of llvm#127196 and indeed with this commit there are no 'generic' builtins using/abusing asm statements - the remaining builtins are specific to the amdgpu and r600 targets.
1 parent 7a2b160 commit ad48fff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+416
-132
lines changed

libclc/CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,23 @@ if ( clspv-- IN_LIST LIBCLC_TARGETS_TO_BUILD OR clspv64-- IN_LIST LIBCLC_TARGETS
263263
endif()
264264

265265
set_source_files_properties(
266+
# CLC builtins
267+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl
268+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp2.cl
269+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_exp.cl
270+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log10.cl
271+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log2.cl
272+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_log.cl
273+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_rsqrt.cl
274+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sin.cl
275+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_sqrt.cl
276+
# Target-specific CLC builtins
277+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp2.cl
278+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_exp.cl
279+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/amdgpu/math/clc_native_log10.cl
280+
# Target-specific OpenCL builtins
281+
${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/r600/math/clc_native_rsqrt.cl
282+
# OpenCL builtins
266283
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_cos.cl
267284
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_divide.cl
268285
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_exp.cl
@@ -277,10 +294,6 @@ set_source_files_properties(
277294
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_sin.cl
278295
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_sqrt.cl
279296
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_tan.cl
280-
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_exp.cl
281-
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_log.cl
282-
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_log10.cl
283-
${CMAKE_CURRENT_SOURCE_DIR}/r600/lib/math/native_rsqrt.cl
284297
PROPERTIES COMPILE_OPTIONS -fapprox-func
285298
)
286299

libclc/amdgpu/lib/SOURCES

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
math/native_exp.cl
2-
math/native_exp2.cl
3-
math/native_log.cl
4-
math/native_log10.cl
51
math/half_exp.cl
62
math/half_exp10.cl
73
math/half_exp2.cl

libclc/amdgpu/lib/math/native_log.inc

Lines changed: 0 additions & 11 deletions
This file was deleted.
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_COS_H__
10+
#define __CLC_MATH_CLC_NATIVE_COS_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_cos
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_COS_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_EXP_H__
10+
#define __CLC_MATH_CLC_NATIVE_EXP_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_exp
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_EXP_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_EXP2_H__
10+
#define __CLC_MATH_CLC_NATIVE_EXP2_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_exp2
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_EXP2_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_LOG_H__
10+
#define __CLC_MATH_CLC_NATIVE_LOG_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_log
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_LOG_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_LOG10_H__
10+
#define __CLC_MATH_CLC_NATIVE_LOG10_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_log10
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_LOG10_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_LOG2_H__
10+
#define __CLC_MATH_CLC_NATIVE_LOG2_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_log2
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_LOG2_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_RSQRT_H__
10+
#define __CLC_MATH_CLC_NATIVE_RSQRT_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_rsqrt
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_RSQRT_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_SIN_H__
10+
#define __CLC_MATH_CLC_NATIVE_SIN_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_sin
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_SIN_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_SQRT_H__
10+
#define __CLC_MATH_CLC_NATIVE_SQRT_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_native_sqrt
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_SQRT_H__

libclc/clc/include/clc/math/unary_intrin.inc

Lines changed: 0 additions & 42 deletions
This file was deleted.

libclc/clc/lib/amdgpu/SOURCES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
math/clc_native_exp2.cl
2+
math/clc_native_exp.cl
3+
math/clc_native_log10.cl
14
math/clc_sqrt_fp64.cl

libclc/amdgpu/lib/math/native_log10.cl renamed to libclc/clc/lib/amdgpu/math/clc_native_exp.cl

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

9-
#include <clc/clc.h>
9+
#include <clc/float/definitions.h>
10+
#include <clc/internal/clc.h>
11+
#include <clc/math/clc_native_exp2.h>
1012

11-
#define __CLC_BODY <native_log10.inc>
13+
#define __CLC_BODY <clc_native_exp.inc>
1214
#define __FLOAT_ONLY
1315
#include <clc/math/gentype.inc>

libclc/amdgpu/lib/math/native_exp.inc renamed to libclc/clc/lib/amdgpu/math/clc_native_exp.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_exp(__CLC_GENTYPE val) {
10-
return native_exp2(val * M_LOG2E_F);
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_exp(__CLC_GENTYPE val) {
10+
return __clc_native_exp2(val * M_LOG2E_F);
1111
}

libclc/amdgpu/lib/math/native_exp2.cl renamed to libclc/clc/lib/amdgpu/math/clc_native_exp2.cl

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

9-
#include <clc/clc.h>
109
#include <clc/clcmacro.h>
10+
#include <clc/internal/clc.h>
1111

12-
_CLC_OVERLOAD _CLC_DEF float native_exp2(float val) {
12+
_CLC_OVERLOAD _CLC_DEF float __clc_native_exp2(float val) {
1313
return __builtin_amdgcn_exp2f(val);
1414
}
1515

16-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, native_exp2, float)
16+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_native_exp2, float)

libclc/amdgpu/lib/math/native_log.cl renamed to libclc/clc/lib/amdgpu/math/clc_native_log10.cl

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

9-
#include <clc/clc.h>
9+
#include <clc/float/definitions.h>
10+
#include <clc/internal/clc.h>
11+
#include <clc/math/clc_native_log2.h>
1012

11-
#define __CLC_BODY <native_log.inc>
13+
#define __CLC_BODY <clc_native_log10.inc>
1214
#define __FLOAT_ONLY
1315
#include <clc/math/gentype.inc>

libclc/amdgpu/lib/math/native_log10.inc renamed to libclc/clc/lib/amdgpu/math/clc_native_log10.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_log10(__CLC_GENTYPE val) {
10-
return native_log2(val) * (M_LN2_F / M_LN10_F);
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_log10(__CLC_GENTYPE val) {
10+
return __clc_native_log2(val) * (M_LN2_F / M_LN10_F);
1111
}

libclc/clc/lib/generic/SOURCES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ math/clc_log2.cl
4545
math/clc_mad.cl
4646
math/clc_modf.cl
4747
math/clc_nan.cl
48+
math/clc_native_cos.cl
49+
math/clc_native_exp.cl
50+
math/clc_native_exp2.cl
51+
math/clc_native_log.cl
52+
math/clc_native_log10.cl
53+
math/clc_native_log2.cl
54+
math/clc_native_rsqrt.cl
55+
math/clc_native_sin.cl
56+
math/clc_native_sqrt.cl
4857
math/clc_nextafter.cl
4958
math/clc_pow.cl
5059
math/clc_pown.cl

0 commit comments

Comments
 (0)