diff options
author | Gil Pitney <gil.pitney@linaro.org> | 2015-04-21 23:51:28 +0000 |
---|---|---|
committer | Gil Pitney <gil.pitney@linaro.org> | 2015-04-21 23:51:28 +0000 |
commit | 6e94d7f24bf1d4c15fc21003289ad968a240d8b3 (patch) | |
tree | 2bace8189c28353e4687bfa85c1f8b37824830c4 /include | |
parent | 5a06e4bef4800fbd1d0d2625e500726587d82bc8 (diff) |
Add popcount builtin function for OpenCL v1.2
OpenCL v1.2 defines the builtin popcount, which counts the number of
one bits in the argument.
Extra care is taken to avoid sign extension in casting from the smaller
signed types (char,short) to uint, the argument of __builting_popcount().
This commit enables the Khronos conformance test to PASS:
% test_integer_ops popcount
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/cpu.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/cpu.h b/include/cpu.h index 383bcac..1e8380f 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -130,6 +130,24 @@ UNARY_VEC_DECL(uint, uint, clz) UNARY_VEC_DECL(long, long, clz) UNARY_VEC_DECL(ulong, ulong, clz) +_CLC_OVERLOAD _CLC_DECL char popcount(char v) ; +_CLC_OVERLOAD _CLC_DECL uchar popcount(uchar v) ; +_CLC_OVERLOAD _CLC_DECL short popcount(short v) ; +_CLC_OVERLOAD _CLC_DECL ushort popcount(ushort v) ; +_CLC_OVERLOAD _CLC_DECL int popcount(int v) ; +_CLC_OVERLOAD _CLC_DECL uint popcount(uint v) ; +_CLC_OVERLOAD _CLC_DECL long popcount(long v) ; +_CLC_OVERLOAD _CLC_DECL ulong popcount(ulong v); + +UNARY_VEC_DECL(char, char, popcount) +UNARY_VEC_DECL(uchar, uchar, popcount) +UNARY_VEC_DECL(short, short, popcount) +UNARY_VEC_DECL(ushort, ushort, popcount) +UNARY_VEC_DECL(int, int, popcount) +UNARY_VEC_DECL(uint, uint, popcount) +UNARY_VEC_DECL(long, long, popcount) +UNARY_VEC_DECL(ulong, ulong, popcount) + _CLC_OVERLOAD _CLC_DECL uchar abs(char x) ; _CLC_OVERLOAD _CLC_DECL ushort abs(short x) ; _CLC_OVERLOAD _CLC_DECL uint abs(int x) ; |