3 ms·
I was a little confused by the assembler in the fourth tweet. Here is what I think is going on. First the code: 1. vxorps %xmm0, %xmm0, %xmm0 2. vmovups %y
by dan-robertson 5y ago
I was a little confused by the assembler in the fourth tweet. Here is what I think is going on. First the code:
1. vxorps %xmm0, %xmm0, %xmm0
2. vmovups %ymm0, 11(%rdi)
3. vmovups %ymm0, (%rdi)
4. vzeroupper
So line 1 sets xmm0, a 128 bit/16 byte register, to 0 (by xoring it with itself). I suppose the convention is for the caller to save the register if it wants it. The thing that confused me is that the way 256 bit/32 byte registers work is that ymmX represents the 256 bit register of which xmmX is the lower half. Similar to the way %eax is the lower 32 bits of %rax. I suppose the upper half of %ymm0 is 0 by ABI.
So line 2 then writes out this 32-byte register (of zeros) starting at buffer[11] and ending at buffer[42]. The actual instruction name stands for “vector move unaligned packed single precision floats” and I don’t really understand why the precision or float type matters.
Line 3 writes it from buffer[0] to buffer[31]. I guess the overlap isn’t expensive.
Line 4 zeros the upper half of the register which is a no-op in this case but might be useful as it breaks the dependency chain so the cpu can know nothing else will need to use the current upper-half values (but isn’t it useful to break the chain on the lower half too?).