Files
scylladb/core/bitops.hh
Avi Kivity 3db75b272e bitops: mark functions as constexpr
Luckily, the gcc builtins are also constexpr.
2014-10-05 19:58:12 +03:00

39 lines
707 B
C++

/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#ifndef BITOPS_HH_
#define BITOPS_HH_
inline
constexpr unsigned count_leading_zeros(unsigned x) {
return __builtin_clz(x);
}
inline
constexpr unsigned count_leading_zeros(unsigned long x) {
return __builtin_clzl(x);
}
inline
constexpr unsigned count_leading_zeros(unsigned long long x) {
return __builtin_clzll(x);
}
inline
constexpr unsigned count_trailing_zeros(unsigned x) {
return __builtin_ctz(x);
}
inline
constexpr unsigned count_trailing_zeros(unsigned long x) {
return __builtin_ctzl(x);
}
inline
constexpr unsigned count_trailing_zeros(unsigned long long x) {
return __builtin_ctzll(x);
}
#endif /* BITOPS_HH_ */