3030#else
3131#include < unordered_map>
3232#endif
33- #include " simde/x86/sse4.1.h" // for simde_mm_max_epu8, simde...
33+ #include " simde-0.8.2 /x86/sse4.1.h" // for simde_mm_max_epu8, simde...
3434
3535#include " hpcombi/perm16.hpp"
3636
3737template <typename T>
3838std::ostream &operator <<(std::ostream &out, const std::vector<T> &v) {
39- out << ' [' ;
40- if (!v.empty ()) {
41- auto i = v.begin ();
42- for (; i != --v.end (); ++i)
43- out << std::setw (2 ) << *i << " ," ;
44- out << std::setw (2 ) << *i;
45- }
46- out << " ]" ;
47- return out;
39+ out << ' [' ;
40+ if (!v.empty ()) {
41+ auto i = v.begin ();
42+ for (; i != --v.end (); ++i)
43+ out << std::setw (2 ) << *i << " ," ;
44+ out << std::setw (2 ) << *i;
45+ }
46+ out << " ]" ;
47+ return out;
4848}
4949
5050using namespace std ;
@@ -54,16 +54,18 @@ std::vector<epu8> subsets;
5454std::vector<epu8> subperm;
5555
5656epu8 tosubset (uint16_t n) {
57- epu8 res {};
57+ epu8 res{};
5858 for (int i = 0 ; i < 16 ; i++) {
59- if (((n >> i) & 1 ) != 0 ) res[i] = 0xff ;
59+ if (((n >> i) & 1 ) != 0 )
60+ res[i] = 0xff ;
6061 }
61- if (simde_mm_movemask_epi8 (res) != n) cout << n << " BUG" << res << endl;
62+ if (simde_mm_movemask_epi8 (res) != n)
63+ cout << n << " BUG" << res << endl;
6264 return res;
6365}
6466
6567epu8 subset_to_perm (epu8 s) {
66- epu8 res = Epu8 ({},0xff );
68+ epu8 res = Epu8 ({}, 0xff );
6769 int c = 0 ;
6870 for (int i = 0 ; i < 16 ; i++) {
6971 if (s[i] != 0 ) {
@@ -76,27 +78,26 @@ epu8 subset_to_perm(epu8 s) {
7678
7779void make_subsets_of_size (int n, int k) {
7880 int n2 = 1 << n;
79- for (uint16_t i= 0 ; i < n2; i++) {
81+ for (uint16_t i = 0 ; i < n2; i++) {
8082 if (__builtin_popcountl (i) == k) {
8183 subsets.push_back (tosubset (i));
8284 subperm.push_back (subset_to_perm (tosubset (i)));
8385 }
8486 }
8587}
8688
87- template <int Size>
88- epu8 extract_pattern (epu8 perm, epu8 permset) {
89+ template <int Size> epu8 extract_pattern (epu8 perm, epu8 permset) {
8990 epu8 cst = Epu8 ({}, Size);
9091 epu8 res = permuted (perm, permset) | (Epu8.id () >= cst);
9192 res = sort_perm (res) & (Epu8.id () < cst);
9293 return res;
9394}
9495
95- template <int Size>
96- bool has_pattern (epu8 perm, epu8 patt) {
96+ template <int Size> bool has_pattern (epu8 perm, epu8 patt) {
9797 for (size_t i = 0 ; i < subperm.size (); i++) {
9898 epu8 extr = extract_pattern<Size>(perm, subperm[i]);
99- if (equal (extr, patt)) return true ;
99+ if (equal (extr, patt))
100+ return true ;
100101 }
101102 return false ;
102103}
@@ -106,13 +107,13 @@ int main() {
106107 int n = 8 , k = 4 , n2 = 1 << n;
107108 make_subsets_of_size (n, k);
108109 cout << subsets.size () << endl;
109- epu8 perm = {1 ,4 , 2 , 0 , 3 , 5 , 6 , 7 };
110+ epu8 perm = {1 , 4 , 2 , 0 , 3 , 5 , 6 , 7 };
110111 int i = 42 ;
111112 cout << Perm16::one () << endl;
112113 cout << perm << endl;
113114 cout << subsets[i] << endl;
114115 cout << simde_mm_movemask_epi8 (subsets[i]) << endl;
115116 cout << extract_pattern<4 >(perm, subperm[i]) << endl;
116- cout << int (has_pattern<4 >(perm, epu8 {2 ,1 , 0 , 3 })) << endl;
117- cout << int (has_pattern<4 >(perm, epu8 {3 ,2 , 1 , 0 })) << endl;
117+ cout << int (has_pattern<4 >(perm, epu8{2 , 1 , 0 , 3 })) << endl;
118+ cout << int (has_pattern<4 >(perm, epu8{3 , 2 , 1 , 0 })) << endl;
118119}
0 commit comments