Merge pull request #88 from THU-DSP-LAB/ctz

[VENTUS][fix] Add ctz function implementation
This commit is contained in:
Jules-Kong 2024-01-15 14:37:15 +08:00 committed by GitHub
commit 5b0ffc2cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 0 deletions

View File

@ -142,6 +142,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>

View File

@ -0,0 +1,2 @@
#define __CLC_BODY <clc/integer/ctz.inc>
#include <clc/integer/gentype.inc>

View File

@ -0,0 +1 @@
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE ctz(__CLC_GENTYPE x);

View File

@ -67,6 +67,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_sat.cl

View File

@ -0,0 +1,42 @@
#include <clc/clc.h>
#include "../clcmacro.h"
_CLC_OVERLOAD _CLC_DEF char ctz(char x) {
return x ? ctz((ushort)(uchar)x) : 8;
}
_CLC_OVERLOAD _CLC_DEF uchar ctz(uchar x) {
return x ? ctz((ushort)x) : 8;
}
_CLC_OVERLOAD _CLC_DEF short ctz(short x) {
return x ? __builtin_ctzs(x) : 16;
}
_CLC_OVERLOAD _CLC_DEF ushort ctz(ushort x) {
return x ? __builtin_ctzs(x) : 16;
}
_CLC_OVERLOAD _CLC_DEF int ctz(int x) {
return x ? __builtin_ctz(x) : 32;
}
_CLC_OVERLOAD _CLC_DEF uint ctz(uint x) {
return x ? __builtin_ctz(x) : 32;
}
_CLC_OVERLOAD _CLC_DEF long ctz(long x) {
return x ? __builtin_ctzl(x) : 64;
}
_CLC_OVERLOAD _CLC_DEF ulong ctz(ulong x) {
return x ? __builtin_ctzl(x) : 64;
}
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, ctz, char)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, ctz, uchar)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, ctz, short)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, ctz, ushort)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, ctz, int)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, ctz, uint)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, ctz, long)
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, ctz, ulong)