Skip to content

Commit c0294f4

Browse files
authored
[libclc] Add generic implementation of bitfield_insert/extract,bit_reverse (#149070)
The implementation is based on reference implementation in OpenCL-CTS/test_integer_ops. The generic implementations pass OpenCL-CTS/test_integer_ops tests on Intel GPU.
1 parent 8813fc0 commit c0294f4

25 files changed

+426
-0
lines changed
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+
#ifndef __CLC_INTEGER_CLC_BIT_REVERSE_H__
10+
#define __CLC_INTEGER_CLC_BIT_REVERSE_H__
11+
12+
#define FUNCTION __clc_bit_reverse
13+
#define __CLC_BODY <clc/shared/unary_decl.inc>
14+
15+
#include <clc/integer/gentype.inc>
16+
17+
#undef FUNCTION
18+
19+
#endif // __CLC_INTEGER_CLC_BIT_REVERSE_H__
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
_CLC_OVERLOAD _CLC_DECL __RETTYPE FUNCTION(__CLC_GENTYPE base, uint offset,
10+
uint count);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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_BITFIELD_EXTRACT_SIGNED_H__
10+
#define __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_bitfield_extract_signed
15+
#define __RETTYPE __CLC_S_GENTYPE
16+
17+
#define __CLC_BODY <clc/integer/clc_bitfield_extract_decl.inc>
18+
#include <clc/integer/gentype.inc>
19+
20+
#undef __RETTYPE
21+
#undef FUNCTION
22+
23+
#endif // __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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_BITFIELD_EXTRACT_SIGNED_H__
10+
#define __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_bitfield_extract_unsigned
15+
#define __RETTYPE __CLC_U_GENTYPE
16+
17+
#define __CLC_BODY <clc/integer/clc_bitfield_extract_decl.inc>
18+
#include <clc/integer/gentype.inc>
19+
20+
#undef __RETTYPE
21+
#undef FUNCTION
22+
23+
#endif // __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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_BITFIELD_INSERT_H__
10+
#define __CLC_INTEGER_CLC_BITFIELD_INSERT_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_bitfield_insert
15+
#define __CLC_BODY <clc/integer/clc_bitfield_insert.inc>
16+
#include <clc/integer/gentype.inc>
17+
18+
#endif // __CLC_INTEGER_CLC_BITFIELD_INSERT_H__
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE base,
10+
__CLC_GENTYPE insert,
11+
uint offset, uint count);

libclc/clc/lib/generic/SOURCES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ geometric/clc_normalize.cl
1515
integer/clc_abs.cl
1616
integer/clc_abs_diff.cl
1717
integer/clc_add_sat.cl
18+
integer/clc_bitfield_extract_signed.cl
19+
integer/clc_bitfield_extract_unsigned.cl
20+
integer/clc_bitfield_insert.cl
21+
integer/clc_bit_reverse.cl
1822
integer/clc_clz.cl
1923
integer/clc_ctz.cl
2024
integer/clc_hadd.cl
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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/integer/clc_bit_reverse.h>
10+
11+
#define FUNCTION __clc_bit_reverse
12+
#define __IMPL_FUNCTION(x) __builtin_elementwise_bitreverse
13+
#define __CLC_BODY <clc/shared/unary_def.inc>
14+
15+
#include <clc/integer/gentype.inc>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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/integer/clc_bitfield_extract_signed.h>
10+
11+
#define __CLC_BODY <clc_bitfield_extract_signed.inc>
12+
#include <clc/integer/gentype.inc>
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+
_CLC_OVERLOAD _CLC_DEF __CLC_S_GENTYPE
10+
__clc_bitfield_extract_signed(__CLC_GENTYPE base, uint offset, uint count) {
11+
if (count == 0)
12+
return 0;
13+
__CLC_U_GENTYPE x = __CLC_AS_U_GENTYPE(base)
14+
<< (__CLC_GENSIZE - offset - count);
15+
// Implement an arithmetic shift right.
16+
__CLC_U_GENTYPE s = -(x >> (__CLC_GENSIZE - 1));
17+
__CLC_U_GENTYPE result = ((s ^ x) >> (__CLC_GENSIZE - count)) ^ s;
18+
return __CLC_AS_S_GENTYPE(result);
19+
}

0 commit comments

Comments
 (0)