nim_prod.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <utility> | ||
| 4 | #include <cstdint> | ||
| 5 | |||
| 6 | // Usage: | ||
| 7 | // constexpr nim_prod_t nimProd; | ||
| 8 | // C++20: | ||
| 9 | // constinit nim_prod_t nimProd; | ||
| 10 | struct nim_prod_t { | ||
| 11 | uint64_t bit_prod[64][64]{}; | ||
| 12 | ✗ | constexpr nim_prod_t() { | |
| 13 | ✗ | for (int i = 0; i < 64; i++) { | |
| 14 | ✗ | for (int j = 0; j < 64; j++) { | |
| 15 | ✗ | if ((i & j) == 0) { | |
| 16 | ✗ | bit_prod[i][j] = uint64_t(1) << (i|j); | |
| 17 | } else { | ||
| 18 | ✗ | int a = (i&j) & -(i&j); | |
| 19 | ✗ | bit_prod[i][j] = bit_prod[i ^ a][j] ^ bit_prod[(i ^ a) | (a-1)][(j ^ a) | (i & (a-1))]; | |
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
| 24 | 4404107 | constexpr uint64_t operator () (uint64_t x, uint64_t y) const { | |
| 25 | 4404107 | uint64_t res = 0; | |
| 26 |
4/4✓ Branch 11 → 12 taken 220856216 times.
✓ Branch 11 → 13 taken 2200394 times.
✓ Branch 12 → 3 taken 218652503 times.
✓ Branch 12 → 13 taken 2203713 times.
|
223056610 | for (int i = 0; i < 64 && (x >> i); i++) |
| 27 |
2/2✓ Branch 3 → 4 taken 140811548 times.
✓ Branch 3 → 10 taken 77840955 times.
|
218652503 | if ((x >> i) & 1) |
| 28 | ✗ | for (int j = 0; j < 64 && (y >> j); j++) | |
| 29 | ✗ | if ((y >> j) & 1) | |
| 30 | ✗ | res ^= bit_prod[i][j]; | |
| 31 | 4404107 | return res; | |
| 32 | } | ||
| 33 | }; | ||
| 34 |