12#ifndef EIGENRAND_PACKET_FILTER_SSE_H
13#define EIGENRAND_PACKET_FILTER_SSE_H
24 class CompressMask<16>
26 std::array<std::array<uint8_t, 16>, 7> idx;
27 std::array<internal::Packet4f, 4> selector;
28 std::array<uint8_t, 16> cnt;
30 static uint8_t make_compress(
int mask,
int offset = 0)
34 for (
int i = 0; i < 4; ++i)
40 if (n >= 0) ret |= (i & 3) << (2 * n);
47 static uint8_t count(
int mask)
50 for (
int i = 0; i < 4; ++i)
60 for (
int i = 0; i < 16; ++i)
62 for (
int o = 0; o < 7; ++o)
64 idx[o][i] = make_compress(i, o < 4 ? o : o - 7);
70 selector[0] = _mm_castsi128_ps(_mm_setr_epi32(0, 0, 0, 0));
71 selector[1] = _mm_castsi128_ps(_mm_setr_epi32(-1, 0, 0, 0));
72 selector[2] = _mm_castsi128_ps(_mm_setr_epi32(-1, -1, 0, 0));
73 selector[3] = _mm_castsi128_ps(_mm_setr_epi32(-1, -1, -1, 0));
76 static EIGEN_STRONG_INLINE internal::Packet4f permute(
const internal::Packet4f& p, uint8_t i)
80 return _mm_setr_ps(u[i & 3], u[(i >> 2) & 3], u[(i >> 4) & 3], u[(i >> 6) & 3]);
85 enum { full_size = 4 };
87 static const CompressMask& get_inst()
89 static CompressMask cm;
93 template<
typename Packet>
94 EIGEN_STRONG_INLINE
int compress_append(Packet& _value,
const Packet& _mask,
95 Packet& _rest,
int rest_cnt,
bool& full)
const
97 auto& value =
reinterpret_cast<internal::Packet4f&
>(_value);
98 auto& mask =
reinterpret_cast<const internal::Packet4f&
>(_mask);
99 auto& rest =
reinterpret_cast<internal::Packet4f&
>(_rest);
101 int m = _mm_movemask_ps(mask);
102 if (cnt[m] == full_size)
108 auto p1 = permute(value, idx[rest_cnt][m]);
109 p1 = internal::pblendv(selector[rest_cnt], rest, p1);
111 auto new_cnt = rest_cnt + cnt[m];
112 if (new_cnt >= full_size)
114 if (new_cnt > full_size)
116 rest = permute(value, idx[new_cnt - cnt[m] + full_size - 1][m]);
120 return new_cnt - full_size;