Folkert de Vries c958a7c66e
[X86] use VPMADDWD for widening adjacent addition (#174149)
The `_mm256_madd_epi16` intrinsic performs first a pointwise widening
multiplication, and then adds adjacent elements. In SIMD versions of the
adler32 checksum algorithm, a trivial multiplication by an all-ones
vector is used to get just the widening and addition behavior.

In the rust standard library, we like to implement intrinsics in terms
of simpler building blocks, so that all backends can implement a small
set of primitives instead of supporting all of LLVM's intrinsics. When
we try that for `_mm256_madd_epi16` in isolation it works, but when one
of the arguments is an all-ones vector, the multiplication is optimized
out long before the `vpmaddwd` instruction can be selected.

This PR recognizes the widening adjacent addition pattern that adler32
uses directly, and manually inserts a trivial multiplication by an
all-ones vector. Experimentally, performing this optimization increases
adler32 throughput from 41 gb/s to 67 gb/s
(https://github.com/rust-lang/rust/issues/150560#issue-3774170588)

cc https://github.com/rust-lang/stdarch/pull/1985
cc https://github.com/rust-lang/rust/issues/150560
2026-01-06 14:51:59 +00:00
..