Skip to content

Commit 7441e87

Browse files
authored
[libclc] Move several integer functions to CLC library (llvm#116786)
This commit moves over the OpenCL clz, hadd, mad24, mad_hi, mul24, mul_hi, popcount, rhadd, and upsample builtins to the CLC library. This commit also optimizes the vector forms of the mul_hi and upsample builtins to consistently remain in vector types, instead of recursively splitting vectors down to the scalar form. The OpenCL mad_hi builtin wasn't previously publicly available from the CLC libraries, as it was hash-defined to mul_hi in the header files. That issue has been fixed, and mad_hi is now exposed. The custom AMD implementation/workaround for popcount has been removed as it was only required for clang < 7. There are still two integer functions which haven't been moved over. The OpenCL mad_sat builtin uses many of the other integer builtins, and would benefit from optimization for vector types. That can take place in a follow-up commit. The rotate builtin could similarly use some more dedicated focus, potentially using clang builtins.
1 parent cf37ae5 commit 7441e87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+726
-297
lines changed

libclc/amdgcn/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cl_khr_int64_extended_atomics/minmax_helpers.ll
2-
integer/popcount.cl
32
math/fmax.cl
43
math/fmin.cl
54
math/ldexp.cl

libclc/amdgcn/lib/integer/popcount.cl

Lines changed: 0 additions & 6 deletions
This file was deleted.

libclc/amdgcn/lib/integer/popcount.inc

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_CLZ_H__
2+
#define __CLC_INTEGER_CLC_CLZ_H__
3+
4+
#define __CLC_FUNCTION __clc_clz
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_CLZ_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_HADD_H__
2+
#define __CLC_INTEGER_CLC_HADD_H__
3+
4+
#define __CLC_FUNCTION __clc_hadd
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_HADD_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_MAD24_H__
2+
#define __CLC_INTEGER_CLC_MAD24_H__
3+
4+
#define __CLC_FUNCTION __clc_mad24
5+
#define __CLC_BODY <clc/shared/ternary_decl.inc>
6+
7+
#include <clc/integer/gentype24.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_MAD24_H__
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef __CLC_INTEGER_CLC_MAD_HI_H__
2+
#define __CLC_INTEGER_CLC_MAD_HI_H__
3+
4+
#include <clc/integer/clc_mul_hi.h>
5+
6+
#define __clc_mad_hi(a, b, c) (__clc_mul_hi((a), (b)) + (c))
7+
8+
#endif // __CLC_INTEGER_CLC_MAD_HI_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_MUL24_H__
2+
#define __CLC_INTEGER_CLC_MUL24_H__
3+
4+
#define __CLC_FUNCTION __clc_mul24
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype24.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_MUL24_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_MUL_HI_H__
2+
#define __CLC_INTEGER_CLC_MUL_HI_H__
3+
4+
#define __CLC_FUNCTION __clc_mul_hi
5+
#define __CLC_BODY <clc/shared/binary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_MUL_HI_H__
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_INTEGER_CLC_POPCOUNT_H__
2+
#define __CLC_INTEGER_CLC_POPCOUNT_H__
3+
4+
#define __CLC_FUNCTION __clc_popcount
5+
#define __CLC_BODY <clc/shared/unary_decl.inc>
6+
7+
#include <clc/integer/gentype.inc>
8+
9+
#undef __CLC_INTRINSIC
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_INTEGER_CLC_POPCOUNT_H__

0 commit comments

Comments
 (0)