File: intrinsics.hpp

package info (click to toggle)
terraphast 0.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: cpp: 5,923; sh: 92; ansic: 55; makefile: 27
file content (25 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (3)
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_t popcount(index_t word) { return index_t(__builtin_popcountll(word)); }

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

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

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

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

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

} // namespace bits
} // namespace terraces