26#include <initializer_list>
33#ifdef SIMDE_X86_SSE4_2_NATIVE
36 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_EACH | \
37 SIMDE_SIDD_NEGATIVE_POLARITY)
39 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_EACH | \
40 SIMDE_SIDD_NEGATIVE_POLARITY | SIMDE_SIDD_MOST_SIGNIFICANT)
41#define FIRST_ZERO (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY)
43 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | \
44 SIMDE_SIDD_MOST_SIGNIFICANT)
45#define FIRST_NON_ZERO \
46 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | \
47 SIMDE_SIDD_MASKED_NEGATIVE_POLARITY)
48#define LAST_NON_ZERO \
49 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | \
50 SIMDE_SIDD_MASKED_NEGATIVE_POLARITY | SIMDE_SIDD_MOST_SIGNIFICANT)
62 for (uint64_t i = 0; i < 16; i++)
63 res[i] = a[b[i] & 0xF];
70 uint64_t
res = simde_mm_movemask_epi8(msk & (
Epu8.id() <
Epu8(bound)));
71 return res == 0 ? 16 : (__builtin_ffsll(
res) - 1);
74 auto res = simde_mm_movemask_epi8(msk & (
Epu8.id() <
Epu8(bound)));
75 return res == 0 ? 16 : (63 - __builtin_clzll(
res));
79 for (
size_t i = 0; i < bound; i++)
84#ifdef SIMDE_X86_SSE4_2_NATIVE
85inline uint64_t first_diff_cmpstr(
epu8 a,
epu8 b,
size_t bound)
noexcept {
86 return unsigned(_mm_cmpestri(a, bound, b, bound, FIRST_DIFF));
96 if (a[bound] != b[bound])
101#ifdef SIMDE_X86_SSE4_2_NATIVE
102inline uint64_t last_diff_cmpstr(
epu8 a,
epu8 b,
size_t bound)
noexcept {
103 return unsigned(_mm_cmpestri(a, bound, b, bound, LAST_DIFF));
112 return (diff < 16) && (a[diff] < b[diff]);
118 :
static_cast<int8_t
>(a[diff]) -
static_cast<int8_t
>(b[diff]);
135template <
bool Increasing = true,
size_t sz>
137 for (
auto round : rounds) {
139 epu8 mask = Increasing ? round <
Epu8.id() :
Epu8.id() < round;
148template <
bool Increasing = true,
size_t sz>
151 for (
auto round : rounds) {
153 epu8 mask = Increasing ? round <
Epu8.id() :
Epu8.id() < round;
155 epu8 cmp = simde_mm_blendv_epi8(b < v, v < b, mask);
156 v = simde_mm_blendv_epi8(v, b, cmp);
170 {{
epu8{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14},
171 epu8{2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13},
172 epu8{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11},
173 epu8{8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7},
174 epu8{0, 2, 1, 12, 8, 10, 9, 11, 4, 6, 5, 7, 3, 14, 13, 15},
175 epu8{0, 4, 8, 10, 1, 9, 12, 13, 2, 5, 3, 14, 6, 7, 11, 15},
176 epu8{0, 1, 4, 5, 2, 3, 8, 9, 6, 7, 12, 13, 10, 11, 14, 15},
177 epu8{0, 1, 2, 6, 4, 8, 3, 10, 5, 12, 7, 11, 9, 13, 14, 15},
178 epu8{0, 1, 2, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 13, 14, 15}}};
192 epu8 { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14},
193 epu8 { 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13},
194 epu8 { 0, 2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15},
195 epu8 { 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11},
196 epu8 { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15},
197 epu8 { 0, 2, 1, 4, 3, 6, 5, 7, 8, 10, 9, 12, 11, 14, 13, 15}
228 epu8 { 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7},
229 epu8 { 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11},
230 epu8 { 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13},
231 epu8 { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14},
252 static std::random_device rd;
253 static std::default_random_engine e1(rd());
254 std::uniform_int_distribution<int> uniform_dist(0, bnd - 1);
256 for (
size_t i = 0; i < 16; i++)
257 res[i] = uniform_dist(e1);
271 epu8 { 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15},
272 epu8 { 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15},
273 epu8 { 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15}
277#ifdef SIMDE_X86_SSE4_2_NATIVE
278#define FIND_IN_VECT \
279 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | SIMDE_SIDD_UNIT_MASK | \
280 SIMDE_SIDD_NEGATIVE_POLARITY)
281#define FIND_IN_VECT_COMPL \
282 (SIMDE_SIDD_UBYTE_OPS | SIMDE_SIDD_CMP_EQUAL_ANY | SIMDE_SIDD_UNIT_MASK)
284inline epu8 permutation_of_cmpestrm(
epu8 a,
epu8 b)
noexcept {
285 epu8 res = -
static_cast<epu8>(_mm_cmpestrm(a, 8, b, 16, FIND_IN_VECT));
289 res -=
static_cast<epu8>(_mm_cmpestrm(a, 8, b, 16, FIND_IN_VECT));
298 for (
size_t i = 0; i < 16; i++) {
300 std::distance(ar.begin(), std::find(ar.begin(), ar.end(), b[i]));
305#ifdef SIMDE_X86_SSE4_2_NATIVE
306 return permutation_of_cmpestrm(a, b);
313#error FF is defined !
321 epu8 {
FF, 0,
FF, 2,
FF, 4,
FF, 6,
FF, 8,
FF, 10,
FF, 12,
FF, 14},
322 epu8 {
FF,
FF, 1, 1,
FF,
FF, 5, 5,
FF,
FF, 9, 9,
FF,
FF, 13, 13},
323 epu8 {
FF,
FF,
FF,
FF, 3, 3, 3, 3,
FF,
FF,
FF,
FF, 11, 11, 11, 11},
324 epu8 {
FF,
FF,
FF,
FF,
FF,
FF,
FF,
FF, 7, 7, 7, 7, 7, 7, 7, 7}
331 epu8 { 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14},
332 epu8 { 0, 1, 1, 1, 4, 5, 5, 5, 8, 9, 9, 9, 12, 13, 13, 13},
333 epu8 { 0, 1, 2, 3, 3, 3, 3, 3, 8, 9, 10, 11, 11, 11, 11, 11},
334 epu8 { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7}
342 for (
size_t i = 0; i < 16; i++)
361 for (
size_t i = 1; i < 16; i++)
362 res[i] =
res[i - 1] + v[i];
377 for (
size_t i = 0; i < 16; i++)
378 res = std::max(
res, v[i]);
390 return std::max(v[7], v[15]);
396 for (
size_t i = 1; i < 16; i++)
397 res[i] = std::max(
res[i - 1], v[i]);
412 for (
size_t i = 0; i < 16; i++)
413 res = std::min(
res, v[i]);
425 return std::min(v[7], v[15]);
431 for (
size_t i = 1; i < 16; i++)
432 res[i] = std::min(
res[i - 1], v[i]);
447 for (
size_t i = 0; i < 16; i++)
456 for (
size_t i = 0; i < 16; i++)
466 for (
int i = 1; i < 16; i++) {
474 for (
size_t i = 0; i < 16; i++) {
476 __builtin_popcountl(simde_mm_movemask_epi8(v ==
Epu8(uint8_t(i))));
490 return (simde_mm_movemask_epi8(v +
Epu8(1) <=
Epu8(0x10)) == 0xffff) &&
491 (diff == 16 || diff < k);
496 return (simde_mm_movemask_epi8(v <
Epu8(0x10)) == 0xffff) &&
497 (diff == 16 || diff < k);
505 return (simde_mm_movemask_epi8(v +
Epu8(1) <=
Epu8(0x10)) == 0xffff) &&
506 (simde_mm_movemask_epi8(
eval16(v) <=
Epu8(1)) == 0xffff) &&
507 (diff == 16 || diff < k);
510#ifdef SIMDE_X86_SSE4_2_NATIVE
511inline bool is_permutation_cmpestri(
epu8 v,
const size_t k)
noexcept {
516 return _mm_cmpestri(
Epu8.id(), 16, v, 16, FIRST_NON_ZERO) == 16 &&
517 _mm_cmpestri(v, 16,
Epu8.id(), 16, FIRST_NON_ZERO) == 16 &&
518 (diff == 16 || diff < k);
532#ifdef SIMDE_X86_SSE4_2_NATIVE
533 return is_permutation_cmpestri(v, k);
544 stream <<
"{" << std::setw(2) << unsigned(a[0]);
545 for (
unsigned i = 1; i < 16; ++i)
546 stream <<
"," << std::setw(2) << unsigned(a[i]);
552 std::ostringstream ss;
579 unsigned __int128 v0 = simde_mm_extract_epi64(a, 0);
580 unsigned __int128 v1 = simde_mm_extract_epi64(a, 1);
601 simde__m128 v1v = simde__m128(v1), v2v = simde__m128(v2);
602 return v1v[0] == v2v[0] ? v1v[1] < v2v[1] : v1v[0] < v2v[0];
uint8_t __attribute__((vector_size(16))) epu8
epu8 stands for Extended Packed Unsigned, grouped by 8 bits; this is the low level type chosen by Int...
Definition epu8.hpp:73
#define FF
Definition bmat8_impl.hpp:297
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
Same interface as horiz_min but with a different implementation.
Definition epu8_impl.hpp:419
epu8 max(epu8 a, epu8 b) noexcept
Vector max between two HPCombi::epu8 0.
Definition epu8.hpp:125
uint64_t last_diff_ref(epu8 a, epu8 b, size_t bound=16) noexcept
Same interface as last_diff but with a different implementation.
Definition epu8_impl.hpp:93
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:127
uint8_t horiz_min_ref(epu8) noexcept
Same interface as horiz_min but with a different implementation.
Definition epu8_impl.hpp:410
epu8 eval16_arr(epu8 v) noexcept
Same interface as eval16 but with a different implementation.
Definition epu8_impl.hpp:453
epu8 permuted(epu8 a, epu8 b) noexcept
Same as permuted_ref but with an optimized implementation using intrinsics.
Definition epu8.hpp:103
epu8 sort8_perm(epu8 &a) noexcept
Sort this and return the sorting permutation.
Definition epu8_impl.hpp:220
epu8 shifted_right(epu8 a) noexcept
Left shifted of a HPCombi::epu8 inserting a 0.
Definition epu8.hpp:110
uint64_t first_diff_ref(epu8 a, epu8 b, size_t bound=16) noexcept
Same interface as first_diff but with a different implementation.
Definition epu8_impl.hpp:78
uint64_t first_diff_mask(epu8 a, epu8 b, size_t bound=16) noexcept
Same interface as first_diff but with a different implementation.
Definition epu8_impl.hpp:89
epu8 partial_sums_ref(epu8) noexcept
Same interface as partial_sums but with a different implementation.
Definition epu8_impl.hpp:358
epu8 eval16_gen(epu8 v) noexcept
Definition epu8_impl.hpp:461
epu8 network_sort(epu8 res, std::array< epu8, sz > rounds)
Apply a sorting network.
Definition epu8_impl.hpp:136
epu8 remove_dups(epu8 a, uint8_t repl=0) noexcept
Remove duplicates in a sorted HPCombi::epu8.
Definition epu8_impl.hpp:261
epu8 revsorted8(epu8 a) noexcept
Return a HPCombi::epu8 with both halves reverse sorted.
Definition epu8_impl.hpp:213
epu8 permutation_of(epu8 a, epu8 b) noexcept
Find if a vector is a permutation of another one.
Definition epu8_impl.hpp:304
bool is_permutation(epu8 v, const size_t k=16) noexcept
Definition epu8_impl.hpp:531
void merge_rev(epu8 &a, epu8 &b) noexcept
Definition epu8_impl.hpp:234
constexpr std::array< epu8, 4 > summing_rounds
Permutation Round for partial and horizontal sums.
Definition epu8_impl.hpp:318
int8_t less_partial(epu8 a, epu8 b, int k) noexcept
Partial lexicographic comparison between two HPCombi::epu8.
Definition epu8_impl.hpp:114
uint8_t horiz_max4(epu8) noexcept
Same interface as horiz_max but with a different implementation.
Definition epu8_impl.hpp:384
uint64_t last_diff_mask(epu8 a, epu8 b, size_t bound=16) noexcept
Same interface as last_diff but with a different implementation.
Definition epu8_impl.hpp:106
uint8_t horiz_max3(epu8) noexcept
Same interface as horiz_max but with a different implementation.
Definition epu8_impl.hpp:385
constexpr uint64_t prime
A prime number good for hashing.
Definition epu8.hpp:198
uint8_t horiz_min_gen(epu8) noexcept
Same interface as horiz_min but with a different implementation.
Definition epu8_impl.hpp:416
bool is_partial_permutation(epu8 v, const size_t k=16) noexcept
Test for partial permutations.
Definition epu8_impl.hpp:500
bool is_permutation_sort(epu8 v, const size_t k=16) noexcept
Same interface as is_permutation but with a different implementation.
Definition epu8_impl.hpp:522
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:124
void merge(epu8 &a, epu8 &b) noexcept
Merge two sorted epu8.
Definition epu8_impl.hpp:241
uint8_t horiz_sum4(epu8) noexcept
Same interface as horiz_sum but with a different implementation.
Definition epu8_impl.hpp:349
epu8 popcount16(epu8 v) noexcept
a vector popcount function
Definition epu8_impl.hpp:481
epu8 partial_sums_round(epu8) noexcept
Same interface as partial_sums but with a different implementation.
Definition epu8_impl.hpp:369
uint8_t horiz_sum3(epu8) noexcept
Same interface as horiz_sum but with a different implementation.
Definition epu8_impl.hpp:350
uint8_t horiz_sum_ref(epu8) noexcept
Same interface as horiz_sum but with a different implementation.
Definition epu8_impl.hpp:340
epu8 partial_sums_gen(epu8) noexcept
Same interface as partial_sums but with a different implementation.
Definition epu8_impl.hpp:365
bool equal(epu8 a, epu8 b) noexcept
Equality of HPCombi::epu8.
Definition epu8.hpp:91
epu8 permutation_of_ref(epu8 a, epu8 b) noexcept
Same interface as permutation_of but with a different implementation.
Definition epu8_impl.hpp:295
epu8 min(epu8 a, epu8 b) noexcept
Vector min between two HPCombi::epu8 0.
Definition epu8.hpp:123
uint64_t first_mask(epu8 msk, size_t bound)
Definition epu8_impl.hpp:69
epu8 partial_max_ref(epu8) noexcept
Same interface as partial_max but with a different implementation.
Definition epu8_impl.hpp:393
epu8 sorted8(epu8 a) noexcept
Return a HPCombi::epu8 with both halves sorted.
Definition epu8_impl.hpp:207
epu8 partial_max_round(epu8) noexcept
Same interface as partial_max but with a different implementation.
Definition epu8_impl.hpp:404
epu8 eval16(epu8 v) noexcept
Evaluation of a HPCombi::epu8: count how many times each int of 0..15 appears in the input.
Definition epu8.hpp:488
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:149
constexpr std::array< epu8, 6 > sorting_rounds8
A duplicated 8-way sorting network.
Definition epu8_impl.hpp:191
epu8 eval16_cycle(epu8 v) noexcept
Same interface as eval16 but with a different implementation.
Definition epu8_impl.hpp:464
constexpr std::array< epu8, 9 > sorting_rounds
A 16-way sorting network.
Definition epu8_impl.hpp:170
epu8 eval16_ref(epu8 v) noexcept
Same interface as eval16 but with a different implementation.
Definition epu8_impl.hpp:445
epu8 partial_max_gen(epu8) noexcept
Same interface as partial_max but with a different implementation.
Definition epu8_impl.hpp:400
bool less(epu8 a, epu8 b) noexcept
Lexicographic comparison between two HPCombi::epu8.
Definition epu8_impl.hpp:110
uint8_t horiz_max_ref(epu8) noexcept
Same interface as horiz_max but with a different implementation.
Definition epu8_impl.hpp:375
epu8 sorted(epu8 a) noexcept
Return a sorted HPCombi::epu8.
Definition epu8_impl.hpp:204
uint64_t last_mask(epu8 msk, size_t bound)
Definition epu8_impl.hpp:73
constexpr std::array< epu8, 4 > mining_rounds
Definition epu8_impl.hpp:328
constexpr TPUBuild< epu8 > Epu8
Factory object acting as a class constructor for type HPCombi::epu8.
Definition epu8.hpp:81
bool is_permutation_eval(epu8 v, const size_t k=16) noexcept
Same interface as is_permutation but with a different implementation.
Definition epu8_impl.hpp:526
VectGeneric< TPUBuild< TPU >::size > & as_VectGeneric(TPU &v)
Cast a HPCombi::epu8 to a c++ HPCombi::VectGeneric.
Definition builder.hpp:162
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:121
epu8 random_epu8(uint16_t bnd)
A random HPCombi::epu8.
Definition epu8_impl.hpp:249
epu8 revsorted(epu8 a) noexcept
Return a reverse sorted HPCombi::epu8.
Definition epu8_impl.hpp:210
epu8 partial_min_round(epu8) noexcept
Same interface as partial_min but with a different implementation.
Definition epu8_impl.hpp:439
bool is_sorted(epu8 a) noexcept
Testing if a HPCombi::epu8 is sorted.
Definition epu8_impl.hpp:201
constexpr std::array< epu8, 3 > inverting_rounds
Definition epu8_impl.hpp:268
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:130
uint64_t last_diff(epu8 a, epu8 b, size_t bound=16) noexcept
The last difference between two HPCombi::epu8.
Definition epu8.hpp:576
epu8 eval16_popcount(epu8 v) noexcept
Same interface as eval16 but with a different implementation.
Definition epu8_impl.hpp:472
epu8 sort_perm(epu8 &a) noexcept
Sort this and return the sorting permutation.
Definition epu8_impl.hpp:217
epu8 partial_min_gen(epu8) noexcept
Same interface as partial_min but with a different implementation.
Definition epu8_impl.hpp:435
epu8 partial_min_ref(epu8) noexcept
Same interface as partial_min but with a different implementation.
Definition epu8_impl.hpp:428
uint8_t horiz_max_gen(epu8) noexcept
Same interface as horiz_max but with a different implementation.
Definition epu8_impl.hpp:381
uint8_t __attribute__((vector_size(16))) epu8
epu8 stands for Extended Packed Unsigned, grouped by 8 bits; this is the low level type chosen by Int...
Definition epu8.hpp:73
bool is_transformation(epu8 v, const size_t k=16) noexcept
Test for transformation.
Definition epu8_impl.hpp:494
uint64_t first_diff(epu8 a, epu8 b, size_t bound=16) noexcept
The first difference between two HPCombi::epu8.
Definition epu8.hpp:531
bool is_partial_transformation(epu8 v, const size_t k=16) noexcept
Test for partial transformation.
Definition epu8_impl.hpp:486
epu8 permuted_ref(epu8 a, epu8 b) noexcept
Apply a permutation b on the vector a: for i=0..16 {result[i] = a[b[i]}.
Definition epu8_impl.hpp:60
constexpr std::array< epu8, 6 > merge_rounds
Definition epu8_impl.hpp:227
TPUBuild< TPU >::array & as_array(TPU &v) noexcept
Cast a TPU to a c++ std::array.
Definition builder.hpp:145
uint8_t horiz_sum_gen(epu8) noexcept
Same interface as horiz_sum but with a different implementation.
Definition epu8_impl.hpp:346
uint8_t horiz_min3(epu8) noexcept
Same interface as horiz_min but with a different implementation.
Definition epu8_impl.hpp:420
bool not_equal(epu8 a, epu8 b) noexcept
Non equality of HPCombi::epu8.
Definition epu8.hpp:95
Definition bmat16_impl.hpp:362
std::ostream & operator<<(std::ostream &os, HPCombi::BMat16 const &bm)
Definition bmat16_impl.hpp:365
std::string to_string(HPCombi::epu8 const &a)
Definition epu8_impl.hpp:551
bool operator()(const HPCombi::epu8 &lhs, const HPCombi::epu8 &rhs) const noexcept
Definition epu8_impl.hpp:560
size_t operator()(HPCombi::epu8 a) const noexcept
Definition epu8_impl.hpp:578
size_t operator()(const HPCombi::epu8 &v1, const HPCombi::epu8 &v2) const noexcept
Definition epu8_impl.hpp:599
bool operator()(const HPCombi::epu8 &lhs, const HPCombi::epu8 &rhs) const noexcept
Definition epu8_impl.hpp:569