14 #ifndef TLX_MATH_FFS_HEADER 15 #define TLX_MATH_FFS_HEADER 26 template <
typename Integral>
28 if (x == 0)
return 0u;
37 #if defined(__GNUC__) || defined(__clang__) 42 return static_cast<unsigned>(__builtin_ffs(i));
47 unsigned ffs(
unsigned i) {
48 return ffs(static_cast<int>(i));
53 unsigned ffs(
long i) {
54 return static_cast<unsigned>(__builtin_ffsl(i));
59 unsigned ffs(
unsigned long i) {
60 return ffs(static_cast<long>(i));
65 unsigned ffs(
long long i) {
66 return static_cast<unsigned>(__builtin_ffsll(i));
71 unsigned ffs(
unsigned long long i) {
72 return ffs(static_cast<long long>(i));
85 unsigned ffs(
unsigned int i) {
91 unsigned ffs(
long i) {
97 unsigned ffs(
unsigned long i) {
103 unsigned ffs(
long long i) {
109 unsigned ffs(
unsigned long long i) {
119 #endif // !TLX_MATH_FFS_HEADER static unsigned ffs(int i)
find first set bit in integer, or zero if none are set.
static unsigned ffs_template(Integral x)
ffs (find first set bit) - generic implementation