Skip to content

Commit 8a883ad

Browse files
committed
add test for multiply by one pattern
1 parent 1a3a6b2 commit 8a883ad

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

crates/core_arch/src/x86/avx2.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4669,6 +4669,16 @@ mod tests {
46694669
assert_eq_m256i(r, e);
46704670
}
46714671

4672+
#[target_feature(enable = "avx2")]
4673+
#[cfg_attr(test, assert_instr(vpmaddwd))]
4674+
unsafe fn test_mm256_madd_epi16_mul_one(mad: __m256i) -> __m256i {
4675+
// This is a trick used in the adler32 algorithm to get a widening addition. The
4676+
// multiplication by 1 is trivial, but must not be optimized out because then the vpmaddwd
4677+
// instruction is no longer selected. The assert_instr verifies that this is the case.
4678+
let one_v = _mm256_set1_epi16(1);
4679+
_mm256_madd_epi16(mad, one_v)
4680+
}
4681+
46724682
#[simd_test(enable = "avx2")]
46734683
const fn test_mm256_inserti128_si256() {
46744684
let a = _mm256_setr_epi64x(1, 2, 3, 4);

0 commit comments

Comments
 (0)