Efficiently Set Lowest 64 Bits of YMM Register to Constant
-
04-12-2019 - |
Question
How can I set the lowest 64 bits of a YMM register to some constant, in the least number of clock cycles? I know various ways that I can do this using SSE instructions, as well as the AVX instruction VBROADCASTSD
, but I'm not sure which method will yield the best result.
Edit: I still need to use the complete YMM register after setting the 64-bit part.
Thanks for your help!
La solution
If you only need to set lowest 64 bits and other YMM bits do not matter, use VMOVQ
.
If you need to preserve other bits in YMM register, the most efficient way is to use VBLENDPD
. Alternatively, you can clear the lowest 64 bits with VANDPD
, then load the constant with VORPD
.
AVX2 allows other alternatives to do it: VPMASKMOVD
or VPBLENDD
(but it is not yet supported by any processor).