Skip to content

Commit 6f50351

Browse files
author
Guillaume Piolat
committed
Add support for _mm256_blendv_epi8
1 parent 7660354 commit 6f50351

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

source/inteli/avx2intrin.d

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,43 @@ unittest
585585
assert(C.array == correct);
586586
}
587587

588-
// TODO __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask) pure @safe
588+
/// Blend packed 8-bit integers from `a` and `b` using `mask`.
589+
/// Select from `b` if the high-order bit of the corresponding 8-bit element in `mask` is set, else select from `a`.
590+
__m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask) pure @safe
591+
{
592+
static if (LDC_with_AVX2)
593+
{
594+
return cast(__m256i) __builtin_ia32_pblendvb256(cast(byte32)a, cast(byte32)b, cast(byte32)mask);
595+
}
596+
else
597+
{
598+
__m128i a_lo = _mm256_extractf128_si256!0(a);
599+
__m128i a_hi = _mm256_extractf128_si256!1(a);
600+
__m128i b_lo = _mm256_extractf128_si256!0(b);
601+
__m128i b_hi = _mm256_extractf128_si256!1(b);
602+
__m128i m_lo = _mm256_extractf128_si256!0(mask);
603+
__m128i m_hi = _mm256_extractf128_si256!1(mask);
604+
__m128i r_lo = _mm_blendv_epi8(a_lo, b_lo, m_lo);
605+
__m128i r_hi = _mm_blendv_epi8(a_hi, b_hi, m_hi);
606+
return _mm256_set_m128i(r_hi, r_lo);
607+
}
608+
}
609+
unittest
610+
{
611+
__m128i A = _mm_setr_epi8( 0, 1, 2, 3, 4, 5, 6, 7,
612+
8, 9, 10, 11, 12, 13, 14, 15);
613+
__m128i B = _mm_setr_epi8(16, 17, 18, 19, 20, 21, 22, 23,
614+
24, 25, 26, 27, 28, 29, 30, 31);
615+
__m128i M = _mm_setr_epi8( 1, -1, 1, 1, -4, 1, -8, 127,
616+
1, 1, -1, -1, 4, 1, 8, -128);
617+
__m256i AA = _mm256_set_m128i(A, A);
618+
__m256i BB = _mm256_set_m128i(B, B);
619+
__m256i MM = _mm256_set_m128i(M, M);
620+
byte32 R = cast(byte32) _mm256_blendv_epi8(AA, BB, MM);
621+
byte[32] correct = [ 0, 17, 2, 3, 20, 5, 22, 7, 8, 9, 26, 27, 12, 13, 14, 31,
622+
0, 17, 2, 3, 20, 5, 22, 7, 8, 9, 26, 27, 12, 13, 14, 31 ];
623+
assert(R.array == correct);
624+
}
589625

590626
/// Broadcast the low packed 8-bit integer from `a` to all elements of result.
591627
__m128i _mm_broadcastb_epi8 (__m128i a) pure @safe

source/inteli/emmintrin.d

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4591,11 +4591,7 @@ unittest
45914591
__m128i _mm_srli_epi64 (__m128i a, int imm8) pure @trusted
45924592
{
45934593
// PERF DMD
4594-
static if (GDC_with_SSE2)
4595-
{
4596-
return cast(__m128i) __builtin_ia32_psrlqi128(cast(long2)a, cast(ubyte)imm8);
4597-
}
4598-
else static if (LDC_with_SSE2)
4594+
static if (GDC_or_LDC_with_SSE2)
45994595
{
46004596
return cast(__m128i) __builtin_ia32_psrlqi128(cast(long2)a, cast(ubyte)imm8);
46014597
}

source/inteli/smmintrin.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ unittest
143143
}
144144

145145
/// Blend packed 8-bit integers from `a` and `b` using `mask`.
146-
__m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask) @trusted
146+
/// Select from `b` if the high-order bit of the corresponding 8-bit element in `mask` is set, else select from `a`.
147+
__m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask) pure @trusted
147148
{
148149
// PERF DMD
149150
/*static if (GDC_with_SSE41)

0 commit comments

Comments
 (0)