Skip to content

Commit b0338c3

Browse files
authored
[libclc] Move shuffle/shuffle2 to the CLC library (llvm#135000)
This commit moves the shuffle and shuffle2 builtins to the CLC library. In so doing it makes the headers simpler and re-usable for other builtin layers to hook into the CLC functions, if they wish. An additional gentype utility has been made available, which provides a consistent vector-size-or-1 macro for use. The existing __CLC_VECSIZE is defined but empty which is useful in certain applications, such as in concatenation with a type to make a correctly sized scalar or vector type. However, this isn't usable in the same preprocessor lines when wanting to check for specific vector sizes, as e.g., '__CLC_VECSIZE == 2' resolves to '== 2' which is invalid. In local testing this is also useful for the geometric builtins which are only available for scalar types and vector types of 2, 3, or 4 elements. No codegen changes are observed, except the internal shuffle/shuffle2 utility functions are no longer made publicly available.
1 parent 5083e80 commit b0338c3

File tree

14 files changed

+613
-334
lines changed

14 files changed

+613
-334
lines changed

libclc/clc/include/clc/integer/gentype.inc

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@
2727
#define __CLC_GENTYPE char
2828
#define __CLC_U_GENTYPE uchar
2929
#define __CLC_S_GENTYPE char
30-
#define __CLC_SCALAR 1
30+
#define __CLC_SCALAR
3131
#define __CLC_VECSIZE
32+
#define __CLC_VECSIZE_OR_1 1
3233
#include __CLC_BODY
34+
#undef __CLC_VECSIZE_OR_1
3335
#undef __CLC_VECSIZE
3436
#undef __CLC_SCALAR
3537
#undef __CLC_GENTYPE
3638
#undef __CLC_U_GENTYPE
3739
#undef __CLC_S_GENTYPE
3840

41+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
42+
3943
#define __CLC_GENTYPE char2
4044
#define __CLC_U_GENTYPE uchar2
4145
#define __CLC_S_GENTYPE char2
@@ -85,22 +89,27 @@
8589
#undef __CLC_GENTYPE
8690
#undef __CLC_U_GENTYPE
8791
#undef __CLC_S_GENTYPE
92+
#undef __CLC_VECSIZE_OR_1
8893

8994
#undef __CLC_SCALAR_GENTYPE
9095
#define __CLC_SCALAR_GENTYPE uchar
9196

9297
#define __CLC_GENTYPE uchar
9398
#define __CLC_U_GENTYPE uchar
9499
#define __CLC_S_GENTYPE char
95-
#define __CLC_SCALAR 1
100+
#define __CLC_SCALAR
96101
#define __CLC_VECSIZE
102+
#define __CLC_VECSIZE_OR_1 1
97103
#include __CLC_BODY
104+
#undef __CLC_VECSIZE_OR_1
98105
#undef __CLC_VECSIZE
99106
#undef __CLC_SCALAR
100107
#undef __CLC_GENTYPE
101108
#undef __CLC_U_GENTYPE
102109
#undef __CLC_S_GENTYPE
103110

111+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
112+
104113
#define __CLC_GENTYPE uchar2
105114
#define __CLC_U_GENTYPE uchar2
106115
#define __CLC_S_GENTYPE char2
@@ -150,6 +159,7 @@
150159
#undef __CLC_GENTYPE
151160
#undef __CLC_U_GENTYPE
152161
#undef __CLC_S_GENTYPE
162+
#undef __CLC_VECSIZE_OR_1
153163

154164
#undef __CLC_GENSIZE
155165
#define __CLC_GENSIZE 16
@@ -159,15 +169,19 @@
159169
#define __CLC_GENTYPE short
160170
#define __CLC_U_GENTYPE ushort
161171
#define __CLC_S_GENTYPE short
162-
#define __CLC_SCALAR 1
172+
#define __CLC_SCALAR
163173
#define __CLC_VECSIZE
174+
#define __CLC_VECSIZE_OR_1 1
164175
#include __CLC_BODY
176+
#undef __CLC_VECSIZE_OR_1
165177
#undef __CLC_VECSIZE
166178
#undef __CLC_SCALAR
167179
#undef __CLC_GENTYPE
168180
#undef __CLC_U_GENTYPE
169181
#undef __CLC_S_GENTYPE
170182

183+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
184+
171185
#define __CLC_GENTYPE short2
172186
#define __CLC_U_GENTYPE ushort2
173187
#define __CLC_S_GENTYPE short2
@@ -217,22 +231,27 @@
217231
#undef __CLC_GENTYPE
218232
#undef __CLC_U_GENTYPE
219233
#undef __CLC_S_GENTYPE
234+
#undef __CLC_VECSIZE_OR_1
220235

221236
#undef __CLC_SCALAR_GENTYPE
222237
#define __CLC_SCALAR_GENTYPE ushort
223238

224239
#define __CLC_GENTYPE ushort
225240
#define __CLC_U_GENTYPE ushort
226241
#define __CLC_S_GENTYPE short
227-
#define __CLC_SCALAR 1
242+
#define __CLC_SCALAR
228243
#define __CLC_VECSIZE
244+
#define __CLC_VECSIZE_OR_1 1
229245
#include __CLC_BODY
246+
#undef __CLC_VECSIZE_OR_1
230247
#undef __CLC_VECSIZE
231248
#undef __CLC_SCALAR
232249
#undef __CLC_GENTYPE
233250
#undef __CLC_U_GENTYPE
234251
#undef __CLC_S_GENTYPE
235252

253+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
254+
236255
#define __CLC_GENTYPE ushort2
237256
#define __CLC_U_GENTYPE ushort2
238257
#define __CLC_S_GENTYPE short2
@@ -282,6 +301,7 @@
282301
#undef __CLC_GENTYPE
283302
#undef __CLC_U_GENTYPE
284303
#undef __CLC_S_GENTYPE
304+
#undef __CLC_VECSIZE_OR_1
285305

286306
#undef __CLC_GENSIZE
287307
#define __CLC_GENSIZE 32
@@ -291,15 +311,19 @@
291311
#define __CLC_GENTYPE int
292312
#define __CLC_U_GENTYPE uint
293313
#define __CLC_S_GENTYPE int
294-
#define __CLC_SCALAR 1
314+
#define __CLC_SCALAR
295315
#define __CLC_VECSIZE
316+
#define __CLC_VECSIZE_OR_1 1
296317
#include __CLC_BODY
318+
#undef __CLC_VECSIZE_OR_1
297319
#undef __CLC_VECSIZE
298320
#undef __CLC_SCALAR
299321
#undef __CLC_GENTYPE
300322
#undef __CLC_U_GENTYPE
301323
#undef __CLC_S_GENTYPE
302324

325+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
326+
303327
#define __CLC_GENTYPE int2
304328
#define __CLC_U_GENTYPE uint2
305329
#define __CLC_S_GENTYPE int2
@@ -349,22 +373,27 @@
349373
#undef __CLC_GENTYPE
350374
#undef __CLC_U_GENTYPE
351375
#undef __CLC_S_GENTYPE
376+
#undef __CLC_VECSIZE_OR_1
352377

353378
#undef __CLC_SCALAR_GENTYPE
354379
#define __CLC_SCALAR_GENTYPE uint
355380

356381
#define __CLC_GENTYPE uint
357382
#define __CLC_U_GENTYPE uint
358383
#define __CLC_S_GENTYPE int
359-
#define __CLC_SCALAR 1
384+
#define __CLC_SCALAR
360385
#define __CLC_VECSIZE
386+
#define __CLC_VECSIZE_OR_1 1
361387
#include __CLC_BODY
388+
#undef __CLC_VECSIZE_OR_1
362389
#undef __CLC_VECSIZE
363390
#undef __CLC_SCALAR
364391
#undef __CLC_GENTYPE
365392
#undef __CLC_U_GENTYPE
366393
#undef __CLC_S_GENTYPE
367394

395+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
396+
368397
#define __CLC_GENTYPE uint2
369398
#define __CLC_U_GENTYPE uint2
370399
#define __CLC_S_GENTYPE int2
@@ -414,6 +443,7 @@
414443
#undef __CLC_GENTYPE
415444
#undef __CLC_U_GENTYPE
416445
#undef __CLC_S_GENTYPE
446+
#undef __CLC_VECSIZE_OR_1
417447

418448
#undef __CLC_GENSIZE
419449
#define __CLC_GENSIZE 64
@@ -423,15 +453,19 @@
423453
#define __CLC_GENTYPE long
424454
#define __CLC_U_GENTYPE ulong
425455
#define __CLC_S_GENTYPE long
426-
#define __CLC_SCALAR 1
456+
#define __CLC_SCALAR
427457
#define __CLC_VECSIZE
458+
#define __CLC_VECSIZE_OR_1 1
428459
#include __CLC_BODY
460+
#undef __CLC_VECSIZE_OR_1
429461
#undef __CLC_VECSIZE
430462
#undef __CLC_SCALAR
431463
#undef __CLC_GENTYPE
432464
#undef __CLC_U_GENTYPE
433465
#undef __CLC_S_GENTYPE
434466

467+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
468+
435469
#define __CLC_GENTYPE long2
436470
#define __CLC_U_GENTYPE ulong2
437471
#define __CLC_S_GENTYPE long2
@@ -481,22 +515,28 @@
481515
#undef __CLC_GENTYPE
482516
#undef __CLC_U_GENTYPE
483517
#undef __CLC_S_GENTYPE
518+
#undef __CLC_VECSIZE_OR_1
484519

485520
#undef __CLC_SCALAR_GENTYPE
486521
#define __CLC_SCALAR_GENTYPE ulong
487522

488523
#define __CLC_GENTYPE ulong
489524
#define __CLC_U_GENTYPE ulong
490525
#define __CLC_S_GENTYPE long
491-
#define __CLC_SCALAR 1
526+
#define __CLC_SCALAR
492527
#define __CLC_VECSIZE
528+
#define __CLC_VECSIZE_OR_1 1
493529
#include __CLC_BODY
530+
#undef __CLC_VECSIZE_OR_1
531+
#undef __CLC_VECSIZE_OR_1
494532
#undef __CLC_VECSIZE
495533
#undef __CLC_SCALAR
496534
#undef __CLC_GENTYPE
497535
#undef __CLC_U_GENTYPE
498536
#undef __CLC_S_GENTYPE
499537

538+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
539+
500540
#define __CLC_GENTYPE ulong2
501541
#define __CLC_U_GENTYPE ulong2
502542
#define __CLC_S_GENTYPE long2
@@ -546,6 +586,7 @@
546586
#undef __CLC_GENTYPE
547587
#undef __CLC_U_GENTYPE
548588
#undef __CLC_S_GENTYPE
589+
#undef __CLC_VECSIZE_OR_1
549590

550591
#undef __CLC_GENSIZE
551592
#undef __CLC_SCALAR_GENTYPE

libclc/clc/include/clc/math/gentype.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@
8181
#define __CLC_BIT_INTN int
8282
#define __CLC_SCALAR
8383
#define __CLC_VECSIZE
84+
#define __CLC_VECSIZE_OR_1 1
8485
#include __CLC_BODY
86+
#undef __CLC_VECSIZE_OR_1
8587
#undef __CLC_VECSIZE
8688
#undef __CLC_GENTYPE
8789
#undef __CLC_BIT_INTN
8890
#undef __CLC_SCALAR
8991

92+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
93+
9094
#define __CLC_GENTYPE float2
9195
#define __CLC_BIT_INTN int2
9296
#define __CLC_VECSIZE 2
@@ -127,6 +131,7 @@
127131
#undef __CLC_GENTYPE
128132
#undef __CLC_BIT_INTN
129133

134+
#undef __CLC_VECSIZE_OR_1
130135
#undef __CLC_U_GENTYPE
131136
#undef __CLC_S_GENTYPE
132137
#undef __CLC_GENTYPE_NAN
@@ -150,14 +155,18 @@
150155

151156
#define __CLC_SCALAR
152157
#define __CLC_VECSIZE
158+
#define __CLC_VECSIZE_OR_1 1
153159
#define __CLC_GENTYPE double
154160
#define __CLC_BIT_INTN long
155161
#include __CLC_BODY
162+
#undef __CLC_VECSIZE_OR_1
156163
#undef __CLC_GENTYPE
157164
#undef __CLC_BIT_INTN
158165
#undef __CLC_VECSIZE
159166
#undef __CLC_SCALAR
160167

168+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
169+
161170
#define __CLC_GENTYPE double2
162171
#define __CLC_BIT_INTN long2
163172
#define __CLC_VECSIZE 2
@@ -198,6 +207,7 @@
198207
#undef __CLC_GENTYPE
199208
#undef __CLC_BIT_INTN
200209

210+
#undef __CLC_VECSIZE_OR_1
201211
#undef __CLC_U_GENTYPE
202212
#undef __CLC_S_GENTYPE
203213
#undef __CLC_GENTYPE_NAN
@@ -221,14 +231,18 @@
221231

222232
#define __CLC_SCALAR
223233
#define __CLC_VECSIZE
234+
#define __CLC_VECSIZE_OR_1 1
224235
#define __CLC_GENTYPE half
225236
#define __CLC_BIT_INTN short
226237
#include __CLC_BODY
227238
#undef __CLC_GENTYPE
228239
#undef __CLC_BIT_INTN
240+
#undef __CLC_VECSIZE_OR_1
229241
#undef __CLC_VECSIZE
230242
#undef __CLC_SCALAR
231243

244+
#define __CLC_VECSIZE_OR_1 __CLC_VECSIZE
245+
232246
#define __CLC_GENTYPE half2
233247
#define __CLC_BIT_INTN short2
234248
#define __CLC_VECSIZE 2
@@ -269,6 +283,7 @@
269283
#undef __CLC_GENTYPE
270284
#undef __CLC_BIT_INTN
271285

286+
#undef __CLC_VECSIZE_OR_1
272287
#undef __CLC_U_GENTYPE
273288
#undef __CLC_S_GENTYPE
274289
#undef __CLC_GENTYPE_NAN
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_MISC_CLC_SHUFFLE_H__
10+
#define __CLC_MISC_CLC_SHUFFLE_H__
11+
12+
#define __CLC_FUNCTION __clc_shuffle
13+
14+
// Integer-type decls
15+
#define __CLC_BODY <clc/misc/shuffle_decl.inc>
16+
#include <clc/integer/gentype.inc>
17+
18+
// Floating-point decls
19+
#define __CLC_BODY <clc/misc/shuffle_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef __CLC_FUNCTION
23+
24+
#endif // __CLC_MISC_CLC_SHUFFLE_H__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_MISC_CLC_SHUFFLE2_H__
10+
#define __CLC_MISC_CLC_SHUFFLE2_H__
11+
12+
#define __CLC_FUNCTION __clc_shuffle2
13+
14+
// Integer-type decls
15+
#define __CLC_BODY <clc/misc/shuffle2_decl.inc>
16+
#include <clc/integer/gentype.inc>
17+
18+
// Floating-point decls
19+
#define __CLC_BODY <clc/misc/shuffle2_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef __CLC_FUNCTION
23+
24+
#endif // __CLC_MISC_CLC_SHUFFLE2_H__
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#if (__CLC_VECSIZE_OR_1 == 2 || __CLC_VECSIZE_OR_1 == 4 || \
10+
__CLC_VECSIZE_OR_1 == 8 || __CLC_VECSIZE_OR_1 == 16)
11+
12+
// The return type is same base type as the input type, with the same vector
13+
// size as the mask. Elements in the mask must be the same size (number of bits)
14+
// as the input value., e.g. char8 ret = shuffle(char2 x, uchar8 mask);
15+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
16+
__CLC_FUNCTION(__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 2) x,
17+
__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 2) y, __CLC_U_GENTYPE mask);
18+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
19+
__CLC_FUNCTION(__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 4) x,
20+
__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 4) y, __CLC_U_GENTYPE mask);
21+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
22+
__CLC_FUNCTION(__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 8) x,
23+
__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 8) y, __CLC_U_GENTYPE mask);
24+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
25+
__CLC_FUNCTION(__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 16) x,
26+
__CLC_XCONCAT(__CLC_SCALAR_GENTYPE, 16) y, __CLC_U_GENTYPE mask);
27+
28+
#endif

0 commit comments

Comments
 (0)