File: intrinsics.hpp

package info (click to toggle)
iqtree 2.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 14,620 kB
  • sloc: cpp: 142,571; ansic: 57,789; sh: 275; python: 242; makefile: 95
file content (25 lines) | stat: -rw-r--r-- 703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <terraces/definitions.hpp>

namespace terraces {
namespace bits {

inline index popcount(index word) { return index(__builtin_popcountll(word)); }

inline index bitscan(index word) { return index(__builtin_ctzll(word)); }

static_assert(sizeof(long long) >= sizeof(index), "intrinsic word sizes incompatible");

inline index rbitscan(index word) {
	return index(std::numeric_limits<long long>::digits - __builtin_clzll(word));
}

inline bool add_overflow(index a, index b, index& result) {
	return __builtin_add_overflow(a, b, &result);
}

inline bool mul_overflow(index a, index b, index& result) {
	return __builtin_mul_overflow(a, b, &result);
}

} // namespace bits
} // namespace terraces