25#include <initializer_list>
32#ifdef SIMDE_X86_SSE4_2_NATIVE
35 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_EACH | \
36 SIMDE_SIDD_NEGATIVE_POLARITY)
38 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_EACH | \
39 SIMDE_SIDD_NEGATIVE_POLARITY | SIMDE_SIDD_MOST_SIGNIFICANT)
40#define FIRST_ZERO (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY)
42 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | \
43 SIMDE_SIDD_MOST_SIGNIFICANT)
44#define FIRST_NON_ZERO \
45 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | \
46 SIMDE_SIDD_MASKED_NEGATIVE_POLARITY)
47#define LAST_NON_ZERO \
48 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | \
49 SIMDE_SIDD_MASKED_NEGATIVE_POLARITY | SIMDE_SIDD_MOST_SIGNIFICANT)
61 for (uint64_t i = 0; i < 16; i++)
62 res[i] = a[b[i] & 0xF];
69 uint64_t
res = simde_mm_movemask_epi8(msk & (
Epu8.id() <
Epu8(bound)));
70 return res == 0 ? 16 : (__builtin_ffsll(
res) - 1);
73 auto res = simde_mm_movemask_epi8(msk & (
Epu8.id() <
Epu8(bound)));
74 return res == 0 ? 16 : (63 - __builtin_clzll(
res));
78 for (
size_t i = 0; i < bound; i++)
83#ifdef SIMDE_X86_SSE4_2_NATIVE
84inline uint64_t first_diff_cmpstr(
epu8 a,
epu8 b,
size_t bound)
noexcept {
85 return unsigned(_mm_cmpestri(a, bound, b, bound, FIRST_DIFF));
95 if (a[bound] != b[bound])
100#ifdef SIMDE_X86_SSE4_2_NATIVE
101inline uint64_t last_diff_cmpstr(
epu8 a,
epu8 b,
size_t bound)
noexcept {
102 return unsigned(_mm_cmpestri(a, bound, b, bound, LAST_DIFF));
111 return (diff < 16) && (a[diff] < b[diff]);
117 :
static_cast<int8_t
>(a[diff]) -
static_cast<int8_t
>(b[diff]);
134template <
bool Increasing = true,
size_t sz>
136 for (
auto round : rounds) {
138 epu8 mask = Increasing ? round <
Epu8.id() :
Epu8.id() < round;
147template <
bool Increasing = true,
size_t sz>
150 for (
auto round : rounds) {
152 epu8 mask = Increasing ? round <
Epu8.id() :
Epu8.id() < round;
154 epu8 cmp = simde_mm_blendv_epi8(b < v, v < b, mask);
155 v = simde_mm_blendv_epi8(v, b, cmp);
169 {{
epu8{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14},
170 epu8{2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13},
171 epu8{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11},
172 epu8{8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7},
173 epu8{0, 2, 1, 12, 8, 10, 9, 11, 4, 6, 5, 7, 3, 14, 13, 15},
174 epu8{0, 4, 8, 10, 1, 9, 12, 13, 2, 5, 3, 14, 6, 7, 11, 15},
175 epu8{0, 1, 4, 5, 2, 3, 8, 9, 6, 7, 12, 13, 10, 11, 14, 15},
176 epu8{0, 1, 2, 6, 4, 8, 3, 10, 5, 12, 7, 11, 9, 13, 14, 15},
177 epu8{0, 1, 2, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 13, 14, 15}}};
191 epu8 { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14},
192 epu8 { 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13},
193 epu8 { 0, 2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15},
194 epu8 { 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11},
195 epu8 { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15},
196 epu8 { 0, 2, 1, 4, 3, 6, 5, 7, 8, 10, 9, 12, 11, 14, 13, 15}
227 epu8 { 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7},
228 epu8 { 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11},
229 epu8 { 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13},
230 epu8 { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14},
251 static std::random_device rd;
252 static std::default_random_engine e1(rd());
253 std::uniform_int_distribution<int> uniform_dist(0, bnd - 1);
255 for (
size_t i = 0; i < 16; i++)
256 res[i] = uniform_dist(e1);
270 epu8 { 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15},
271 epu8 { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15},
272 epu8 { 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15}
276#ifdef SIMDE_X86_SSE4_2_NATIVE
277#define FIND_IN_VECT \
278 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | SIMDE_SIDD_UNIT_MASK | \
279 SIMDE_SIDD_NEGATIVE_POLARITY)
280#define FIND_IN_VECT_COMPL \
281 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | SIMDE_SIDD_UNIT_MASK)
283inline epu8 permutation_of_cmpestrm(
epu8 a,
epu8 b)
noexcept {
284 epu8 res = -
static_cast<epu8>(_mm_cmpestrm(a, 8, b, 16, FIND_IN_VECT));
288 res -=
static_cast<epu8>(_mm_cmpestrm(a, 8, b, 16, FIND_IN_VECT));
297 for (
size_t i = 0; i < 16; i++) {
299 std::distance(ar.begin(), std::find(ar.begin(), ar.end(), b[i]));
304#ifdef SIMDE_X86_SSE4_2_NATIVE
305 return permutation_of_cmpestrm(a, b);
312#error FF is defined !
320 epu8 {
FF, 0,
FF, 2,
FF, 4,
FF, 6,
FF, 8,
FF, 10,
FF, 12,
FF, 14},
321 epu8 {
FF,
FF, 1, 1,
FF,
FF, 5, 5,
FF,
FF, 9, 9,
FF,
FF, 13, 13},
322 epu8 {
FF,
FF,
FF,
FF, 3, 3, 3, 3,
FF,
FF,
FF,
FF, 11, 11, 11, 11},
323 epu8 {
FF,
FF,
FF,
FF,
FF,
FF,
FF,
FF, 7, 7, 7, 7, 7, 7, 7, 7}
330 epu8 { 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14},
331 epu8 { 0, 1, 1, 1, 4, 5, 5, 5, 8, 9, 9, 9, 12, 13, 13, 13},
332 epu8 { 0, 1, 2, 3, 3, 3, 3, 3, 8, 9, 10, 11, 11, 11, 11, 11},
333 epu8 { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7}
341 for (
size_t i = 0; i < 16; i++)
360 for (
size_t i = 1; i < 16; i++)
361 res[i] =
res[i - 1] + v[i];
376 for (
size_t i = 0; i < 16; i++)
377 res = std::max(
res, v[i]);
389 return std::max(v[7], v[15]);
395 for (
size_t i = 1; i < 16; i++)
396 res[i] = std::max(
res[i - 1], v[i]);
411 for (
size_t i = 0; i < 16; i++)
412 res = std::min(
res, v[i]);
424 return std::min(v[7], v[15]);
430 for (
size_t i = 1; i < 16; i++)
431 res[i] = std::min(
res[i - 1], v[i]);
446 for (
size_t i = 0; i < 16; i++)
455 for (
size_t i = 0; i < 16; i++)
465 for (
int i = 1; i < 16; i++) {
473 for (
size_t i = 0; i < 16; i++) {
475 __builtin_popcountl(simde_mm_movemask_epi8(v ==
Epu8(uint8_t(i))));
489 return (simde_mm_movemask_epi8(v +
Epu8(1) <=
Epu8(0x10)) == 0xffff) &&
490 (diff == 16 || diff < k);
495 return (simde_mm_movemask_epi8(v <
Epu8(0x10)) == 0xffff) &&
496 (diff == 16 || diff < k);
504 return (simde_mm_movemask_epi8(v +
Epu8(1) <=
Epu8(0x10)) == 0xffff) &&
505 (simde_mm_movemask_epi8(
eval16(v) <=
Epu8(1)) == 0xffff) &&
506 (diff == 16 || diff < k);
509#ifdef SIMDE_X86_SSE4_2_NATIVE
510inline bool is_permutation_cmpestri(
epu8 v,
const size_t k)
noexcept {
515 return _mm_cmpestri(
Epu8.id(), 16, v, 16, FIRST_NON_ZERO) == 16 &&
516 _mm_cmpestri(v, 16,
Epu8.id(), 16, FIRST_NON_ZERO) == 16 &&
517 (diff == 16 || diff < k);
531#ifdef SIMDE_X86_SSE4_2_NATIVE
532 return is_permutation_cmpestri(v, k);
543 stream <<
"{" << std::setw(2) << unsigned(a[0]);
544 for (
unsigned i = 1; i < 16; ++i)
545 stream <<
"," << std::setw(2) << unsigned(a[i]);
551 std::ostringstream ss;
563template <>
struct not_equal_to<
HPCombi::epu8> {
572 unsigned __int128 v0 = simde_mm_extract_epi64(a, 0);
573 unsigned __int128 v1 = simde_mm_extract_epi64(a, 1);
592 simde__m128 v1v = simde__m128(v1), v2v = simde__m128(v2);
593 return v1v[0] == v2v[0] ? v1v[1] < v2v[1] : v1v[0] < v2v[0];
#define FF
Definition bmat8_impl.hpp:246
std::array< std::tuple< uint16_t, uint16_t, std::array< uint16_t, gens.size()> >, 65536 > res
Definition image.cpp:66
uint8_t horiz_min4(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:418
epu8 max(epu8 a, epu8 b) noexcept
Vector max between two HPCombi::epu8 0.
Definition epu8.hpp:91
uint64_t last_diff_ref(epu8 a, epu8 b, size_t bound=16) noexcept
The last difference between two HPCombi::epu8.
Definition epu8_impl.hpp:92
uint64_t first_non_zero(epu8 v, int bnd) noexcept
return the index of the first non zero entry or 16 if there are none Only index smaller than bound ar...
Definition epu8_impl.hpp:126
uint8_t horiz_min_ref(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:409
epu8 eval16_arr(epu8 v) noexcept
Evaluation of a HPCombi::epu8.
Definition epu8_impl.hpp:452
epu8 permuted(epu8 a, epu8 b) noexcept
Permuting a HPCombi::epu8.
Definition epu8.hpp:72
epu8 sort8_perm(epu8 &a) noexcept
Sort this and return the sorting permutation.
Definition epu8_impl.hpp:219
epu8 shifted_right(epu8 a) noexcept
Left shifted of a HPCombi::epu8 inserting a 0.
Definition epu8.hpp:78
uint64_t first_diff_ref(epu8 a, epu8 b, size_t bound=16) noexcept
The first difference between two HPCombi::epu8.
Definition epu8_impl.hpp:77
uint64_t first_diff_mask(epu8 a, epu8 b, size_t bound=16) noexcept
The first difference between two HPCombi::epu8.
Definition epu8_impl.hpp:88
epu8 partial_sums_ref(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:357
epu8 eval16_gen(epu8 v) noexcept
Definition epu8_impl.hpp:460
epu8 network_sort(epu8 res, std::array< epu8, sz > rounds)
Apply a sorting network.
Definition epu8_impl.hpp:135
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 is_permutation(epu8 v, const size_t k=16) noexcept
Definition epu8_impl.hpp:530
void merge_rev(epu8 &a, epu8 &b) noexcept
Definition epu8_impl.hpp:233
constexpr std::array< epu8, 4 > summing_rounds
Permutation Round for partial and horizontal sums.
Definition epu8_impl.hpp:317
int8_t less_partial(epu8 a, epu8 b, int k) noexcept
Partial lexicographic comparison between two HPCombi::epu8.
Definition epu8_impl.hpp:113
uint8_t horiz_max4(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:383
uint64_t last_diff_mask(epu8 a, epu8 b, size_t bound=16) noexcept
The last difference between two HPCombi::epu8.
Definition epu8_impl.hpp:105
uint8_t horiz_max3(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:384
constexpr uint64_t prime
A prime number good for hashing.
Definition epu8.hpp:164
uint8_t horiz_min_gen(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:415
bool is_partial_permutation(epu8 v, const size_t k=16) noexcept
Test for partial permutations.
Definition epu8_impl.hpp:499
bool is_permutation_sort(epu8 v, const size_t k=16) noexcept
Definition epu8_impl.hpp:521
uint64_t last_zero(epu8 v, int bnd) noexcept
return the index of the last zero entry or 16 if there are none Only index smaller than bound are tak...
Definition epu8_impl.hpp:123
void merge(epu8 &a, epu8 &b) noexcept
Merge two sorted epu8.
Definition epu8_impl.hpp:240
uint8_t horiz_sum4(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:348
epu8 popcount16(epu8 v) noexcept
a vector popcount function
Definition epu8_impl.hpp:480
epu8 partial_sums_round(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:368
uint8_t horiz_sum3(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:349
uint8_t horiz_sum_ref(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:339
epu8 partial_sums_gen(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:364
bool equal(epu8 a, epu8 b) noexcept
Equality of HPCombi::epu8.
Definition epu8.hpp:63
epu8 permutation_of_ref(epu8 a, epu8 b) noexcept
Find if a vector is a permutation of one other.
Definition epu8_impl.hpp:294
epu8 min(epu8 a, epu8 b) noexcept
Vector min between two HPCombi::epu8 0.
Definition epu8.hpp:89
uint64_t first_mask(epu8 msk, size_t bound)
Definition epu8_impl.hpp:68
epu8 partial_max_ref(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:392
epu8 sorted8(epu8 a) noexcept
Return a HPCombi::epu8 with the two half sorted.
Definition epu8_impl.hpp:206
epu8 partial_max_round(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:403
epu8 eval16(epu8 v) noexcept
Evaluation of a HPCombi::epu8.
Definition epu8.hpp:408
epu8 network_sort_perm(epu8 &v, std::array< epu8, sz > rounds)
Apply a sorting network in place and return the permutation.
Definition epu8_impl.hpp:148
constexpr std::array< epu8, 6 > sorting_rounds8
A duplicated 8-way sorting network.
Definition epu8_impl.hpp:190
epu8 eval16_cycle(epu8 v) noexcept
Evaluation of a HPCombi::epu8.
Definition epu8_impl.hpp:463
constexpr std::array< epu8, 9 > sorting_rounds
A 16-way sorting network.
Definition epu8_impl.hpp:169
epu8 eval16_ref(epu8 v) noexcept
Evaluation of a HPCombi::epu8.
Definition epu8_impl.hpp:444
epu8 partial_max_gen(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:399
bool less(epu8 a, epu8 b) noexcept
Lexicographic comparison between two HPCombi::epu8.
Definition epu8_impl.hpp:109
uint8_t horiz_max_ref(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:374
epu8 sorted(epu8 a) noexcept
Return a sorted HPCombi::epu8.
Definition epu8_impl.hpp:203
uint64_t last_mask(epu8 msk, size_t bound)
Definition epu8_impl.hpp:72
constexpr std::array< epu8, 4 > mining_rounds
Definition epu8_impl.hpp:327
constexpr TPUBuild< epu8 > Epu8
Factory object acting as a class constructor for type HPCombi::epu8.
Definition epu8.hpp:53
bool is_permutation_eval(epu8 v, const size_t k=16) noexcept
Definition epu8_impl.hpp:525
VectGeneric< TPUBuild< TPU >::size > & as_VectGeneric(TPU &v)
Cast a HPCombi::epu8 to a c++ HPCombi::VectGeneric.
Definition builder.hpp:156
uint64_t first_zero(epu8 v, int bnd) noexcept
return the index of the first zero entry or 16 if there are none Only index smaller than bound are ta...
Definition epu8_impl.hpp:120
epu8 random_epu8(uint16_t bnd)
A random HPCombi::epu8.
Definition epu8_impl.hpp:248
epu8 revsorted(epu8 a) noexcept
Return a reverse sorted HPCombi::epu8.
Definition epu8_impl.hpp:209
epu8 partial_min_round(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:438
bool is_sorted(epu8 a) noexcept
Testing if a HPCombi::epu8 is sorted.
Definition epu8_impl.hpp:200
uint8_t __attribute__((vector_size(16))) epu8
SIMD vector of 16 unsigned bytes.
Definition epu8.hpp:45
constexpr std::array< epu8, 3 > inverting_rounds
Definition epu8_impl.hpp:267
uint64_t last_non_zero(epu8 v, int bnd) noexcept
return the index of the last non zero entry or 16 if there are none Only index smaller than bound are...
Definition epu8_impl.hpp:129
uint64_t last_diff(epu8 a, epu8 b, size_t bound=16) noexcept
The last difference between two HPCombi::epu8.
Definition epu8.hpp:486
epu8 eval16_popcount(epu8 v) noexcept
Evaluation of a HPCombi::epu8.
Definition epu8_impl.hpp:471
epu8 sort_perm(epu8 &a) noexcept
Sort this and return the sorting permutation.
Definition epu8_impl.hpp:216
epu8 partial_min_gen(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:434
epu8 partial_min_ref(epu8) noexcept
Horizontal partial sum of a HPCombi::epu8.
Definition epu8_impl.hpp:427
uint8_t horiz_max_gen(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:380
bool is_transformation(epu8 v, const size_t k=16) noexcept
Test for transformation.
Definition epu8_impl.hpp:493
uint64_t first_diff(epu8 a, epu8 b, size_t bound=16) noexcept
The first difference between two HPCombi::epu8.
Definition epu8.hpp:446
bool is_partial_transformation(epu8 v, const size_t k=16) noexcept
Test for partial transformation.
Definition epu8_impl.hpp:485
epu8 permuted_ref(epu8 a, epu8 b) noexcept
Permuting a HPCombi::epu8.
Definition epu8_impl.hpp:59
constexpr std::array< epu8, 6 > merge_rounds
Definition epu8_impl.hpp:226
TPUBuild< TPU >::array & as_array(TPU &v) noexcept
Cast a TPU to a c++ std::array.
Definition builder.hpp:139
uint8_t horiz_sum_gen(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:345
uint8_t horiz_min3(epu8) noexcept
Horizontal sum of a HPCombi::epu8.
Definition epu8_impl.hpp:419
bool not_equal(epu8 a, epu8 b) noexcept
Non equality of HPCombi::epu8.
Definition epu8.hpp:67
std::ostream & operator<<(std::ostream &os, HPCombi::BMat8 const &bm)
Definition bmat8_impl.hpp:508
std::string to_string(HPCombi::epu8 const &a)
Definition epu8_impl.hpp:550
bool operator()(const HPCombi::epu8 &lhs, const HPCombi::epu8 &rhs) const noexcept
Definition epu8_impl.hpp:557
size_t operator()(HPCombi::epu8 a) const noexcept
Definition epu8_impl.hpp:571
size_t operator()(const HPCombi::epu8 &v1, const HPCombi::epu8 &v2) const noexcept
Definition epu8_impl.hpp:590
bool operator()(const HPCombi::epu8 &lhs, const HPCombi::epu8 &rhs) const noexcept
Definition epu8_impl.hpp:564