Skip to content

Commit 4ba508a

Browse files
committed
[libclc] Move several 'native' builtins to CLC library
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. This work forms part of #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 a32d543 commit 4ba508a

Some content is hidden

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

41 files changed

+209
-132
lines changed

libclc/amdgpu/lib/SOURCES

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
math/native_exp.cl
2-
math/native_log.cl
3-
math/native_log10.cl
41
math/half_exp.cl
52
math/half_exp10.cl
63
math/half_exp2.cl

libclc/amdgpu/lib/math/native_exp.cl

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

libclc/amdgpu/lib/math/native_exp.inc

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

libclc/amdgpu/lib/math/native_log.cl

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

libclc/amdgpu/lib/math/native_log.inc

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

libclc/amdgpu/lib/math/native_log10.cl

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

libclc/amdgpu/lib/math/native_log10.inc

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_COS_H__
2+
#define __CLC_MATH_CLC_NATIVE_COS_H__
3+
4+
#define __CLC_FUNCTION __clc_native_cos
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_COS_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_EXP_H__
2+
#define __CLC_MATH_CLC_NATIVE_EXP_H__
3+
4+
#define __CLC_FUNCTION __clc_native_exp
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_EXP_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_EXP2_H__
2+
#define __CLC_MATH_CLC_NATIVE_EXP2_H__
3+
4+
#define __CLC_FUNCTION __clc_native_exp2
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_EXP2_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_LOG_H__
2+
#define __CLC_MATH_CLC_NATIVE_LOG_H__
3+
4+
#define __CLC_FUNCTION __clc_native_log
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_LOG_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_LOG10_H__
2+
#define __CLC_MATH_CLC_NATIVE_LOG10_H__
3+
4+
#define __CLC_FUNCTION __clc_native_log10
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_LOG10_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_LOG2_H__
2+
#define __CLC_MATH_CLC_NATIVE_LOG2_H__
3+
4+
#define __CLC_FUNCTION __clc_native_log2
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_LOG2_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_SIN_H__
2+
#define __CLC_MATH_CLC_NATIVE_SIN_H__
3+
4+
#define __CLC_FUNCTION __clc_native_sin
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_SIN_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_NATIVE_SQRT_H__
2+
#define __CLC_MATH_CLC_NATIVE_SQRT_H__
3+
4+
#define __CLC_FUNCTION __clc_native_sqrt
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_NATIVE_SQRT_H__

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

Lines changed: 0 additions & 34 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_log10.cl
2+
math/clc_native_log.cl
3+
math/clc_native_exp.cl
14
math/clc_sqrt_fp64.cl
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <clc/float/definitions.h>
2+
#include <clc/internal/clc.h>
3+
#include <clc/math/clc_native_exp2.h>
4+
5+
#define __CLC_BODY <clc_native_exp.inc>
6+
#define __FLOAT_ONLY
7+
#include <clc/math/gentype.inc>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_exp(__CLC_GENTYPE val) {
2+
return __clc_native_exp2(val * M_LOG2E_F);
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <clc/float/definitions.h>
2+
#include <clc/internal/clc.h>
3+
#include <clc/math/clc_native_log2.h>
4+
5+
#define __CLC_BODY <clc_native_log.inc>
6+
#define __FLOAT_ONLY
7+
#include <clc/math/gentype.inc>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_log(__CLC_GENTYPE val) {
2+
return __clc_native_log2(val) * (1.0f / M_LOG2E_F);
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <clc/float/definitions.h>
2+
#include <clc/internal/clc.h>
3+
#include <clc/math/clc_native_log2.h>
4+
5+
#define __CLC_BODY <clc_native_log10.inc>
6+
#define __FLOAT_ONLY
7+
#include <clc/math/gentype.inc>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_native_log10(__CLC_GENTYPE val) {
2+
return __clc_native_log2(val) * (M_LN2_F / M_LN10_F);
3+
}

