Skip to content

[libclc] Add ctz built-in implementation to clc and generic (#135309) #18434

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

Merged
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
20 changes: 20 additions & 0 deletions libclc/clc/include/clc/integer/clc_ctz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef __CLC_INTEGER_CLC_CTZ_H__
#define __CLC_INTEGER_CLC_CTZ_H__

#define __CLC_FUNCTION __clc_ctz
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif // __CLC_INTEGER_CLC_CTZ_H__
1 change: 1 addition & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ integer/clc_abs.cl
integer/clc_abs_diff.cl
integer/clc_add_sat.cl
integer/clc_clz.cl
integer/clc_ctz.cl
integer/clc_hadd.cl
integer/clc_mad24.cl
integer/clc_mad_sat.cl
Expand Down
48 changes: 48 additions & 0 deletions libclc/clc/lib/generic/integer/clc_ctz.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <clc/clcmacro.h>
#include <clc/integer/clc_ctz.h>
#include <clc/internal/clc.h>

_CLC_OVERLOAD _CLC_DEF char __clc_ctz(char 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) {
return __clc_ctz(__clc_as_ushort(x));
}

_CLC_OVERLOAD _CLC_DEF ushort __clc_ctz(ushort x) {
return __builtin_ctzg(x, 16);
}

_CLC_OVERLOAD _CLC_DEF int __clc_ctz(int x) {
return __clc_ctz(__clc_as_uint(x));
}

_CLC_OVERLOAD _CLC_DEF uint __clc_ctz(uint x) { return __builtin_ctzg(x, 32); }

_CLC_OVERLOAD _CLC_DEF long __clc_ctz(long x) {
return __clc_ctz(__clc_as_ulong(x));
}

_CLC_OVERLOAD _CLC_DEF ulong __clc_ctz(ulong x) {
return __builtin_ctzg(x, 64);
}

_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __clc_ctz, char)
_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)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, __clc_ctz, int)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, __clc_ctz, uint)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, __clc_ctz, long)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, __clc_ctz, ulong)
1 change: 1 addition & 0 deletions libclc/generic/include/clc/clc.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
#include <clc/integer/abs_diff.h>
#include <clc/integer/add_sat.h>
#include <clc/integer/clz.h>
#include <clc/integer/ctz.h>
#include <clc/integer/hadd.h>
#include <clc/integer/mad24.h>
#include <clc/integer/mad_hi.h>
Expand Down
19 changes: 19 additions & 0 deletions libclc/generic/include/clc/integer/ctz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0

#define __CLC_FUNCTION ctz
#define __CLC_BODY <clc/shared/unary_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
1 change: 1 addition & 0 deletions libclc/generic/lib/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ integer/abs.cl
integer/abs_diff.cl
integer/add_sat.cl
integer/clz.cl
integer/ctz.cl
integer/hadd.cl
integer/mad24.cl
integer/mad_hi.cl
Expand Down
19 changes: 19 additions & 0 deletions libclc/generic/lib/integer/ctz.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0

#include <clc/clc.h>
#include <clc/integer/clc_ctz.h>

#define FUNCTION ctz
#define __CLC_BODY <clc/shared/unary_def.inc>

#include <clc/integer/gentype.inc>

#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0