Skip to content

Commit d2ef239

Browse files
committed
Add avx2::mm_blend_*
1 parent 5a8a827 commit d2ef239

File tree

2 files changed

+315
-0
lines changed

2 files changed

+315
-0
lines changed

src/avx2.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,28 @@ pub fn mm256_avg_epu8(a: m256i, b: m256i) -> m256i {
131131

132132
// vpblendw
133133
// __m256i _mm256_blend_epi16 (__m256i a, __m256i b, const int imm8)
134+
#[inline]
135+
pub fn mm256_blend_epi16(a: m256i, b: m256i, imm8: i32) -> m256i {
136+
let x: i16x16 = blend_shuffle16!(a.as_i16x16(), b.as_i16x16(), imm8);
137+
x.as_m256i()
138+
}
139+
134140
// vpblendd
135141
// __m128i _mm_blend_epi32 (__m128i a, __m128i b, const int imm8)
142+
#[inline]
143+
pub fn mm_blend_epi32(a: m128i, b: m128i, imm8: i32) -> m128i {
144+
let x: i32x4 = blend_shuffle4!(a.as_i32x4(), b.as_i32x4(), imm8);
145+
x.as_m128i()
146+
}
147+
136148
// vpblendd
137149
// __m256i _mm256_blend_epi32 (__m256i a, __m256i b, const int imm8)
150+
#[inline]
151+
pub fn mm256_blend_epi32(a: m256i, b: m256i, imm8: i32) -> m256i {
152+
let x: i32x8 = blend_shuffle8!(a.as_i32x8(), b.as_i32x8(), imm8);
153+
x.as_m256i()
154+
}
155+
138156
// vpblendvb
139157
// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
140158
// vpbroadcastb
@@ -677,6 +695,37 @@ mod tests {
677695
[1 ^ 2, 2 ^ 3, 3 ^ 4, 4 ^ 5, 5 ^ 6, 6 ^ 7, 7 ^ 8, 8 ^ 9]);
678696
}
679697

698+
#[test]
699+
fn test_blend() {
700+
{
701+
let a = mm256_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
702+
let b = mm256_setr_epi16(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32);
703+
704+
assert_eq!(mm256_blend_epi16(a, b, 0).as_i16x16().as_array(),
705+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
706+
assert_eq!(mm256_blend_epi16(a, b, 0xFF).as_i16x16().as_array(),
707+
[17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]);
708+
assert_eq!(mm256_blend_epi16(a, b, 0x11).as_i16x16().as_array(),
709+
[17, 2, 3, 4, 21, 6, 7, 8, 25, 10, 11, 12, 29, 14, 15, 16]);
710+
}
711+
{
712+
let a = mm_setr_epi32(1, 2, 3, 4);
713+
let b = mm_setr_epi32(11, 12, 13, 14);
714+
715+
assert_eq!(mm_blend_epi32(a, b, 0).as_i32x4().as_array(), [1, 2, 3, 4]);
716+
assert_eq!(mm_blend_epi32(a, b, 0xFF).as_i32x4().as_array(), [11, 12, 13, 14]);
717+
assert_eq!(mm_blend_epi32(a, b, 0x03).as_i32x4().as_array(), [11, 12, 3, 4]);
718+
}
719+
{
720+
let a = mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 8);
721+
let b = mm256_setr_epi32(11, 12, 13, 14, 15, 16, 17, 18);
722+
723+
assert_eq!(mm256_blend_epi32(a, b, 0).as_i32x8().as_array(), [1, 2, 3, 4, 5, 6, 7, 8]);
724+
assert_eq!(mm256_blend_epi32(a, b, 0xFF).as_i32x8().as_array(), [11, 12, 13, 14, 15, 16, 17, 18]);
725+
assert_eq!(mm256_blend_epi32(a, b, 0x11).as_i32x8().as_array(), [11, 2, 3, 4, 15, 6, 7, 8]);
726+
}
727+
}
728+
680729
#[test]
681730
fn test_unpack() {
682731
assert_eq!(mm256_unpacklo_epi8(seq8(), mseq8()).as_i8x32().as_array(),

0 commit comments

Comments
 (0)