I want VC++ to emit code like this:
vpxor ymm0, ymm0, ymm0
vmovdqa xmm0, xmm7
In human language, I want a 32-byte __m256i
value where the lowest 16 bytes come from another variable, and the highest 16 bytes are zero. An equivalent of _mm256_castsi128_si256
intrinsic, only I need the upper 128 bits to be zero, as opposed to undefined.
Here’s what I’ve tried:
_mm256_setr_m128i( low, _mm_setzero_si128() )
_mm256_insertf128_si256( _mm256_setzero_si256(), low, 0 )
Both lines above compile into vinsertf128
, relatively slow, 3-4 cycles latency, much slower than vmovdqa
. Any workaround for VC++ 2017?
vpxor ymm0, ymm0, ymm0
first; simply writing an XMM register with a VEX or EVEX encoded instruction likevmovdqa
(not legacy SSE) already zero-extends to full width. That's how 128-bit AVX instructions avoid false dependencies without SSE/AVX transition penalties. It's the same as writing a 32-bit integer register on x86-64. In fact, the most efficient way to zero a YMM register is with xor-zero of the corresponding XMM, so AMD CPUs before Zen2 still only need 1 uop. – Peter Cordes Feb 5 '20 at 10:59_mm256_setr_m128i
and the non-rset
version, you're probably screwed. Upvoted your question because it's an ever bigger missed optimization than you thought. It's possible with 1 uop with zero latency on IvB+ and Bulldozer/Zen. – Peter Cordes Feb 5 '20 at 11:02