What is the purpose of xorps in the same register?

I was considering the following disassembled C ++ code

    auto test2 = convert<years, weeks>(2.0);
00007FF6D6475ECC  mov         eax,16Dh  
00007FF6D6475ED1  xorps       xmm1,xmm1  
00007FF6D6475ED4  cvtsi2sd    xmm1,rax  
00007FF6D6475ED9  mulsd       xmm1,mmword ptr [__real@4000000000000000 (07FF6D64AFE38h)]  
00007FF6D6475EE1  divsd       xmm1,mmword ptr [__real@401c000000000000 (07FF6D64AFE58h)] 

and it was curious what the point of instruction was xorps xmm1, xmm1. It seems that any xor would just give 0? If so, what is the purpose of clearing the register?

Note. I just ask for this out of sheer curiosity. I don't know much about assembler.

+4
source share
1 answer

The XMM register has 128 bits, and use cvtsi2sdonly fills the low 64 bits. Therefore, the command is xorpsused to clear possible values ​​of garbage and / or chains of dependencies that would otherwise affect subsequent operations.

Basically, the sequence of operations you have:

mov         eax, 16Dh       ; load 0x16D into lower 32 bits of RAX register
xorps       xmm1, xmm1      ; zero xmm1
cvtsi2sd    xmm1, rax       ; load lower 32 bits from RAX into xmm1
<do more stuff with xmm1>

, , . xor x, x .

. ( , ) , xor (mov x, 0, and x, 0).

+5

Source: https://habr.com/ru/post/1626665/


All Articles