Add upper and lower 64-bit of 128-bit xmm register

I have two packed whole squares in xmm0, and I need to add them together and save the result in a memory location. I can guarantee that the value of each integer is less than 2 ^ 15 . Now I am doing the following:

int temp;
....   

   movdq2q mm0, xmm0
   psrldq xmm0, 8
   movdq2q mm1, xmm0
   paddq mm0,mm1
   movd temp, mm0

Is there a better way to do this?

+3
source share
1 answer

First, why do you use quadrants to represent values ​​that fit in a 16-bit format? Leaving this aside, a couple of solutions:

pshufd xmm1, xmm0, EEh
paddq  xmm0, xmm1
movd   temp, xmm0

or

movdqa xmm1, xmm0
psrldq xmm1, 8
paddq  xmm0, xmm1
movd   temp, xmm0

or

movhlps xmm1, xmm0
paddq   xmm0, xmm1
movd    temp, xmm0

, paddq, , .

, - - , , . , , , - :

shufps  xmm0, xmm2, 88h
shufps  xmm4, xmm6, 88h
paddd   xmm0, xmm4
psrlq   xmm1, xmm0, 32
paddd   xmm0, xmm1
movhlps xmm1, xmm0
paddd   xmm0, xmm0
movd    temp, xmm0

.

EMMS, . , MMX, , x87, emms.

+3

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


All Articles