Skip to content

Commit

Permalink
Fixed examples/* wrt new directories
Browse files Browse the repository at this point in the history
  • Loading branch information
hivert committed Oct 29, 2023
1 parent 02dbb8c commit fca0c0b
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/CF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
// http://www.gnu.org/licenses/ //
//****************************************************************************//

#include "perm16.hpp"
#include <array>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <x86intrin.h>

#include "hpcombi/perm16.hpp"

using namespace std;
using namespace HPCombi;
Expand Down
8 changes: 6 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ else()
add_compile_definitions(HPCOMBI_HAVE_DENSEHASHSET)
endif()

include_directories(${CMAKE_SOURCE_DIR}/include ${PROJECT_BINARY_DIR})
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/third_party
${PROJECT_BINARY_DIR})

set(usage_examples RD.cpp Renner.cpp stringmonoid.cpp Trans.cpp CF.cpp image.cpp)
set(usage_examples RD.cpp Renner.cpp stringmonoid.cpp Trans.cpp CF.cpp
image.cpp pattern.cpp)

foreach(f ${usage_examples})
get_filename_component(exampleName ${f} NAME_WE)
Expand Down
12 changes: 6 additions & 6 deletions examples/RD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// http://www.gnu.org/licenses/ //
//****************************************************************************//

#include "perm16.hpp"
#include <array>
#include <cassert>
#include <cstdint>
Expand All @@ -25,7 +24,8 @@
#else
#include <unordered_set>
#endif
#include <x86intrin.h>

#include "hpcombi/perm16.hpp"

using HPCombi::epu8;
using HPCombi::PTransf16;
Expand Down Expand Up @@ -56,10 +56,10 @@ inline PTransf16 act1(PTransf16 x, PTransf16 y) { return x * y; }

inline PTransf16 act0(PTransf16 x, PTransf16 y) {
PTransf16 minab, maxab, mask, b = x * y;
mask = _mm_cmplt_epi8(y, PTransf16::one());
minab = _mm_min_epi8(x, b);
maxab = _mm_max_epi8(x, b);
return static_cast<epu8>(_mm_blendv_epi8(maxab, minab, mask)) |
mask = simde_mm_cmplt_epi8(y, PTransf16::one());
minab = simde_mm_min_epi8(x, b);
maxab = simde_mm_max_epi8(x, b);
return static_cast<epu8>(simde_mm_blendv_epi8(maxab, minab, mask)) |
(y.v == HPCombi::Epu8(0xFF));
}

Expand Down
14 changes: 8 additions & 6 deletions examples/Renner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// http://www.gnu.org/licenses/ //
//****************************************************************************//

#include "perm16.hpp"
#include <array>
#include <cassert>
#include <cstdint>
Expand All @@ -27,7 +26,10 @@
#else
#include <unordered_map>
#endif
#include <x86intrin.h>

#include "simde/x86/sse4.1.h" // for simde_mm_max_epu8, simde...
#include "hpcombi/perm16.hpp"


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
Expand Down Expand Up @@ -84,10 +86,10 @@ inline PTransf16 mult1(PTransf16 x, PTransf16 y) { return x * y; }

inline PTransf16 act0(PTransf16 x, PTransf16 y) {
PTransf16 minab, maxab, mask, b = x * y;
mask = _mm_cmplt_epi8(y, Perm16::one());
minab = _mm_min_epi8(x, b);
maxab = _mm_max_epi8(x, b);
return static_cast<epu8>(_mm_blendv_epi8(maxab, minab, mask)) |
mask = simde_mm_cmplt_epi8(y, Perm16::one());
minab = simde_mm_min_epi8(x, b);
maxab = simde_mm_max_epi8(x, b);
return static_cast<epu8>(simde_mm_blendv_epi8(maxab, minab, mask)) |
(y.v == Epu8(0xFF));
}

Expand Down
4 changes: 3 additions & 1 deletion examples/Trans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
// http://www.gnu.org/licenses/ //
//****************************************************************************//

