Skip to content

Commit

Permalink
Replaced intrinsic by builtin for popcount
Browse files Browse the repository at this point in the history
  • Loading branch information
hivert committed Oct 23, 2023
1 parent 331ad84 commit d4a5791
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions include/bmat8_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ inline void BMat8::row_space_bitset(epu8 &res0, epu8 &res1) const {
inline uint64_t BMat8::row_space_size_bitset() const {
epu8 res0 {}, res1 {};
row_space_bitset(res0, res1);
return (_mm_popcnt_u64(_mm_extract_epi64(res0, 0)) +
_mm_popcnt_u64(_mm_extract_epi64(res1, 0)) +
_mm_popcnt_u64(_mm_extract_epi64(res0, 1)) +
_mm_popcnt_u64(_mm_extract_epi64(res1, 1)));
return (__builtin_popcountll(_mm_extract_epi64(res0, 0)) +
__builtin_popcountll(_mm_extract_epi64(res1, 0)) +
__builtin_popcountll(_mm_extract_epi64(res0, 1)) +
__builtin_popcountll(_mm_extract_epi64(res1, 1)));
}

inline uint64_t BMat8::row_space_size_incl1() const {
Expand All @@ -292,7 +292,7 @@ inline uint64_t BMat8::row_space_size_incl1() const {
orincl |= ((in | block) == block) & in;
in = permuted(in, rotboth);
}
res += _mm_popcnt_u64(_mm_movemask_epi8(block == orincl));
res += __builtin_popcountll(_mm_movemask_epi8(block == orincl));
block += Epu8(16);
}
return res;
Expand All @@ -308,7 +308,7 @@ inline uint64_t BMat8::row_space_size_incl() const {
in = permuted(in, rotboth);
orincl |= ((in | block) == block) & in;
}
res += _mm_popcnt_u64(_mm_movemask_epi8(block == orincl));
res += __builtin_popcountll(_mm_movemask_epi8(block == orincl));
block += Epu8(16);
}
return res;
Expand Down Expand Up @@ -399,7 +399,7 @@ inline std::vector<uint8_t> BMat8::rows() const {

inline size_t BMat8::nr_rows() const {
epu8 x = _mm_set_epi64x(_data, 0);
return _mm_popcnt_u64(_mm_movemask_epi8(x != epu8 {}));
return __builtin_popcountll(_mm_movemask_epi8(x != epu8 {}));
}

static HPCOMBI_CONSTEXPR epu8
Expand Down
2 changes: 1 addition & 1 deletion include/epu_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ inline epu8 eval16_cycle(epu8 v) {
inline epu8 eval16_popcount(epu8 v) {
epu8 res{};
for (size_t i = 0; i < 16; i++) {
res[i] = _mm_popcnt_u32(_mm_movemask_epi8(v == Epu8(uint8_t(i))));
res[i] = __builtin_popcountl(_mm_movemask_epi8(v == Epu8(uint8_t(i))));
}
return res;
}
Expand Down
8 changes: 4 additions & 4 deletions include/perm16_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ inline uint32_t PTransf16::rank_ref() const {
return std::accumulate(tmp.begin(), tmp.end(), uint8_t(0));
}
inline uint32_t PTransf16::rank() const {
return _mm_popcnt_u32(image_bitset());
return __builtin_popcountl(image_bitset());
}

inline epu8 PTransf16::fix_points_mask(bool complement) const {
Expand Down Expand Up @@ -107,7 +107,7 @@ inline uint8_t PTransf16::largest_moved_point() const {
}
/** Returns the number of fix points of \c *this */
inline uint8_t PTransf16::nb_fix_points() const {
return _mm_popcnt_u32(fix_points_bitset());
return __builtin_popcountl(fix_points_bitset());
}

inline static HPCOMBI_CONSTEXPR uint8_t hilo_exchng_fun(uint8_t i) {
Expand Down Expand Up @@ -307,7 +307,7 @@ inline uint8_t Perm16::nb_descents_ref() const {
return res;
}
inline uint8_t Perm16::nb_descents() const {
return _mm_popcnt_u32(_mm_movemask_epi8(v < shifted_right(v)));
return __builtin_popcountl(_mm_movemask_epi8(v < shifted_right(v)));
}

inline uint8_t Perm16::nb_cycles_ref() const {
Expand Down Expand Up @@ -338,7 +338,7 @@ inline epu8 Perm16::cycles_partition() const {

inline uint8_t Perm16::nb_cycles_unroll() const {
epu8 res = (epu8id == cycles_partition());
return _mm_popcnt_u32(_mm_movemask_epi8(res));
return __builtin_popcountl(_mm_movemask_epi8(res));
}

inline bool Perm16::left_weak_leq_ref(Perm16 other) const {
Expand Down
4 changes: 2 additions & 2 deletions list_intrin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ _mm_max_epu8;__m128i(),__m128i()
_mm_min_epi8;__m128i(),__m128i()
_mm_min_epu8;__m128i(),__m128i()
_mm_movemask_epi8;__m128i()
_mm_popcnt_u32;1
_mm_popcnt_u64;1
__builtin_popcountl;1
__builtin_popcountll;1
_mm_set_epi64x;1,1
_mm_shuffle_epi8;__m128i(),__m128i()
_mm_slli_epi32;__m128i(),1
Expand Down

0 comments on commit d4a5791

Please sign in to comment.