PCMPEQW - Compare Packed Data for Equal

Bare metal programming in PureBasic, for experienced users
interfind
New User
New User
Posts: 7
Joined: Thu Apr 22, 2021 1:41 pm

PCMPEQW - Compare Packed Data for Equal

Post 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?
User avatar
STARGÅTE
Addict
Addict
Posts: 1761
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: PCMPEQW - Compare Packed Data for Equal

Post 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
PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 5.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
interfind
New User
New User
Posts: 7
Joined: Thu Apr 22, 2021 1:41 pm

Re: PCMPEQW - Compare Packed Data for Equal

Post 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?
Post Reply