Compare Bytes

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

Compare Bytes

Post by interfind »

Hello,

I'm looking for a SIMD command (SSE or AVX) to compare
single bytes in a ymm0, ymm1 Register or in memory.
I find VPCMPEQB, can i do it with this command?
The bytes can be on different place in the register.

I will get the number of bytes that's equal.

Example:
20, 96, 12, 67, 150, 55, 1, 123...
73, 1, 80, 45, 20, 123, 210, 21...
Here i have 3 equal bytes as result.
How can i do this?


Interfind
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Compare Bytes

Post by Keya »

it's not something I've tried, but my googling also suggests VPCMPEQB, as you found, though I have a feeling it won't operate as you require because you want to compare every byte in array A with every byte in array B (eg. N passes instead of 1), whereas as VPCMPEQB is SIMD i think it simply compares A[0] with B[0], A[1] with B[1], A[2] with B[2] etc, in the 1 pass ... the docs seem to suggest this - "If a pair of data elements is equal, the corresponding data element in the destination operand is set to all 1s; otherwise, it is set to all 0s" (the bytes which match are set to 1, otherwise 0)

At this stage I would try to write the solution in C, and see what the compiler builds as the assembly code - it's an interesting little challenge because it should be fairly straight-forward (probably just two loops - the first iterating over each byte from array A, the second loop iterating over each byte from array B), so it should be fascinating to see how easy an assembler can make this - it seems very "ripe for the picking" for an assembler to optimise
Post Reply