28static_assert(std::is_trivial<BMat8>(),
"BMat8 is not a trivial class!");
30static const constexpr std::array<uint64_t, 8> ROW_MASK = {
31 {0xff00000000000000, 0xff000000000000, 0xff0000000000, 0xff00000000,
32 0xff000000, 0xff0000, 0xff00, 0xff}};
34static const constexpr std::array<uint64_t, 8> COL_MASK = {
35 0x8080808080808080, 0x4040404040404040, 0x2020202020202020,
36 0x1010101010101010, 0x808080808080808, 0x404040404040404,
37 0x202020202020202, 0x101010101010101};
39static const constexpr std::array<uint64_t, 64> BIT_MASK = {{0x8000000000000000,
107 return (_data << (8 * i + j)) >> 63;
110inline void BMat8::set(
size_t i,
size_t j,
bool val)
noexcept {
113 _data ^= (-val ^ _data) & BIT_MASK[8 * i + j];
122 for (
auto const &row : mat) {
124 for (
auto entry : row) {
130 pow =
pow >> (8 - mat.size());
135 static std::random_device _rd;
136 static std::mt19937 _gen(_rd());
137 static std::uniform_int_distribution<uint64_t> _dist(0, 0xffffffffffffffff);
139 return BMat8(_dist(_gen));
145 for (
size_t i = dim; i < 8; ++i) {
146 bm._data &= ~ROW_MASK[i];
147 bm._data &= ~COL_MASK[i];
154 uint64_t y = (x ^ (x >> 7)) & 0xAA00AA00AA00AA;
155 x = x ^ y ^ (y << 7);
156 y = (x ^ (x >> 14)) & 0xCCCC0000CCCC;
157 x = x ^ y ^ (y << 14);
158 y = (x ^ (x >> 28)) & 0xF0F0F0F0;
159 x = x ^ y ^ (y << 28);
164 epu8 x = simde_mm_set_epi64x(_data, _data << 1);
165 uint64_t
res = simde_mm_movemask_epi8(x);
167 res =
res << 16 | simde_mm_movemask_epi8(x);
169 res =
res << 16 | simde_mm_movemask_epi8(x);
171 res =
res << 16 | simde_mm_movemask_epi8(x);
177 simde_mm_movemask_epi8(simde_mm_set_epi64x(_data, _data << 1));
179 simde_mm_movemask_epi8(simde_mm_set_epi64x(_data << 2, _data << 3));
181 simde_mm_movemask_epi8(simde_mm_set_epi64x(_data << 4, _data << 5));
183 simde_mm_movemask_epi8(simde_mm_set_epi64x(_data << 6, _data << 7));
187using epu64 = uint64_t __attribute__((__vector_size__(16), __may_alias__));
190 epu64 x = simde_mm_set_epi64x(a._data, b._data);
191 epu64 y = (x ^ (x >> 7)) & (
epu64{0xAA00AA00AA00AA, 0xAA00AA00AA00AA});
192 x = x ^ y ^ (y << 7);
193 y = (x ^ (x >> 14)) & (
epu64{0xCCCC0000CCCC, 0xCCCC0000CCCC});
194 x = x ^ y ^ (y << 14);
195 y = (x ^ (x >> 28)) & (
epu64{0xF0F0F0F0, 0xF0F0F0F0});
196 x = x ^ y ^ (y << 28);
197 a._data = simde_mm_extract_epi64(x, 1);
198 b._data = simde_mm_extract_epi64(x, 0);
201static constexpr epu8 rotlow{7, 0, 1, 2, 3, 4, 5, 6};
202static constexpr epu8 rothigh{0, 1, 2, 3, 4, 5, 6, 7,
203 15, 8, 9, 10, 11, 12, 13, 14};
204static constexpr epu8 rotboth{7, 0, 1, 2, 3, 4, 5, 6,
205 15, 8, 9, 10, 11, 12, 13, 14};
206static constexpr epu8 rot2{6, 7, 0, 1, 2, 3, 4, 5,
207 14, 15, 8, 9, 10, 11, 12, 13};
210 epu8 x = simde_mm_set_epi64x(_data, _data);
211 epu8 y = simde_mm_shuffle_epi8(simde_mm_set_epi64x(that._data, that._data),
214 epu8 diag{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
215 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40};
216 for (
int i = 0; i < 4; ++i) {
217 data |= ((x & y) !=
epu8{}) & diag;
218 y = simde_mm_shuffle_epi8(y, rot2);
219 diag = simde_mm_shuffle_epi8(diag, rot2);
221 return BMat8(simde_mm_extract_epi64(data, 0) |
222 simde_mm_extract_epi64(data, 1));
225inline epu8 BMat8::row_space_basis_internal() const noexcept {
230 for (
int i = 0; i < 7; i++) {
232 orincl |= ((rescy |
res) ==
res) & rescy;
240 simde_mm_extract_epi64(
sorted8(row_space_basis_internal()), 0));
244#error FF is defined !
248constexpr std::array<epu8, 4>
masks{{
250 {
FF, 0,
FF, 0,
FF, 0,
FF, 0,
FF, 0,
FF, 0,
FF, 0,
FF, 0},
251 {
FF,
FF, 1, 1,
FF,
FF, 1, 1,
FF,
FF, 1, 1,
FF,
FF, 1, 1},
252 {
FF,
FF,
FF,
FF, 2, 2, 2, 2,
FF,
FF,
FF,
FF, 2, 2, 2, 2},
253 {
FF,
FF,
FF,
FF,
FF,
FF,
FF,
FF, 3, 3, 3, 3, 3, 3, 3, 3}
257static const epu8 shiftres{1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
263 static const epu8 bound08 = simde_mm_slli_epi32(
264 static_cast<simde__m128i
>(
Epu8.id()), 3);
265 static const epu8 bound18 = bound08 +
Epu8(0x80);
266 for (
size_t slice8 = 0; slice8 < 16; slice8++) {
268 epu8 shft = simde_mm_shuffle_epi8(shiftres, block - bm5);
269 set0 |= (bm5 == bound08) & shft;
270 set1 |= (bm5 == bound18) & shft;
271 block = simde_mm_shuffle_epi8(block,
Epu8.right_cycle());
277 epu8 in = simde_mm_set_epi64x(0, _data);
278 epu8 block0{}, block1{};
280 block0 |=
static_cast<epu8>(simde_mm_shuffle_epi8(in, m));
281 block1 |=
static_cast<epu8>(simde_mm_shuffle_epi8(in, m |
Epu8(4)));
285 for (
size_t r = 0; r < 16; r++) {
287 block1 = simde_mm_shuffle_epi8(block1,
Epu8.right_cycle());
294 return (__builtin_popcountll(simde_mm_extract_epi64(res0, 0)) +
295 __builtin_popcountll(simde_mm_extract_epi64(res1, 0)) +
296 __builtin_popcountll(simde_mm_extract_epi64(res0, 1)) +
297 __builtin_popcountll(simde_mm_extract_epi64(res1, 1)));
301 epu8 in = simde_mm_set_epi64x(_data, _data);
304 for (
size_t r = 0; r < 16; r++) {
306 for (
int i = 0; i < 8; i++) {
307 orincl |= ((in | block) == block) & in;
310 res += __builtin_popcountll(simde_mm_movemask_epi8(block == orincl));
317 epu8 in = simde_mm_set_epi64x(_data, _data);
320 for (
size_t r = 0; r < 16; r++) {
321 epu8 orincl = ((in | block) == block) & in;
322 for (
int i = 0; i < 7; i++) {
324 orincl |= ((in | block) == block) & in;
326 res += __builtin_popcountll(simde_mm_movemask_epi8(block == orincl));
333 epu8 this0, this1, other0, other1;
334 this->row_space_bitset(this0, this1);
335 other.row_space_bitset(other0, other1);
337 return equal(this0 | other0, other0) &&
equal(this1 | other1, other1);
341 epu8 in = simde_mm_set_epi64x(0, other._data);
342 epu8 block = simde_mm_set_epi64x(0, _data);
343 epu8 orincl = ((in | block) == block) & in;
344 for (
int i = 0; i < 7; i++) {
346 orincl |= ((in | block) == block) & in;
348 return equal(block, orincl);
352 epu8 in = simde_mm_set_epi64x(_data, _data);
353 epu8 orincl = ((in | block) == block) & in;
354 for (
int i = 0; i < 7; i++) {
356 orincl |= ((in | block) == block) & in;
358 return block == orincl;
363 epu8 in = simde_mm_set_epi64x(b1._data, b0._data);
364 epu8 block = simde_mm_set_epi64x(
a1._data, a0._data);
365 epu8 orincl = ((in | block) == block) & in;
366 for (
int i = 0; i < 7; i++) {
368 orincl |= ((in | block) == block) & in;
371 return std::make_pair(simde_mm_extract_epi64(
res, 0) == -1,
372 simde_mm_extract_epi64(
res, 1) == -1);
376 std::bitset<256> lookup;
378 auto last = std::remove(row_vec.begin(), row_vec.end(), 0);
379 row_vec.erase(last, row_vec.end());
380 for (uint8_t x : row_vec) {
384 std::vector<uint8_t> row_space(row_vec.begin(), row_vec.end());
385 for (
size_t i = 0; i < row_space.size(); ++i) {
386 for (uint8_t row : row_vec) {
387 uint8_t x = row_space[i] | row;
389 row_space.push_back(x);
398 std::bitset<256> thisspace = row_space_bitset_ref();
399 std::bitset<256> otherspace = other.row_space_bitset_ref();
400 return (thisspace | otherspace) == otherspace;
408 std::vector<uint8_t>
rows;
409 for (
size_t i = 0; i < 8; ++i) {
410 uint8_t row =
static_cast<uint8_t
>(_data << (8 * i) >> 56);
417 epu8 x = simde_mm_set_epi64x(_data, 0);
418 return __builtin_popcountll(simde_mm_movemask_epi8(x !=
epu8{}));
421static constexpr epu8 rev8{7, 6, 5, 4, 3, 2, 1, 0,
422 8, 9, 10, 11, 12, 13, 14, 15};
425 epu8 x = simde_mm_set_epi64x(0, _data);
429 return BMat8(simde_mm_extract_epi64(x, 0));
446 std::vector<uint8_t>
rows = this->
rows();
447 BMat8 product = *
this * bm;
448 std::vector<uint8_t> prod_rows = product.
rows();
452 std::vector<uint8_t> perm(8);
453 for (
size_t i = 0; i <
nr_rows(); ++i) {
454 uint8_t row =
rows[i];
456 std::distance(prod_rows.begin(),
457 std::find(prod_rows.begin(), prod_rows.end(), row));
461#pragma GCC diagnostic push
462#pragma GCC diagnostic ignored "-Wstringop-overflow"
466#pragma GCC diagnostic pop
470 for (
size_t i = 0; i < 8; i++)
477 epu8 y =
permuted(simde_mm_set_epi64x((*
this * other)._data, 0),
489 for (
size_t i = 0; i < 8; ++i) {
490 for (
size_t j = 0; j < 8; ++j) {
#define FF
Definition bmat8_impl.hpp:246
Class for fast boolean matrices of dimension up to 8 x 8.
Definition bmat8.hpp:52
uint64_t row_space_size_incl() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:316
BMat8 row_space_basis() const noexcept
Returns a canonical basis of the row space of this.
Definition bmat8_impl.hpp:238
static std::pair< bool, bool > row_space_included2(BMat8 a1, BMat8 b1, BMat8 a2, BMat8 b2)
Returns inclusion of row spaces.
Definition bmat8_impl.hpp:361
static void transpose2(BMat8 &, BMat8 &) noexcept
Transpose two matrices at once.
Definition bmat8_impl.hpp:189
uint64_t row_space_size_bitset() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:291
static BMat8 row_permutation_matrix(Perm16 p) noexcept
Returns the matrix associated to the permutation p by rows.
Definition bmat8_impl.hpp:436
BMat8 mult_transpose(BMat8 const &that) const noexcept
Returns the matrix product of this and the transpose of that.
Definition bmat8_impl.hpp:209
BMat8 transpose_maskd() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:175
bool row_space_included_bitset(BMat8 other) const noexcept
Returns whether the row space of this is included in other's.
Definition bmat8_impl.hpp:332
BMat8 transpose() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:152
static BMat8 col_permutation_matrix(Perm16 p) noexcept
Returns the matrix associated to the permutation p by columns.
Definition bmat8_impl.hpp:440
epu8 row_space_mask(epu8 vects) const noexcept
Returns a mask for which vectors of a 16 rows epu8 are in the row space of this.
Definition bmat8_impl.hpp:351
BMat8 row_permuted(Perm16 p) const noexcept
Returns the matrix whose rows have been permuted according to p.
Definition bmat8_impl.hpp:424
BMat8() noexcept=default
A default constructor.
bool row_space_included(BMat8 other) const noexcept
Returns whether the row space of this is included in other's.
Definition bmat8_impl.hpp:340
std::ostream & write(std::ostream &os) const
Write this on os.
Definition bmat8_impl.hpp:485
void row_space_bitset(epu8 &res1, epu8 &res2) const noexcept
Returns the the row space of this as 256 bits.
Definition bmat8_impl.hpp:276
Perm16 right_perm_action_on_basis(BMat8) const noexcept
Give the permutation whose right multiplication change *this to other.
Definition bmat8_impl.hpp:475
std::bitset< 256 > row_space_bitset_ref() const
Returns the the row space of this.
Definition bmat8_impl.hpp:375
BMat8 col_permuted(Perm16 p) const noexcept
Returns the matrix whose columns have been permuted according to p.
Definition bmat8_impl.hpp:432
uint64_t row_space_size_ref() const
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:403
BMat8 transpose_mask() const noexcept
Returns the transpose of this.
Definition bmat8_impl.hpp:163
std::vector< uint8_t > rows() const
Returns a std::vector for rows of this.
Definition bmat8_impl.hpp:407
size_t nr_rows() const noexcept
Returns the number of non-zero rows of this.
Definition bmat8_impl.hpp:416
void set(size_t i, size_t j, bool val) noexcept
Sets the (i, j)th position to val.
Definition bmat8_impl.hpp:110
static BMat8 random()
Returns a random BMat8.
Definition bmat8_impl.hpp:134
bool operator()(size_t i, size_t j) const noexcept
Returns the entry in the (i, j)th position.
Definition bmat8_impl.hpp:104
uint64_t row_space_size_incl1() const noexcept
Returns the cardinality of the row space of this.
Definition bmat8_impl.hpp:300
bool row_space_included_ref(BMat8 other) const noexcept
Returns whether the row space of this is included in other's.
Definition bmat8_impl.hpp:397
Perm16 right_perm_action_on_basis_ref(BMat8) const
Give the permutation whose right multiplication change *this to other.
Definition bmat8_impl.hpp:444
#define HPCOMBI_ASSERT(x)
Definition debug.hpp:28
const Transf16 a1
Definition image.cpp:52
std::array< std::tuple< uint16_t, uint16_t, std::array< uint16_t, gens.size()> >, 65536 > res
Definition image.cpp:66
void row_space_update_bitset(epu8 block, epu8 &set0, epu8 &set1) noexcept
Definition bmat8_impl.hpp:261
epu8 permuted(epu8 a, epu8 b) noexcept
Permuting a HPCombi::epu8.
Definition epu8.hpp:72
epu8 remove_dups(epu8 a, uint8_t repl=0) noexcept
Remove duplicates in a sorted HPCombi::epu8.
Definition epu8_impl.hpp:260
epu8 revsorted8(epu8 a) noexcept
Return a HPCombi::epu8 with the two half reverse sorted.
Definition epu8_impl.hpp:212
epu8 permutation_of(epu8 a, epu8 b) noexcept
Find if a vector is a permutation of one other.
Definition epu8_impl.hpp:303
bool equal(epu8 a, epu8 b) noexcept
Equality of HPCombi::epu8.
Definition epu8.hpp:63
epu8 sorted8(epu8 a) noexcept
Return a HPCombi::epu8 with the two half sorted.
Definition epu8_impl.hpp:206
uint64_t __attribute__((__vector_size__(16), __may_alias__)) epu64
Definition bmat8_impl.hpp:187
constexpr TPUBuild< epu8 > Epu8
Factory object acting as a class constructor for type HPCombi::epu8.
Definition epu8.hpp:53
uint8_t __attribute__((vector_size(16))) epu8
SIMD vector of 16 unsigned bytes.
Definition epu8.hpp:45
constexpr std::array< epu8, 4 > masks
Definition bmat8_impl.hpp:248
const T pow(const T x)
A generic compile time exponentiation function.
Definition power.hpp:83
std::ostream & operator<<(std::ostream &os, HPCombi::BMat8 const &bm)
Definition bmat8_impl.hpp:508
Permutations of .
Definition perm16.hpp:208
static constexpr Perm16 one()
The identity partial permutation.
Definition perm16.hpp:223