Skip to content

Commit 54438a2

Browse files
authored
[libspirv][generic] re-use __clc_ctz implementation for __spirv_ocl_ctz (#18478)
Add schar variant of __clc_ctz since libspirv requires schar variant.
1 parent a722e78 commit 54438a2

File tree

2 files changed

+10
-45
lines changed

2 files changed

+10
-45
lines changed

libclc/clc/lib/generic/integer/clc_ctz.cl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ _CLC_OVERLOAD _CLC_DEF char __clc_ctz(char x) {
1414
return __clc_ctz(__clc_as_uchar(x));
1515
}
1616

17+
_CLC_OVERLOAD _CLC_DEF schar __clc_ctz(schar x) {
18+
return __clc_ctz(__clc_as_uchar(x));
19+
}
20+
1721
_CLC_OVERLOAD _CLC_DEF uchar __clc_ctz(uchar x) { return __builtin_ctzg(x, 8); }
1822

1923
_CLC_OVERLOAD _CLC_DEF short __clc_ctz(short x) {
@@ -39,6 +43,7 @@ _CLC_OVERLOAD _CLC_DEF ulong __clc_ctz(ulong x) {
3943
}
4044

4145
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __clc_ctz, char)
46+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, schar, __clc_ctz, schar)
4247
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, __clc_ctz, uchar)
4348
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, __clc_ctz, short)
4449
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, __clc_ctz, ushort)

libclc/libspirv/lib/generic/integer/ctz.cl

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

9-
#include <clc/clcmacro.h>
9+
#include <clc/integer/clc_ctz.h>
1010
#include <libspirv/spirv.h>
1111

12-
_CLC_OVERLOAD _CLC_DEF short __spirv_ocl_ctz(short x) {
13-
return x ? __builtin_ctzs(x) : 16;
14-
}
12+
#define FUNCTION __spirv_ocl_ctz
13+
#define __CLC_FUNCTION(x) __clc_ctz
14+
#define __CLC_BODY <clc/shared/unary_def.inc>
1515

16-
_CLC_OVERLOAD _CLC_DEF ushort __spirv_ocl_ctz(ushort x) {
17-
return x ? __builtin_ctzs(x) : 16;
18-
}
19-
20-
_CLC_OVERLOAD _CLC_DEF int __spirv_ocl_ctz(int x) {
21-
return x ? __builtin_ctz(x) : 32;
22-
}
23-
24-
_CLC_OVERLOAD _CLC_DEF uint __spirv_ocl_ctz(uint x) {
25-
return x ? __builtin_ctz(x) : 32;
26-
}
27-
28-
_CLC_OVERLOAD _CLC_DEF long __spirv_ocl_ctz(long x) {
29-
return x ? __builtin_ctzl(x) : 64;
30-
}
31-
32-
_CLC_OVERLOAD _CLC_DEF ulong __spirv_ocl_ctz(ulong x) {
33-
return x ? __builtin_ctzl(x) : 64;
34-
}
35-
36-
_CLC_OVERLOAD _CLC_DEF char __spirv_ocl_ctz(char x) {
37-
return x ? __spirv_ocl_ctz((ushort)(uchar)x) : 8;
38-
}
39-
40-
_CLC_OVERLOAD _CLC_DEF schar __spirv_ocl_ctz(schar x) {
41-
return x ? __spirv_ocl_ctz((ushort)(uchar)x) : 8;
42-
}
43-
44-
_CLC_OVERLOAD _CLC_DEF uchar __spirv_ocl_ctz(uchar x) {
45-
return x ? __spirv_ocl_ctz((ushort)x) : 8;
46-
}
47-
48-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __spirv_ocl_ctz, char)
49-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, schar, __spirv_ocl_ctz, schar)
50-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, __spirv_ocl_ctz, uchar)
51-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, __spirv_ocl_ctz, short)
52-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, __spirv_ocl_ctz, ushort)
53-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, __spirv_ocl_ctz, int)
54-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, __spirv_ocl_ctz, uint)
55-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, __spirv_ocl_ctz, long)
56-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, __spirv_ocl_ctz, ulong)
16+
#include <clc/integer/gentype.inc>

0 commit comments

Comments
 (0)