2013-06-27 02:21:55 +08:00
|
|
|
#include <clc/clc.h>
|
2014-06-24 17:36:32 +08:00
|
|
|
#include "../clcmacro.h"
|
2013-06-27 02:21:55 +08:00
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF char clz(char x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return clz((ushort)(uchar)x) - 8;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF uchar clz(uchar x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return clz((ushort)x) - 8;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF short clz(short x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return x ? __builtin_clzs(x) : 16;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF ushort clz(ushort x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return x ? __builtin_clzs(x) : 16;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF int clz(int x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return x ? __builtin_clz(x) : 32;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF uint clz(uint x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return x ? __builtin_clz(x) : 32;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF long clz(long x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return x ? __builtin_clzl(x) : 64;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_OVERLOAD _CLC_DEF ulong clz(ulong x) {
|
2017-10-03 02:38:57 +08:00
|
|
|
return x ? __builtin_clzl(x) : 64;
|
2013-06-27 02:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, clz, char)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, clz, uchar)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, clz, short)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, clz, ushort)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, clz, int)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, clz, uint)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, clz, long)
|
|
|
|
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, clz, ulong)
|