libclc/clc/lib/generic/SOURCES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ math/clc_log2.cl
3030
math/clc_mad.cl
3131
math/clc_modf.cl
3232
math/clc_nan.cl
33+
math/clc_native_cos.cl
34+
math/clc_native_exp.cl
35+
math/clc_native_exp2.cl
36+
math/clc_native_log.cl
37+
math/clc_native_log10.cl
38+
math/clc_native_log2.cl
39+
math/clc_native_sin.cl
40+
math/clc_native_sqrt.cl
3341
math/clc_nextafter.cl
3442
math/clc_rint.cl
3543
math/clc_round.cl
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_cos
5+
#define __CLC_BUILTIN __builtin_elementwise_cos
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_exp
5+
#define __CLC_BUILTIN __builtin_elementwise_exp
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_exp2
5+
#define __CLC_BUILTIN __builtin_elementwise_exp2
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_log
5+
#define __CLC_BUILTIN __builtin_elementwise_log
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_log10
5+
#define __CLC_BUILTIN __builtin_elementwise_log10
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_log2
5+
#define __CLC_BUILTIN __builtin_elementwise_log2
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_sin
5+
#define __CLC_BUILTIN __builtin_elementwise_sin
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <clc/internal/clc.h>
2+
3+
#undef __CLC_FUNCTION
4+
#define __CLC_FUNCTION __clc_native_sqrt
5+
#define __CLC_BUILTIN __builtin_elementwise_sqrt
6+
#include <clc/math/unary_builtin.inc>

libclc/generic/lib/math/native_cos.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <clc/clc.h>
2+
#include <clc/math/clc_native_cos.h>
23

3-
#define __CLC_NATIVE_INTRINSIC cos
4-
5-
#define __CLC_BODY <native_unary_intrinsic.inc>
64
#define __FLOAT_ONLY
7-
#include <clc/math/gentype.inc>
5+
#define __CLC_FUNCTION native_cos
6+
#include <clc/math/unary_builtin.inc>

libclc/generic/lib/math/native_exp.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <clc/clc.h>
2+
#include <clc/math/clc_native_exp.h>
23

3-
#define __CLC_NATIVE_INTRINSIC exp
4-
5-
#define __CLC_BODY <native_unary_intrinsic.inc>
64
#define __FLOAT_ONLY
7-
#include <clc/math/gentype.inc>
5+
#define __CLC_FUNCTION native_exp
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <clc/clc.h>
2+
#include <clc/math/clc_native_exp2.h>
23

3-
#define __CLC_NATIVE_INTRINSIC exp2
4-
5-
#define __CLC_BODY <native_unary_intrinsic.inc>
64
#define __FLOAT_ONLY
7-
#include <clc/math/gentype.inc>
5+
#define __CLC_FUNCTION native_exp2
6+
#include <clc/math/unary_builtin.inc>

libclc/generic/lib/math/native_log.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
*/
2222

2323
#include <clc/clc.h>
24+
#include <clc/math/clc_native_log.h>
2425

25-
#define __CLC_NATIVE_INTRINSIC log
26-
27-
#define __CLC_BODY <native_unary_intrinsic.inc>
2826
#define __FLOAT_ONLY
29-
#include <clc/math/gentype.inc>
27+
#define __CLC_FUNCTION native_log
28+
#include <clc/math/unary_builtin.inc>
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <clc/clc.h>
2+
#include <clc/math/clc_native_log10.h>
23

3-
#define __CLC_NATIVE_INTRINSIC log10
4-
5-
#define __CLC_BODY <native_unary_intrinsic.inc>
64
#define __FLOAT_ONLY
7-
#include <clc/math/gentype.inc>
5+
#define __CLC_FUNCTION native_log10
6+
#include <clc/math/unary_builtin.inc>

libclc/generic/lib/math/native_log2.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222

2323
#include <clc/clc.h>
24+
#include <clc/math/clc_native_log2.h>
2425

25-
#define __CLC_NATIVE_INTRINSIC log2
26-
#define __CLC_BODY <native_unary_intrinsic.inc>
2726
#define __FLOAT_ONLY
28-
#include <clc/math/gentype.inc>
27+
#define __CLC_FUNCTION native_log2
28+
#include <clc/math/unary_builtin.inc>

libclc/generic/lib/math/native_sin.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <clc/clc.h>
2+
#include <clc/math/clc_native_sin.h>
23

3-
#define __CLC_NATIVE_INTRINSIC sin
4-
5-
#define __CLC_BODY <native_unary_intrinsic.inc>
64
#define __FLOAT_ONLY
7-
#include <clc/math/gentype.inc>
5+
#define __CLC_FUNCTION native_sin
6+
#include <clc/math/unary_builtin.inc>
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <clc/clc.h>
2+
#include <clc/math/clc_native_sqrt.h>
23

3-
#define __CLC_NATIVE_INTRINSIC sqrt
4-
5-
#define __CLC_BODY <native_unary_intrinsic.inc>
64
#define __FLOAT_ONLY
7-
#include <clc/math/gentype.inc>
5+
#define __CLC_FUNCTION native_sqrt
6+
#include <clc/math/unary_builtin.inc>

0 commit comments

Comments
 (0)