Page 1 of 1
PCMPEQW - Compare Packed Data for Equal
Posted: Wed May 11, 2022 2:52 pm
by interfind
Hello, ich have a problem in using the SIMD compare function PCMPEQW.
I will do a compare WORD's in XMM registers of equality.
But it should only compare were the words are not ZERO.
here is my compare example:
Code: Select all
PCMPEQW xmm0, xmm1
xmm0: 0030 0000 0001 0000 0000 0000 0032 0000
xmm1: 0030 0000 0000 0000 0000 0000 0032 0000
result:
xmm0: FFFF FFFF 0000 FFFF FFFF FFFF FFFF FFFF
I want the following result
FFFF 0000 0000 0000 0000 0000 FFFF 0000
So only the WORD's that was not zero should be compared.
How can i do this in best way?
Re: PCMPEQW - Compare Packed Data for Equal
Posted: Sat May 14, 2022 3:57 pm
by STARGĂ…TE
Here a code with some additional operations:
Code: Select all
Structure EightWord
w.w[8]
EndStructure
Procedure.s EightWordStr(*W8.EightWord)
Protected String.s = RSet(Hex(*W8\w[0], #PB_Word), 4, "0")
Protected I.i
For I = 1 To 7
String + " " + RSet(Hex(*W8\w[I], #PB_Word), 4, "0")
Next
ProcedureReturn String
EndProcedure
Define *A.EightWord = ?A
Define *B.EightWord = ?B
Define *C.EightWord = ?C
Debug "xmm0: "+EightWordStr(*A)
Debug "xmm1: "+EightWordStr(*B)
! MOV rax, [p_A]
! MOVDQU xmm0, [rax] ; xmm0 = *A
! MOV rax, [p_B]
! MOVDQU xmm1, [rax] ; xmm1 = *B
! MOVDQA xmm2, xmm0 ; xmm2 = *A
! PXOR xmm3, xmm3 ; xmm3 = {0 0 0 0 0 0 0 0}
! PCMPEQW xmm0, xmm1 ; xmm0 = (*A == *B)
! PMAXUW xmm2, xmm1 ; xmm2 = Max(*A, *B)
! PCMPEQW xmm2, xmm3 ; xmm2 = (xmm2 == 0)
! PXOR xmm0, xmm2 ; xmm0 = xmm0 ! xmm2
! MOV rax, [p_C]
! MOVDQU [rax], xmm0 ; *C = xmm0
Debug "result: "+EightWordStr(*C)
DataSection
A: : Data.w $0030, $0000, $0001, $0000, $0000, $0000, $0032, $0000
B: : Data.w $0030, $0000, $0000, $0000, $0000, $0000, $0032, $0000
C: : Data.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000
EndDataSection
Re: PCMPEQW - Compare Packed Data for Equal
Posted: Sun May 15, 2022 8:36 am
by interfind
Hello Stargate, your solution is very nice and exactly that what i' looking for.
But i have i little problem to check the result correctly.
PCMPEQW sets the ZF-Flag, but here with Zero also count as equal.
And the PXOR don't set a Flag.
Can/must i do a !PMOVMSKB eax, xmm0 and then Test eax, eax after PXOR
to find out if my compare is euqal exempt zero's?
Or is there a better way do check the result?