Skip to content

[libspirv][generic] re-use __clc_ctz implementation for __spirv_ocl_ctz #18478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libclc/clc/lib/generic/integer/clc_ctz.cl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ _CLC_OVERLOAD _CLC_DEF char __clc_ctz(char x) {
return __clc_ctz(__clc_as_uchar(x));
}

_CLC_OVERLOAD _CLC_DEF schar __clc_ctz(schar x) {
return __clc_ctz(__clc_as_uchar(x));
}

_CLC_OVERLOAD _CLC_DEF uchar __clc_ctz(uchar x) { return __builtin_ctzg(x, 8); }

_CLC_OVERLOAD _CLC_DEF short __clc_ctz(short x) {
Expand All @@ -39,6 +43,7 @@ _CLC_OVERLOAD _CLC_DEF ulong __clc_ctz(ulong x) {
}

_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __clc_ctz, char)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, schar, __clc_ctz, schar)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, __clc_ctz, uchar)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, __clc_ctz, short)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, __clc_ctz, ushort)
Expand Down
50 changes: 5 additions & 45 deletions libclc/libspirv/lib/generic/integer/ctz.cl
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,11 @@
//
//===----------------------------------------------------------------------===//

#include <clc/clcmacro.h>
#include <clc/integer/clc_ctz.h>
#include <libspirv/spirv.h>

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

_CLC_OVERLOAD _CLC_DEF ushort __spirv_ocl_ctz(ushort x) {
return x ? __builtin_ctzs(x) : 16;
}

_CLC_OVERLOAD _CLC_DEF int __spirv_ocl_ctz(int x) {
return x ? __builtin_ctz(x) : 32;
}

_CLC_OVERLOAD _CLC_DEF uint __spirv_ocl_ctz(uint x) {
return x ? __builtin_ctz(x) : 32;
}

_CLC_OVERLOAD _CLC_DEF long __spirv_ocl_ctz(long x) {
return x ? __builtin_ctzl(x) : 64;
}

_CLC_OVERLOAD _CLC_DEF ulong __spirv_ocl_ctz(ulong x) {
return x ? __builtin_ctzl(x) : 64;
}

_CLC_OVERLOAD _CLC_DEF char __spirv_ocl_ctz(char x) {
return x ? __spirv_ocl_ctz((ushort)(uchar)x) : 8;
}

_CLC_OVERLOAD _CLC_DEF schar __spirv_ocl_ctz(schar x) {
return x ? __spirv_ocl_ctz((ushort)(uchar)x) : 8;
}

_CLC_OVERLOAD _CLC_DEF uchar __spirv_ocl_ctz(uchar x) {
return x ? __spirv_ocl_ctz((ushort)x) : 8;
}

_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __spirv_ocl_ctz, char)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, schar, __spirv_ocl_ctz, schar)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, __spirv_ocl_ctz, uchar)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, __spirv_ocl_ctz, short)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, __spirv_ocl_ctz, ushort)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, __spirv_ocl_ctz, int)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, __spirv_ocl_ctz, uint)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, __spirv_ocl_ctz, long)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, __spirv_ocl_ctz, ulong)
#include <clc/integer/gentype.inc>
Loading