src/bit/parity/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../util/util/lib.hpp" | ||
| 4 | |||
| 5 | namespace tifa_libs { | ||
| 6 | |||
| 7 | template <class T> | ||
| 8 | 12000771 | CEXP int parity(T x) NE { | |
| 9 | 12000771 | CEXP int nd = sizeof(T) * 8; | |
| 10 | static_assert(nd <= 128); | ||
| 11 | 12000771 | CEXP int nd_ull = sizeof(unsigned long long) * 8; | |
| 12 | 11703460 | if CEXP (nd <= sizeof(unsigned) * 8) return __builtin_parity(x); | |
| 13 | 297311 | else if CEXP (nd <= sizeof(unsigned long) * 8) return __builtin_parityl(x); | |
| 14 | else if CEXP (nd <= nd_ull) return __builtin_parityll(x); | ||
| 15 | else return __builtin_parityll(x >> nd_ull) ^ __builtin_parityll(x & (unsigned long long)(-1)); | ||
| 16 | } | ||
| 17 | |||
| 18 | } // namespace tifa_libs | ||
| 19 |