Skip to content

Commit 7441e87

Browse files
authored
[libclc] Move several integer functions to CLC library (llvm#116786)
This commit moves over the OpenCL clz, hadd, mad24, mad_hi, mul24, mul_hi, popcount, rhadd, and upsample builtins to the CLC library. This commit also optimizes the vector forms of the mul_hi and upsample builtins to consistently remain in vector types, instead of recursively splitting vectors down to the scalar form. The OpenCL mad_hi builtin wasn't previously publicly available from the CLC libraries, as it was hash-defined to mul_hi in the header files. That issue has been fixed, and mad_hi is now exposed. The custom AMD implementation/workaround for popcount has been removed as it was only required for clang < 7. There are still two integer functions which haven't been moved over. The OpenCL mad_sat builtin uses many of the other integer builtins, and would benefit from optimization for vector types. That can take place in a follow-up commit. The rotate builtin could similarly use some more dedicated focus, potentially using clang builtins.
1 parent cf37ae5 commit 7441e87

Some content is hidden

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

73 files changed

+726
-297
lines changed

libclc/amdgcn/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cl_khr_int64_extended_atomics/minmax_helpers.ll
2-
integer/popcount.cl
32
math/fmax.cl
43
math/fmin.cl
54
math/ldexp.cl

libclc/amdgcn/lib/integer/popcount.cl

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

libclc/amdgcn/lib/integer/popcount.inc

Lines changed: 0 additions & 17 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_INTEGER_CLC_CLZ_H__
2+
#define __CLC_INTEGER_CLC_CLZ_H__
3+
4+
#define __CLC_FUNCTION __clc_clz
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_CLZ_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_HADD_H__
2+
#define __CLC_INTEGER_CLC_HADD_H__
3+
4+
#define __CLC_FUNCTION __clc_hadd
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_HADD_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_MAD24_H__
2+
#define __CLC_INTEGER_CLC_MAD24_H__
3+
4+
#define __CLC_FUNCTION __clc_mad24
5+
#define __CLC_BODY <clc/shared/ternary_decl.inc>
6+
7+
#include <clc/integer/gentype24.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_MAD24_H__
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef __CLC_INTEGER_CLC_MAD_HI_H__
2+
#define __CLC_INTEGER_CLC_MAD_HI_H__
3+
4+
#include <clc/integer/clc_mul_hi.h>
5+
6+
#define __clc_mad_hi(a, b, c) (__clc_mul_hi((a), (b)) + (c))
7+
8+
#endif // __CLC_INTEGER_CLC_MAD_HI_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_MUL24_H__
2+
#define __CLC_INTEGER_CLC_MUL24_H__
3+
4+
#define __CLC_FUNCTION __clc_mul24
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype24.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_MUL24_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_MUL_HI_H__
2+
#define __CLC_INTEGER_CLC_MUL_HI_H__
3+
4+
#define __CLC_FUNCTION __clc_mul_hi
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_MUL_HI_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_POPCOUNT_H__
2+
#define __CLC_INTEGER_CLC_POPCOUNT_H__
3+
4+
#define __CLC_FUNCTION __clc_popcount
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_INTRINSIC
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_POPCOUNT_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_RHADD_H__
2+
#define __CLC_INTEGER_CLC_RHADD_H__
3+
4+
#define __CLC_FUNCTION __clc_rhadd
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_RHADD_H__
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef __CLC_INTEGER_CLC_UPSAMPLE_H__
2+
#define __CLC_INTEGER_CLC_UPSAMPLE_H__
3+
4+
#include <clc/clcfunc.h>
5+
#include <clc/clctypes.h>
6+
7+
#define __CLC_UPSAMPLE_DECL(BGENTYPE, GENTYPE, UGENTYPE) \
8+
_CLC_OVERLOAD _CLC_DECL BGENTYPE __clc_upsample(GENTYPE hi, UGENTYPE lo);
9+
10+
#define __CLC_UPSAMPLE_VEC(BGENTYPE, GENTYPE, UGENTYPE) \
11+
__CLC_UPSAMPLE_DECL(BGENTYPE, GENTYPE, UGENTYPE) \
12+
__CLC_UPSAMPLE_DECL(BGENTYPE##2, GENTYPE##2, UGENTYPE##2) \
13+
__CLC_UPSAMPLE_DECL(BGENTYPE##3, GENTYPE##3, UGENTYPE##3) \
14+
__CLC_UPSAMPLE_DECL(BGENTYPE##4, GENTYPE##4, UGENTYPE##4) \
15+
__CLC_UPSAMPLE_DECL(BGENTYPE##8, GENTYPE##8, UGENTYPE##8) \
16+
__CLC_UPSAMPLE_DECL(BGENTYPE##16, GENTYPE##16, UGENTYPE##16)
17+
18+
#define __CLC_UPSAMPLE_TYPES() \
19+
__CLC_UPSAMPLE_VEC(short, char, uchar) \
20+
__CLC_UPSAMPLE_VEC(ushort, uchar, uchar) \
21+
__CLC_UPSAMPLE_VEC(int, short, ushort) \
22+
__CLC_UPSAMPLE_VEC(uint, ushort, ushort) \
23+
__CLC_UPSAMPLE_VEC(long, int, uint) \
24+
__CLC_UPSAMPLE_VEC(ulong, uint, uint)
25+
26+
__CLC_UPSAMPLE_TYPES()
27+
28+
#undef __CLC_UPSAMPLE_TYPES
29+
#undef __CLC_UPSAMPLE_DECL
30+
#undef __CLC_UPSAMPLE_VEC
31+
32+
#endif // __CLC_INTEGER_CLC_UPSAMPLE_H__

libclc/generic/include/clc/integer/definitions.h renamed to libclc/clc/include/clc/integer/definitions.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#ifndef __CLC_INTEGER_DEFINITIONS_H__
2+
#define __CLC_INTEGER_DEFINITIONS_H__
3+
14
#define CHAR_BIT 8
25
#define INT_MAX 2147483647
36
#define INT_MIN (-2147483647 - 1)
4-
#define LONG_MAX 0x7fffffffffffffffL
7+
#define LONG_MAX 0x7fffffffffffffffL
58
#define LONG_MIN (-0x7fffffffffffffffL - 1)
69
#define CHAR_MAX SCHAR_MAX
710
#define CHAR_MIN SCHAR_MIN
@@ -13,3 +16,5 @@
1316
#define USHRT_MAX 65535
1417
#define UINT_MAX 0xffffffff
1518
#define ULONG_MAX 0xffffffffffffffffUL
19+
20+
#endif // __CLC_INTEGER_DEFINITIONS_H__
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#include <clc/clcfunc.h>
2+
#include <clc/clctypes.h>
3+
4+
#define __CLC_GENSIZE 32
5+
#undef __CLC_SCALAR_GENTYPE
6+
#define __CLC_SCALAR_GENTYPE int
7+
8+
#define __CLC_GENTYPE int
9+
#define __CLC_U_GENTYPE uint
10+
#define __CLC_S_GENTYPE int
11+
#define __CLC_SCALAR 1
12+
#define __CLC_VECSIZE
13+
#include __CLC_BODY
14+
#undef __CLC_VECSIZE
15+
#undef __CLC_SCALAR
16+
#undef __CLC_GENTYPE
17+
#undef __CLC_U_GENTYPE
18+
#undef __CLC_S_GENTYPE
19+
20+
#define __CLC_GENTYPE int2
21+
#define __CLC_U_GENTYPE uint2
22+
#define __CLC_S_GENTYPE int2
23+
#define __CLC_VECSIZE 2
24+
#include __CLC_BODY
25+
#undef __CLC_VECSIZE
26+
#undef __CLC_GENTYPE
27+
#undef __CLC_U_GENTYPE
28+
#undef __CLC_S_GENTYPE
29+
30+
#define __CLC_GENTYPE int3
31+
#define __CLC_U_GENTYPE uint3
32+
#define __CLC_S_GENTYPE int3
33+
#define __CLC_VECSIZE 3
34+
#include __CLC_BODY
35+
#undef __CLC_VECSIZE
36+
#undef __CLC_GENTYPE
37+
#undef __CLC_U_GENTYPE
38+
#undef __CLC_S_GENTYPE
39+
40+
#define __CLC_GENTYPE int4
41+
#define __CLC_U_GENTYPE uint4
42+
#define __CLC_S_GENTYPE int4
43+
#define __CLC_VECSIZE 4
44+
#include __CLC_BODY
45+
#undef __CLC_VECSIZE
46+
#undef __CLC_GENTYPE
47+
#undef __CLC_U_GENTYPE
48+
#undef __CLC_S_GENTYPE
49+
50+
#define __CLC_GENTYPE int8
51+
#define __CLC_U_GENTYPE uint8
52+
#define __CLC_S_GENTYPE int8
53+
#define __CLC_VECSIZE 8
54+
#include __CLC_BODY
55+
#undef __CLC_VECSIZE
56+
#undef __CLC_GENTYPE
57+
#undef __CLC_U_GENTYPE
58+
#undef __CLC_S_GENTYPE
59+
60+
#define __CLC_GENTYPE int16
61+
#define __CLC_U_GENTYPE uint16
62+
#define __CLC_S_GENTYPE int16
63+
#define __CLC_VECSIZE 16
64+
#include __CLC_BODY
65+
#undef __CLC_VECSIZE
66+
#undef __CLC_GENTYPE
67+
#undef __CLC_U_GENTYPE
68+
#undef __CLC_S_GENTYPE
69+
70+
#undef __CLC_SCALAR_GENTYPE
71+
#define __CLC_SCALAR_GENTYPE uint
72+
73+
#define __CLC_GENTYPE uint
74+
#define __CLC_U_GENTYPE uint
75+
#define __CLC_S_GENTYPE int
76+
#define __CLC_SCALAR 1
77+
#define __CLC_VECSIZE
78+
#include __CLC_BODY
79+
#undef __CLC_VECSIZE
80+
#undef __CLC_SCALAR
81+
#undef __CLC_GENTYPE
82+
#undef __CLC_U_GENTYPE
83+
#undef __CLC_S_GENTYPE
84+
85+
#define __CLC_GENTYPE uint2
86+
#define __CLC_U_GENTYPE uint2
87+
#define __CLC_S_GENTYPE int2
88+
#define __CLC_VECSIZE 2
89+
#include __CLC_BODY
90+
#undef __CLC_VECSIZE
91+
#undef __CLC_GENTYPE
92+
#undef __CLC_U_GENTYPE
93+
#undef __CLC_S_GENTYPE
94+
95+
#define __CLC_GENTYPE uint3
96+
#define __CLC_U_GENTYPE uint3
97+
#define __CLC_S_GENTYPE int3
98+
#define __CLC_VECSIZE 3
99+
#include __CLC_BODY
100+
#undef __CLC_VECSIZE
101+
#undef __CLC_GENTYPE
102+
#undef __CLC_U_GENTYPE
103+
#undef __CLC_S_GENTYPE
104+
105+
#define __CLC_GENTYPE uint4
106+
#define __CLC_U_GENTYPE uint4
107+
#define __CLC_S_GENTYPE int4
108+
#define __CLC_VECSIZE 4
109+
#include __CLC_BODY
110+
#undef __CLC_VECSIZE
111+
#undef __CLC_GENTYPE
112+
#undef __CLC_U_GENTYPE
113+
#undef __CLC_S_GENTYPE
114+
115+
#define __CLC_GENTYPE uint8
116+
#define __CLC_U_GENTYPE uint8
117+
#define __CLC_S_GENTYPE int8
118+
#define __CLC_VECSIZE 8
119+
#include __CLC_BODY
120+
#undef __CLC_VECSIZE
121+
#undef __CLC_GENTYPE
122+
#undef __CLC_U_GENTYPE
123+
#undef __CLC_S_GENTYPE
124+
125+
#define __CLC_GENTYPE uint16
126+
#define __CLC_U_GENTYPE uint16
127+
#define __CLC_S_GENTYPE int16
128+
#define __CLC_VECSIZE 16
129+
#include __CLC_BODY
130+
#undef __CLC_VECSIZE
131+
#undef __CLC_GENTYPE
132+
#undef __CLC_U_GENTYPE
133+
#undef __CLC_S_GENTYPE
134+
135+
#undef __CLC_GENSIZE
136+
#undef __CLC_SCALAR_GENTYPE
137+
#undef __CLC_BODY

libclc/clc/include/clc/math/clc_mad.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __CLC_MATH_CLC_MAD_H__
22
#define __CLC_MATH_CLC_MAD_H__
33

4-
#define __CLC_BODY <clc/math/ternary_decl.inc>
4+
#define __CLC_BODY <clc/shared/ternary_decl.inc>
55
#define __CLC_FUNCTION __clc_mad
66

77
#include <clc/math/gentype.inc>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <clc/utils.h>
2+
3+
#ifndef __CLC_FUNCTION
4+
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
5+
#endif
6+
7+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a, __CLC_GENTYPE b,
8+
__CLC_GENTYPE c) {
9+
return __CLC_FUNCTION(FUNCTION)(a, b, c);
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <clc/utils.h>
2+
3+
#ifndef __CLC_FUNCTION
4+
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
5+
#endif
6+
7+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a) {
8+
return __CLC_FUNCTION(FUNCTION)(a);
9+
}

libclc/clc/lib/clspv/SOURCES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
../generic/integer/clc_add_sat.cl
2+
../generic/integer/clc_clz.cl
3+
../generic/integer/clc_hadd.cl
4+
../generic/integer/clc_mad24.cl
5+
../generic/integer/clc_mul24.cl
6+
../generic/integer/clc_mul_hi.cl
7+
../generic/integer/clc_popcount.cl
8+
../generic/integer/clc_rhadd.cl
29
../generic/integer/clc_sub_sat.cl
10+
../generic/integer/clc_upsample.cl
311
../generic/math/clc_ceil.cl
412
../generic/math/clc_copysign.cl
513
../generic/math/clc_fabs.cl

libclc/clc/lib/generic/SOURCES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ geometric/clc_dot.cl
55
integer/clc_abs.cl
66
integer/clc_abs_diff.cl
77
integer/clc_add_sat.cl
8+
integer/clc_clz.cl
9+
integer/clc_hadd.cl
10+
integer/clc_mad24.cl
11+
integer/clc_mul24.cl
12+
integer/clc_mul_hi.cl
13+
integer/clc_popcount.cl
14+
integer/clc_rhadd.cl
815
integer/clc_sub_sat.cl
16+
integer/clc_upsample.cl
917
math/clc_ceil.cl
1018
math/clc_copysign.cl
1119
math/clc_fabs.cl

0 commit comments

Comments
 (0)