#include "perm16.hpp"
#include <array>
#include <cassert>
#include <cstdint>
#include <functional> // less<>
#include <iostream>
#include <vector>

#ifdef HPCOMBI_HAVE_DENSEHASHSET
#include <sparsehash/dense_hash_set>
#else
#include <unordered_set>
#endif

#include "hpcombi/perm16.hpp"

using HPCombi::Transf16;

// Full transformation semigroup on 7 points
Expand Down
6 changes: 3 additions & 3 deletions examples/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// http://www.gnu.org/licenses/ //
//****************************************************************************//

#include "perm16.hpp"
#include "timer.h"
#include <array>
#include <cassert>
#include <cstdint>
Expand All @@ -25,7 +23,9 @@
#include <tuple>
#include <utility> // pair
#include <vector>
#include <x86intrin.h>

#include "hpcombi/perm16.hpp"
#include "timer.h"

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
Expand Down
99 changes: 99 additions & 0 deletions examples/pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <array>
#include <cassert>
#include <cstdint>
#include <functional> // less<>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#ifdef HPCOMBI_HAVE_DENSEHASHSET
#include <sparsehash/dense_hash_map>
#else
#include <unordered_map>
#endif
#include "simde/x86/sse4.1.h" // for simde_mm_max_epu8, simde...

#include "hpcombi/perm16.hpp"

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
out << '[';
if (!v.empty()) {
auto i = v.begin();
for (; i != --v.end(); ++i)
out << std::setw(2) << *i << ",";
out << std::setw(2) << *i;
}
out << "]";
return out;
}

using namespace std;
using namespace HPCombi;

std::vector<epu8> subsets;
std::vector<epu8> subperm;

epu8 tosubset(uint16_t n) {
epu8 res {};
for (int i = 0; i < 16; i++) {
if (((n >> i) & 1) != 0) res[i] = 0xff;
}
if (simde_mm_movemask_epi8(res) != n) cout << n << "BUG" << res << endl;
return res;
}

epu8 subset_to_perm(epu8 s) {
epu8 res = Epu8({},0xff);
int c = 0;
for (int i = 0; i < 16; i++) {
if (s[i] != 0) {
res[c] = i;
c++;
}
}
return res;
}

void make_subsets_of_size(int n, int k) {
int n2 = 1 << n;
for (uint16_t i=0; i < n2; i++) {
if (__builtin_popcountl(i) == k) {
subsets.push_back(tosubset(i));
subperm.push_back(subset_to_perm(tosubset(i)));
}
}
}

template <int Size>
epu8 extract_pattern(epu8 perm, epu8 permset) {
epu8 cst = Epu8({}, Size);
epu8 res = permuted(perm, permset) | (epu8id >= cst);
res = sort_perm(res) & (epu8id < cst);
return res;
}

template <int Size>
bool has_pattern(epu8 perm, epu8 patt) {
for (size_t i = 0; i < subperm.size(); i++) {
epu8 extr = extract_pattern<Size>(perm, subperm[i]);
if (equal(extr, patt)) return true;
}
return false;
}

int main() {
cout << hex;
int n = 8, k = 4, n2 = 1 << n;
make_subsets_of_size(n, k);
cout << subsets.size() << endl;
epu8 perm = {1,4,2,0,3,5,6,7};
int i = 42;
cout << Perm16::one() << endl;
cout << perm << endl;
cout << subsets[i] << endl;
cout << simde_mm_movemask_epi8(subsets[i]) << endl;
cout << extract_pattern<4>(perm, subperm[i]) << endl;
cout << int(has_pattern<4>(perm, epu8 {2,1,0,3})) << endl;
cout << int(has_pattern<4>(perm, epu8 {3,2,1,0})) << endl;
}
3 changes: 2 additions & 1 deletion examples/stringmonoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
* #HPCombi::power_helper::Monoid
*/

#include "power.hpp"
#include <cassert>
#include <string>

#include "hpcombi/power.hpp"

namespace HPCombi {
namespace power_helper {

Expand Down

0 comments on commit fca0c0b

Please sign in to comment.