Skip to content

Commit 65713ca

Browse files
committed
[libclc] Move several integer functions to CLC library
This commit moves over the OpenCL clz, hadd, mad24, mad_hi, mul24, mul_hi, popcount, rhadd, and upsample builtins to the CLC library. There are no changes to any target's CLC libraries. 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 valid for clang < 7. There are still two integer functions which haven't been moved over. The OpenCL add_sat, sub_sat, and mad_sat builtins require saturating conversion builtins which haven't yet been ported.
1 parent e0a79ee commit 65713ca

Some content is hidden

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

68 files changed

+780
-301
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
2+
__CLC_GENTYPE y);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __CLC_INTEGER_CLC_CLZ_H__
2+
#define __CLC_INTEGER_CLC_CLZ_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible clz
6+
#define __clc_clz clz
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
#include <clc/clctypes.h>
11+
12+
#define FUNCTION __clc_clz
13+
#define __CLC_BODY "unary_decl.h"
14+
15+
#include <clc/integer/gentype.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif
20+
21+
#endif // __CLC_INTEGER_CLC_CLZ_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __CLC_INTEGER_CLC_HADD_H__
2+
#define __CLC_INTEGER_CLC_HADD_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible hadd
6+
#define __clc_hadd hadd
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
#include <clc/clctypes.h>
11+
12+
#define FUNCTION __clc_hadd
13+
#define __CLC_BODY "binary_decl.h"
14+
15+
#include <clc/integer/gentype.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif
20+
21+
#endif // __CLC_INTEGER_CLC_HADD_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __CLC_INTEGER_CLC_MAD24_H__
2+
#define __CLC_INTEGER_CLC_MAD24_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible mad24
6+
#define __clc_mad24 mad24
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
#include <clc/clctypes.h>
11+
12+
#define FUNCTION __clc_mad24
13+
#define __CLC_BODY "ternary_decl.h"
14+
15+
#include <clc/integer/gentype24.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif
20+
21+
#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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __CLC_INTEGER_CLC_MUL24_H__
2+
#define __CLC_INTEGER_CLC_MUL24_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible mul24
6+
#define __clc_mul24 mul24
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
#include <clc/clctypes.h>
11+
12+
#define FUNCTION __clc_mul24
13+
#define __CLC_BODY "binary_decl.h"
14+
15+
#include <clc/integer/gentype24.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif
20+
21+
#endif // __CLC_INTEGER_CLC_MUL24_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __CLC_INTEGER_CLC_MUL_HI_H__
2+
#define __CLC_INTEGER_CLC_MUL_HI_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible mul_hi
6+
#define __clc_mul_hi mul_hi
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
#include <clc/clctypes.h>
11+
12+
#define FUNCTION __clc_mul_hi
13+
#define __CLC_BODY "binary_decl.h"
14+
15+
#include <clc/integer/gentype.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif
20+
21+
#endif // __CLC_INTEGER_CLC_MUL_HI_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_INTEGER_CLC_POPCOUNT_H__
2+
#define __CLC_INTEGER_CLC_POPCOUNT_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible popcount
6+
#define __clc_popcount popcount
7+
#else
8+
9+
// Map the function to an LLVM intrinsic
10+
#define __CLC_FUNCTION __clc_popcount
11+
#define __CLC_INTRINSIC "llvm.ctpop"
12+
#include <clc/integer/unary_intrin.inc>
13+
14+
#undef __CLC_INTRINSIC
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_INTEGER_CLC_POPCOUNT_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __CLC_INTEGER_CLC_RHADD_H__
2+
#define __CLC_INTEGER_CLC_RHADD_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible rhadd
6+
#define __clc_rhadd rhadd
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
#include <clc/clctypes.h>
11+
12+
#define FUNCTION __clc_rhadd
13+
#define __CLC_BODY "binary_decl.h"
14+
15+
#include <clc/integer/gentype.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif
20+
21+
#endif // __CLC_INTEGER_CLC_RHADD_H__
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef __CLC_INTEGER_CLC_UPSAMPLE_H__
2+
#define __CLC_INTEGER_CLC_UPSAMPLE_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible upsample
6+
#define __clc_upsample upsample
7+
#else
8+
9+
#include <clc/clctypes.h>
10+
11+
#define __CLC_UPSAMPLE_DECL(BGENTYPE, GENTYPE, UGENTYPE) \
12+
_CLC_OVERLOAD _CLC_DECL BGENTYPE __clc_upsample(GENTYPE hi, UGENTYPE lo);
13+
14+
#define __CLC_UPSAMPLE_VEC(BGENTYPE, GENTYPE, UGENTYPE) \
15+
__CLC_UPSAMPLE_DECL(BGENTYPE, GENTYPE, UGENTYPE) \
16+
__CLC_UPSAMPLE_DECL(BGENTYPE##2, GENTYPE##2, UGENTYPE##2) \
17+
__CLC_UPSAMPLE_DECL(BGENTYPE##3, GENTYPE##3, UGENTYPE##3) \
18+
__CLC_UPSAMPLE_DECL(BGENTYPE##4, GENTYPE##4, UGENTYPE##4) \
19+
__CLC_UPSAMPLE_DECL(BGENTYPE##8, GENTYPE##8, UGENTYPE##8) \
20+
__CLC_UPSAMPLE_DECL(BGENTYPE##16, GENTYPE##16, UGENTYPE##16)
21+
22+
#define __CLC_UPSAMPLE_TYPES() \
23+
__CLC_UPSAMPLE_VEC(short, char, uchar) \
24+
__CLC_UPSAMPLE_VEC(ushort, uchar, uchar) \
25+
__CLC_UPSAMPLE_VEC(int, short, ushort) \
26+
__CLC_UPSAMPLE_VEC(uint, ushort, ushort) \
27+
__CLC_UPSAMPLE_VEC(long, int, uint) \
28+
__CLC_UPSAMPLE_VEC(ulong, uint, uint)
29+
30+
__CLC_UPSAMPLE_TYPES()
31+
32+
#undef __CLC_UPSAMPLE_TYPES
33+
#undef __CLC_UPSAMPLE_DECL
34+
#undef __CLC_UPSAMPLE_VEC
35+
36+
#endif
37+
38+
#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: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#define __CLC_GENSIZE 32
2+
#undef __CLC_SCALAR_GENTYPE
3+
#define __CLC_SCALAR_GENTYPE int
4+
5+
#define __CLC_GENTYPE int
6+
#define __CLC_U_GENTYPE uint
7+
#define __CLC_S_GENTYPE int
8+
#define __CLC_SCALAR 1
9+
#define __CLC_VECSIZE
10+
#include __CLC_BODY
11+
#undef __CLC_VECSIZE
12+
#undef __CLC_SCALAR
13+
#undef __CLC_GENTYPE
14+
#undef __CLC_U_GENTYPE
15+
#undef __CLC_S_GENTYPE
16+
17+
#define __CLC_GENTYPE int2
18+
#define __CLC_U_GENTYPE uint2
19+
#define __CLC_S_GENTYPE int2
20+
#define __CLC_VECSIZE 2
21+
#include __CLC_BODY
22+
#undef __CLC_VECSIZE
23+
#undef __CLC_GENTYPE
24+
#undef __CLC_U_GENTYPE
25+
#undef __CLC_S_GENTYPE
26+
27+
#define __CLC_GENTYPE int3
28+
#define __CLC_U_GENTYPE uint3
29+
#define __CLC_S_GENTYPE int3
30+
#define __CLC_VECSIZE 3
31+
#include __CLC_BODY
32+
#undef __CLC_VECSIZE
33+
#undef __CLC_GENTYPE
34+
#undef __CLC_U_GENTYPE
35+
#undef __CLC_S_GENTYPE
36+
37+
#define __CLC_GENTYPE int4
38+
#define __CLC_U_GENTYPE uint4
39+
#define __CLC_S_GENTYPE int4
40+
#define __CLC_VECSIZE 4
41+
#include __CLC_BODY
42+
#undef __CLC_VECSIZE
43+
#undef __CLC_GENTYPE
44+
#undef __CLC_U_GENTYPE
45+
#undef __CLC_S_GENTYPE
46+
47+
#define __CLC_GENTYPE int8
48+
#define __CLC_U_GENTYPE uint8
49+
#define __CLC_S_GENTYPE int8
50+
#define __CLC_VECSIZE 8
51+
#include __CLC_BODY
52+
#undef __CLC_VECSIZE
53+
#undef __CLC_GENTYPE
54+
#undef __CLC_U_GENTYPE
55+
#undef __CLC_S_GENTYPE
56+
57+
#define __CLC_GENTYPE int16
58+
#define __CLC_U_GENTYPE uint16
59+
#define __CLC_S_GENTYPE int16
60+
#define __CLC_VECSIZE 16
61+
#include __CLC_BODY
62+
#undef __CLC_VECSIZE
63+
#undef __CLC_GENTYPE
64+
#undef __CLC_U_GENTYPE
65+
#undef __CLC_S_GENTYPE
66+
67+
#undef __CLC_SCALAR_GENTYPE
68+
#define __CLC_SCALAR_GENTYPE uint
69+
70+
#define __CLC_GENTYPE uint
71+
#define __CLC_U_GENTYPE uint
72+
#define __CLC_S_GENTYPE int
73+
#define __CLC_SCALAR 1
74+
#define __CLC_VECSIZE
75+
#include __CLC_BODY
76+
#undef __CLC_VECSIZE
77+
#undef __CLC_SCALAR
78+
#undef __CLC_GENTYPE
79+
#undef __CLC_U_GENTYPE
80+
#undef __CLC_S_GENTYPE
81+
82+
#define __CLC_GENTYPE uint2
83+
#define __CLC_U_GENTYPE uint2
84+
#define __CLC_S_GENTYPE int2
85+
#define __CLC_VECSIZE 2
86+
#include __CLC_BODY
87+
#undef __CLC_VECSIZE
88+
#undef __CLC_GENTYPE
89+
#undef __CLC_U_GENTYPE
90+
#undef __CLC_S_GENTYPE
91+
92+
#define __CLC_GENTYPE uint3
93+
#define __CLC_U_GENTYPE uint3
94+
#define __CLC_S_GENTYPE int3
95+
#define __CLC_VECSIZE 3
96+
#include __CLC_BODY
97+
#undef __CLC_VECSIZE
98+
#undef __CLC_GENTYPE
99+
#undef __CLC_U_GENTYPE
100+
#undef __CLC_S_GENTYPE
101+
102+
#define __CLC_GENTYPE uint4
103+
#define __CLC_U_GENTYPE uint4
104+
#define __CLC_S_GENTYPE int4
105+
#define __CLC_VECSIZE 4
106+
#include __CLC_BODY
107+
#undef __CLC_VECSIZE
108+
#undef __CLC_GENTYPE
109+
#undef __CLC_U_GENTYPE
110+
#undef __CLC_S_GENTYPE
111+
112+
#define __CLC_GENTYPE uint8
113+
#define __CLC_U_GENTYPE uint8
114+
#define __CLC_S_GENTYPE int8
115+
#define __CLC_VECSIZE 8
116+
#include __CLC_BODY
117+
#undef __CLC_VECSIZE
118+
#undef __CLC_GENTYPE
119+
#undef __CLC_U_GENTYPE
120+
#undef __CLC_S_GENTYPE
121+
122+
#define __CLC_GENTYPE uint16
123+
#define __CLC_U_GENTYPE uint16
124+
#define __CLC_S_GENTYPE int16
125+
#define __CLC_VECSIZE 16
126+
#include __CLC_BODY
127+
#undef __CLC_VECSIZE
128+
#undef __CLC_GENTYPE
129+
#undef __CLC_U_GENTYPE
130+
#undef __CLC_S_GENTYPE
131+
132+
#undef __CLC_GENSIZE
133+
#undef __CLC_SCALAR_GENTYPE
134+
#undef __CLC_BODY
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x, __CLC_GENTYPE y,
2+
__CLC_GENTYPE z);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x);

0 commit comments

Comments
 (0)