12#ifndef EIGENRAND_PACKET_FILTER_AVX_H
13#define EIGENRAND_PACKET_FILTER_AVX_H
24 class CompressMask<32>
26 std::array<std::array<internal::Packet8i, 256>, 15> idx;
27 std::array<internal::Packet8f, 8> selector;
28 std::array<uint8_t, 256> cnt;
30 static internal::Packet8i make_compress(
int mask,
int offset = 0)
32 int32_t ret[8] = { 0, };
34 for (
int i = 0; i < 8; ++i)
40 if (n >= 0) ret[n] = i;
44 return _mm256_loadu_si256((internal::Packet8i*)ret);
47 static uint8_t count(
int mask)
50 for (
int i = 0; i < 8; ++i)
60 for (
int i = 0; i < 256; ++i)
62 for (
int o = 0; o < 15; ++o)
64 idx[o][i] = make_compress(i, o < 8 ? o : o - 15);
70 selector[0] = _mm256_castsi256_ps(_mm256_setr_epi32(0, 0, 0, 0, 0, 0, 0, 0));
71 selector[1] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, 0, 0, 0, 0, 0, 0, 0));
72 selector[2] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, -1, 0, 0, 0, 0, 0, 0));
73 selector[3] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, -1, -1, 0, 0, 0, 0, 0));
74 selector[4] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, -1, -1, -1, 0, 0, 0, 0));
75 selector[5] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, -1, -1, -1, -1, 0, 0, 0));
76 selector[6] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, -1, -1, -1, -1, -1, 0, 0));
77 selector[7] = _mm256_castsi256_ps(_mm256_setr_epi32(-1, -1, -1, -1, -1, -1, -1, 0));
80 static EIGEN_STRONG_INLINE internal::Packet8f permute(
const internal::Packet8f& p,
const internal::Packet8i& i)
82#ifdef EIGEN_VECTORIZE_AVX2
83 return _mm256_permutevar8x32_ps(p, i);
85 auto l = _mm256_permutevar_ps(p, i);
86 auto h = _mm256_permutevar_ps(_mm256_permute2f128_ps(p, p, 0x01), i);
87 internal::Packet4i i1, i2;
88 internal::split_two(i, i1, i2);
89 i1 = _mm_slli_epi32(i1, 29);
90 i2 = _mm_slli_epi32(i2, 29);
91 auto c = _mm256_castsi256_ps(
92 internal::combine_two(
93 _mm_cmplt_epi32(i1, internal::pset1<internal::Packet4i>(0)),
94 _mm_cmplt_epi32(internal::pset1<internal::Packet4i>(-1), i2)
97 return internal::pblendv(c, h, l);
102 enum { full_size = 8 };
103 static const CompressMask& get_inst()
105 static CompressMask cm;
109 template<
typename Packet>
110 EIGEN_STRONG_INLINE
int compress_append(Packet& _value,
const Packet& _mask,
111 Packet& _rest,
int rest_cnt,
bool& full)
const
113 auto& value =
reinterpret_cast<internal::Packet8f&
>(_value);
114 auto& mask =
reinterpret_cast<const internal::Packet8f&
>(_mask);
115 auto& rest =
reinterpret_cast<internal::Packet8f&
>(_rest);
117 int m = _mm256_movemask_ps(mask);
118 if (cnt[m] == full_size)
124 auto p1 = permute(value, idx[rest_cnt][m]);
125 p1 = internal::pblendv(selector[rest_cnt], rest, p1);
127 auto new_cnt = rest_cnt + cnt[m];
128 if (new_cnt >= full_size)
130 if (new_cnt > full_size)
132 rest = permute(value, idx[new_cnt - cnt[m] + full_size - 1][m]);
136 return new_cnt - full_size;