flat assembler
Message board for the users of flat assembler.

 Index > Main > floating point cmp, bit twiddling expertise needed
Author
tthsqe

Joined: 20 May 2009
Posts: 766
tthsqe 01 Dec 2013, 11:54
We can determine if two 128-bit sse registers xmm0 and xmm1 have exactly the same bit pattern with
Code:
```pcmpeqb xmm0,xmm1
pmovmskb  eax,xmm0
cmp  ax,-1    ```

but unfortunately this cannot be extended to 256 bits because vpcmpeqb is not supported on 256-bit operands in AVX.
Is it possible to get the same functionality in AVX by using the floating point operations? (The floating point ops are supported in AVX.)
Code:
```vcmpeqpd ymm2,ymm0,ymm1
vmovmskpd  eax,ymm2
cmp  eax,01111b    ```

This doesn't work because 0x8000000000000000, and 0x0000000000000000 are treated as equal.
01 Dec 2013, 11:54
cod3b453

Joined: 25 Aug 2004
Posts: 618
cod3b453 01 Dec 2013, 13:38
I don't have a processor with AVX to try this but maybe:
Code:
```vptest ymm0,ymm1
j[c/z] ...    ```
01 Dec 2013, 13:38
tthsqe

Joined: 20 May 2009
Posts: 766
tthsqe 01 Dec 2013, 14:03
ah, this is very good! Thanks, cod3b453! I completely forgot about ptest.
Actually, I think the following are correct
Code:
```; zero test
; if (ymm0=0), then a, else b
jz  a
b:
a:

; another zero test
; if (ymm0=0), then a, else b
vxorps  ymm1,ymm1,ymm1
vptest  ymm1,ymm0
jc  a
b:
a:

; equality test
; if (ymm0=ymm1), then a, else b
vxorps  ymm2,ymm0,ymm1
jz  a
b:
a:

align 32
mask: dq -1,-1,-1,-1    ```
01 Dec 2013, 14:03
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum