Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Jan 17, 2020
1 parent fefbced commit 4ba8fef
Show file tree
Hide file tree
Showing 16 changed files with 734 additions and 734 deletions.
15 changes: 5 additions & 10 deletions include/bmat8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,10 @@ class BMat8 {
//! This method returns the 8 x 8 BMat8 with 1s on the main diagonal.
static BMat8 one(size_t dim = 8) {
HPCOMBI_ASSERT(dim <= 8);
static std::array<uint64_t, 9> const ones = {0x0000000000000000,
0x8000000000000000,
0x8040000000000000,
0x8040200000000000,
0x8040201000000000,
0x8040201008000000,
0x8040201008040000,
0x8040201008040200,
0x8040201008040201};
static std::array<uint64_t, 9> const ones = {
0x0000000000000000, 0x8000000000000000, 0x8040000000000000,
0x8040200000000000, 0x8040201000000000, 0x8040201008000000,
0x8040201008040000, 0x8040201008040200, 0x8040201008040201};
return BMat8(ones[dim]);
}

Expand All @@ -328,7 +323,7 @@ class BMat8 {
void swap(BMat8 &that) { std::swap(this->_data, that._data); }

//! Write \c this on \c os
std::ostream & write(std::ostream &os) const;
std::ostream &write(std::ostream &os) const;

#ifdef LIBSEMIGROUPS_DENSEHASHMAP
// FIXME do this another way
Expand Down
36 changes: 17 additions & 19 deletions include/bmat8_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ inline BMat8 BMat8::transpose() const {
return BMat8(x);
}


inline BMat8 BMat8::transpose_mask() const {
epu8 x = _mm_set_epi64x(_data, _data << 1);
uint64_t res = _mm_movemask_epi8(x);
Expand All @@ -177,35 +176,34 @@ inline BMat8 BMat8::transpose_maskd() const {
return BMat8(res);
}


using epu64 = uint64_t __attribute__ ((__vector_size__ (16), __may_alias__));
using epu64 = uint64_t __attribute__((__vector_size__(16), __may_alias__));

inline void BMat8::transpose2(BMat8 &a, BMat8 &b) {
epu64 x = _mm_set_epi64x(a._data, b._data);
epu64 y = (x ^ (x >> 7)) & (epu64 {0xAA00AA00AA00AA, 0xAA00AA00AA00AA});
epu64 y = (x ^ (x >> 7)) & (epu64{0xAA00AA00AA00AA, 0xAA00AA00AA00AA});
x = x ^ y ^ (y << 7);
y = (x ^ (x >> 14)) & (epu64 {0xCCCC0000CCCC, 0xCCCC0000CCCC});
y = (x ^ (x >> 14)) & (epu64{0xCCCC0000CCCC, 0xCCCC0000CCCC});
x = x ^ y ^ (y << 14);
y = (x ^ (x >> 28)) & (epu64 {0xF0F0F0F0, 0xF0F0F0F0});
y = (x ^ (x >> 28)) & (epu64{0xF0F0F0F0, 0xF0F0F0F0});
x = x ^ y ^ (y << 28);
a._data = _mm_extract_epi64(x, 1);
b._data = _mm_extract_epi64(x, 0);
}

static constexpr epu8 rotlow { 7, 0, 1, 2, 3, 4, 5, 6};
static constexpr epu8 rothigh
{ 0, 1, 2, 3, 4, 5, 6, 7,15, 8, 9,10,11,12,13,14};
static constexpr epu8 rotboth
{ 7, 0, 1, 2, 3, 4, 5, 6,15, 8, 9,10,11,12,13,14};
static constexpr epu8 rot2
{ 6, 7, 0, 1, 2, 3, 4, 5,14,15, 8, 9,10,11,12,13};
static constexpr epu8 rotlow{7, 0, 1, 2, 3, 4, 5, 6};
static constexpr epu8 rothigh{0, 1, 2, 3, 4, 5, 6, 7,
15, 8, 9, 10, 11, 12, 13, 14};
static constexpr epu8 rotboth{7, 0, 1, 2, 3, 4, 5, 6,
15, 8, 9, 10, 11, 12, 13, 14};
static constexpr epu8 rot2{6, 7, 0, 1, 2, 3, 4, 5,
14, 15, 8, 9, 10, 11, 12, 13};

inline BMat8 BMat8::mult_transpose(BMat8 const &that) const {
epu8 x = _mm_set_epi64x(_data, _data);
epu8 y = _mm_shuffle_epi8(_mm_set_epi64x(that._data, that._data), rothigh);
epu8 data {};
epu8 diag {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40};
epu8 data{};
epu8 diag{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40};
for (int i = 0; i < 4; ++i) {
data |= ((x & y) != epu8{}) & diag;
y = _mm_shuffle_epi8(y, rot2);
Expand All @@ -218,7 +216,7 @@ inline epu8 BMat8::row_space_basis_internal() const {
epu8 res = remove_dups(revsorted8(_mm_set_epi64x(0, _data)));
epu8 rescy = res;
// We now compute the union of all the included different rows
epu8 orincl {};
epu8 orincl{};
for (int i = 0; i < 7; i++) {
rescy = permuted(rescy, rotlow);
orincl |= ((rescy | res) == res) & rescy;
Expand All @@ -236,8 +234,8 @@ inline BMat8 BMat8::row_space_basis() const {
#endif /* FF */
#define FF 0xff

constexpr std::array<epu8, 4> masks {{
// clang-format off
constexpr std::array<epu8, 4> masks{
{// clang-format off
{FF, 0,FF, 0,FF, 0,FF, 0,FF, 0,FF, 0,FF, 0,FF, 0},
{FF,FF, 1, 1,FF,FF, 1, 1,FF,FF, 1, 1,FF,FF, 1, 1},
{FF,FF,FF,FF, 2, 2, 2, 2,FF,FF,FF,FF, 2, 2, 2, 2},
Expand Down
19 changes: 5 additions & 14 deletions include/epu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#define HPCOMBI_CONSTEXPR_CONSTRUCTOR
#endif


namespace HPCombi {

/// Unsigned 8 bits int constant.
Expand All @@ -64,7 +63,6 @@ using xpu8 = uint8_t __attribute__((vector_size(32)));
static_assert(alignof(xpu8) == 32,
"xpu8 type is not properly aligned by the compiler !");


namespace { // Implementation detail code

/// A handmade C++11 constexpr lambda
Expand Down Expand Up @@ -136,15 +134,12 @@ uint8_t right_dup_fun(uint8_t i) { return i == 0 ? 0 : i - 1; }
HPCOMBI_CONSTEXPR
uint8_t complement_fun(uint8_t i) { return 15 - i; }
HPCOMBI_CONSTEXPR uint8_t popcount4_fun(uint8_t i) {
return ((i & 1) != 0 ? 1 : 0)
+ ((i & 2) != 0 ? 1 : 0)
+ ((i & 4) != 0 ? 1 : 0)
+ ((i & 8) != 0 ? 1 : 0);
return ((i & 1) != 0 ? 1 : 0) + ((i & 2) != 0 ? 1 : 0) +
((i & 4) != 0 ? 1 : 0) + ((i & 8) != 0 ? 1 : 0);
}

} // Anonymous namespace


/// Factory object for various SIMD constants in particular constexpr
TPUBuild<epu8> Epu8;

Expand Down Expand Up @@ -258,13 +253,12 @@ inline epu8 revsorted8(epu8 a);
* @details
* @par Algorithm: Uses a 9 stages sorting network #sorting_rounds8
*/
inline epu8 sort_perm(epu8 & a);
inline epu8 sort_perm(epu8 &a);
/** Sort \c this and return the sorting permutation
* @details
* @par Algorithm: Uses a 9 stages sorting network #sorting_rounds8
*/
inline epu8 sort8_perm(epu8 & a);

inline epu8 sort8_perm(epu8 &a);

/** Find if a vector is a permutation of one other
* @details
Expand Down Expand Up @@ -358,7 +352,6 @@ inline epu8 partial_sums_round(epu8);
/** @copydoc common_partial_sums */
inline epu8 partial_sums(epu8 v) { return partial_sums_round(v); }


/** @class common_horiz_max
* @brief Horizontal sum of a #HPCombi::epu8
* @details
Expand Down Expand Up @@ -422,7 +415,6 @@ inline epu8 partial_max_round(epu8);
/** @copydoc common_partial_max */
inline epu8 partial_max(epu8 v) { return partial_max_round(v); }


/** @class common_horiz_min
* @brief Horizontal sum of a #HPCombi::epu8
* @details
Expand Down Expand Up @@ -486,7 +478,6 @@ inline epu8 partial_min_round(epu8);
/** @copydoc common_partial_min */
inline epu8 partial_min(epu8 v) { return partial_min_round(v); }


/** @class common_eval16
* @brief Evaluation of a #HPCombi::epu8
* @details
Expand Down Expand Up @@ -710,7 +701,7 @@ inline std::ostream &operator<<(std::ostream &stream, HPCombi::epu8 const &a);
* - std::hash<epu8>
* - std::less<epu8>
*/
}
} // namespace std

#include "epu_impl.hpp"

Expand Down
58 changes: 22 additions & 36 deletions include/epu_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,17 @@ inline char less_partial(epu8 a, epu8 b, int k) {
: static_cast<char>(a[diff]) - static_cast<char>(b[diff]);
}


inline uint64_t first_zero(epu8 v, int bnd) {
return first_mask(v == epu8 {}, bnd);
return first_mask(v == epu8{}, bnd);
}
inline uint64_t last_zero(epu8 v, int bnd) {
return last_mask(v == epu8 {}, bnd);
return last_mask(v == epu8{}, bnd);
}
inline uint64_t first_non_zero(epu8 v, int bnd) {
return first_mask(v != epu8 {}, bnd);
return first_mask(v != epu8{}, bnd);
}
inline uint64_t last_non_zero(epu8 v, int bnd) {
return last_mask(v != epu8 {}, bnd);
return last_mask(v != epu8{}, bnd);
}

/// Apply a sorting network
Expand Down Expand Up @@ -180,15 +179,9 @@ constexpr std::array<epu8, 6> sorting_rounds8
inline bool is_sorted(epu8 a) {
return _mm_movemask_epi8(shifted_right(a) > a) == 0;
}
inline epu8 sorted(epu8 a) {
return network_sort<true>(a, sorting_rounds);
}
inline epu8 sorted8(epu8 a) {
return network_sort<true>(a, sorting_rounds8);
}
inline epu8 revsorted(epu8 a) {
return network_sort<false>(a, sorting_rounds);
}
inline epu8 sorted(epu8 a) { return network_sort<true>(a, sorting_rounds); }
inline epu8 sorted8(epu8 a) { return network_sort<true>(a, sorting_rounds8); }
inline epu8 revsorted(epu8 a) { return network_sort<false>(a, sorting_rounds); }
inline epu8 revsorted8(epu8 a) {
return network_sort<false>(a, sorting_rounds8);
}
Expand All @@ -200,7 +193,6 @@ inline epu8 sort8_perm(epu8 &a) {
return network_sort_perm<true>(a, sorting_rounds8);
}


inline epu8 random_epu8(uint16_t bnd) {
epu8 res;
std::random_device rd;
Expand All @@ -219,7 +211,7 @@ inline epu8 remove_dups(epu8 v, uint8_t repl) {
}

// Gather at the front numbers with (3-i)-th bit not set.
constexpr std::array<epu8, 3> inverting_rounds {{
constexpr std::array<epu8, 3> inverting_rounds{{
// clang-format off
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
epu8 { 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15},
Expand All @@ -244,14 +236,13 @@ inline epu8 permutation_of(epu8 a, epu8 b) {
return res;
}


#if defined(FF)
#error FF is defined !
#endif /* FF */
#define FF 0xff

/// Permutation Round for partial and horizontal sums
constexpr std::array<epu8, 4> summing_rounds {{
constexpr std::array<epu8, 4> summing_rounds{{
// clang-format off
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
epu8 { FF, 0, FF, 2, FF, 4, FF, 6, FF, 8, FF, 10, FF, 12, FF, 14},
Expand All @@ -261,7 +252,7 @@ constexpr std::array<epu8, 4> summing_rounds {{
// clang-format on
}};

constexpr std::array<epu8, 4> mining_rounds {{
constexpr std::array<epu8, 4> mining_rounds{{
// clang-format off
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
epu8 { 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14},
Expand Down Expand Up @@ -306,7 +297,6 @@ inline epu8 partial_sums_round(epu8 v) {
return v;
}


inline uint8_t horiz_max_ref(epu8 v) {
uint8_t res = 0;
for (size_t i = 0; i < 16; i++)
Expand Down Expand Up @@ -340,7 +330,6 @@ inline epu8 partial_max_round(epu8 v) {
return v;
}


inline uint8_t horiz_min_ref(epu8 v) {
uint8_t res = 255;
for (size_t i = 0; i < 16; i++)
Expand All @@ -361,7 +350,7 @@ inline epu8 partial_min_ref(epu8 v) {
epu8 res;
res[0] = v[0];
for (size_t i = 1; i < 16; i++)
res[i] = std::min(res[i - 1], v[i]) ;
res[i] = std::min(res[i - 1], v[i]);
return res;
}
inline epu8 partial_min_gen(epu8 v) {
Expand All @@ -374,7 +363,6 @@ inline epu8 partial_min_round(epu8 v) {
return v;
}


inline epu8 eval16_ref(epu8 v) {
epu8 res{};
for (size_t i = 0; i < 16; i++)
Expand Down Expand Up @@ -409,44 +397,42 @@ inline epu8 eval16_popcount(epu8 v) {
return res;
}


inline epu8 popcount16(epu8 v){
inline epu8 popcount16(epu8 v) {
return permuted(popcount4, (v & Epu8(0x0f))) + permuted(popcount4, v >> 4);
}


inline bool is_partial_transformation(epu8 v, const size_t k) {
uint64_t diff = last_diff(v, epu8id, 16);
// (forall x in v, x + 1 <= 16) and
// (v = Perm16::one() or last diff index < 16)
return (_mm_movemask_epi8(v + Epu8(1) <= Epu8(0x10)) == 0xffff)
&& (diff == 16 || diff < k);
return (_mm_movemask_epi8(v + Epu8(1) <= Epu8(0x10)) == 0xffff) &&
(diff == 16 || diff < k);
}

inline bool is_transformation(epu8 v, const size_t k) {
uint64_t diff = last_diff(v, epu8id, 16);
return (_mm_movemask_epi8(v < Epu8(0x10)) == 0xffff)
&& (diff == 16 || diff < k);
return (_mm_movemask_epi8(v < Epu8(0x10)) == 0xffff) &&
(diff == 16 || diff < k);
}

inline bool is_partial_permutation(epu8 v, const size_t k) {
uint64_t diff = last_diff(v, epu8id, 16);
// (forall x in v, x <= 15) and
// (forall x < 15, multiplicity x v <= 1
// (v = Perm16::one() or last diff index < 16)
return (_mm_movemask_epi8(v + Epu8(1) <= Epu8(0x10)) == 0xffff)
&& (_mm_movemask_epi8(eval16(v) <= Epu8(1)) == 0xffff)
&& (diff == 16 || diff < k);
return (_mm_movemask_epi8(v + Epu8(1) <= Epu8(0x10)) == 0xffff) &&
(_mm_movemask_epi8(eval16(v) <= Epu8(1)) == 0xffff) &&
(diff == 16 || diff < k);
}

inline bool is_permutation(epu8 v, const size_t k) {
uint64_t diff = last_diff(v, epu8id, 16);
// (forall x in v, x in Perm16::one()) and
// (forall x in Perm16::one(), x in v) and
// (v = Perm16::one() or last diff index < 16)
return _mm_cmpestri(epu8id, 16, v, 16, FIRST_NON_ZERO) == 16
&& _mm_cmpestri(v, 16, epu8id, 16, FIRST_NON_ZERO) == 16
&& (diff == 16 || diff < k);
return _mm_cmpestri(epu8id, 16, v, 16, FIRST_NON_ZERO) == 16 &&
_mm_cmpestri(v, 16, epu8id, 16, FIRST_NON_ZERO) == 16 &&
(diff == 16 || diff < k);
}

} // namespace HPCombi
Expand Down
2 changes: 1 addition & 1 deletion include/hpcombi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifndef HPCOMBI_HPCOMBI_HPP_INCLUDED
#define HPCOMBI_HPCOMBI_HPP_INCLUDED

#include "bmat8.hpp"
#include "epu.hpp"
#include "perm16.hpp"
#include "bmat8.hpp"

#endif // HPCOMBI_HPCOMBI_HPP_INCLUDED
Loading

0 comments on commit 4ba8fef

Please sign in to comment.