Skip to content

Commit 3f97fe4

Browse files
authored
[libclc] Add ctz built-in implementation to clc and generic (#135309) (#18434)
(cherry picked from commit 5529024)
1 parent 635bf3c commit 3f97fe4

File tree

7 files changed

+109
-0
lines changed

7 files changed

+109
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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_INTEGER_CLC_CTZ_H__
10+
#define __CLC_INTEGER_CLC_CTZ_H__
11+
12+
#define __CLC_FUNCTION __clc_ctz
13+
#define __CLC_BODY <clc/shared/unary_decl.inc>
14+
15+
#include <clc/integer/gentype.inc>
16+
17+
#undef __CLC_BODY
18+
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_INTEGER_CLC_CTZ_H__

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ integer/clc_abs.cl
77
integer/clc_abs_diff.cl
88
integer/clc_add_sat.cl
99
integer/clc_clz.cl
10+
integer/clc_ctz.cl
1011
integer/clc_hadd.cl
1112
integer/clc_mad24.cl
1213
integer/clc_mad_sat.cl
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
#include <clc/clcmacro.h>
10+
#include <clc/integer/clc_ctz.h>
11+
#include <clc/internal/clc.h>
12+
13+
_CLC_OVERLOAD _CLC_DEF char __clc_ctz(char x) {
14+
return __clc_ctz(__clc_as_uchar(x));
15+
}
16+
17+
_CLC_OVERLOAD _CLC_DEF uchar __clc_ctz(uchar x) { return __builtin_ctzg(x, 8); }
18+
19+
_CLC_OVERLOAD _CLC_DEF short __clc_ctz(short x) {
20+
return __clc_ctz(__clc_as_ushort(x));
21+
}
22+
23+
_CLC_OVERLOAD _CLC_DEF ushort __clc_ctz(ushort x) {
24+
return __builtin_ctzg(x, 16);
25+
}
26+
27+
_CLC_OVERLOAD _CLC_DEF int __clc_ctz(int x) {
28+
return __clc_ctz(__clc_as_uint(x));
29+
}
30+
31+
_CLC_OVERLOAD _CLC_DEF uint __clc_ctz(uint x) { return __builtin_ctzg(x, 32); }
32+
33+
_CLC_OVERLOAD _CLC_DEF long __clc_ctz(long x) {
34+
return __clc_ctz(__clc_as_ulong(x));
35+
}
36+
37+
_CLC_OVERLOAD _CLC_DEF ulong __clc_ctz(ulong x) {
38+
return __builtin_ctzg(x, 64);
39+
}
40+
41+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, __clc_ctz, char)
42+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, __clc_ctz, uchar)
43+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, __clc_ctz, short)
44+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, __clc_ctz, ushort)
45+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, __clc_ctz, int)
46+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, __clc_ctz, uint)
47+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, __clc_ctz, long)
48+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, __clc_ctz, ulong)

libclc/generic/include/clc/clc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
#include <clc/integer/abs_diff.h>
172172
#include <clc/integer/add_sat.h>
173173
#include <clc/integer/clz.h>
174+
#include <clc/integer/ctz.h>
174175
#include <clc/integer/hadd.h>
175176
#include <clc/integer/mad24.h>
176177
#include <clc/integer/mad_hi.h>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 __OPENCL_C_VERSION__ >= CL_VERSION_2_0
10+
11+
#define __CLC_FUNCTION ctz
12+
#define __CLC_BODY <clc/shared/unary_decl.inc>
13+
14+
#include <clc/integer/gentype.inc>
15+
16+
#undef __CLC_BODY
17+
#undef __CLC_FUNCTION
18+
19+
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0

libclc/generic/lib/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ integer/abs.cl
6464
integer/abs_diff.cl
6565
integer/add_sat.cl
6666
integer/clz.cl
67+
integer/ctz.cl
6768
integer/hadd.cl
6869
integer/mad24.cl
6970
integer/mad_hi.cl

libclc/generic/lib/integer/ctz.cl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 __OPENCL_C_VERSION__ >= CL_VERSION_2_0
10+
11+
#include <clc/clc.h>
12+
#include <clc/integer/clc_ctz.h>
13+
14+
#define FUNCTION ctz
15+
#define __CLC_BODY <clc/shared/unary_def.inc>
16+
17+
#include <clc/integer/gentype.inc>
18+
19+
#endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0

0 commit comments

Comments
 (0)