Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing quadwords in xmm

using nasm to program in x86 assembly...

with MOVQ instruction I put m64 to xmm

MOVQ xmm1, qword [mymem64]

and now I want to compare it to zero so I can use Jcc

how it can be done and what instruction must use? (with quick look in manual I didn't found)

PS. I prefer Intel syntax :P

like image 812
davispuh Avatar asked Dec 27 '22 22:12

davispuh


2 Answers

Don't use SSE if you want to jump conditionally depending on the value. To be able to set the flags necessary for Jcc you need to store the value in a general purpose register. If you are on 64-bit you can do something like:

    mov     r8,[m64]
    test    r8,r8
    jnz     .out

If you're on 32-bit you can check the two parts separately:

    mov     eax,dword [m64]
    mov     edx,dword [m64+4]
    or      eax,edx
    jnz     .out    
like image 195
Jens Björnhager Avatar answered Dec 31 '22 14:12

Jens Björnhager


Note that it doesn't make sense to compare 64 bit operands in xmm registers, you can use general purpose registers for that.

If you need an AND or ANDN test against an operand you can use PTEST:

PTEST  XMM0, [yourmem128] ; compare
JZ     somewhere          ; jump if all bits of the logical and are zero

If you want to test two 64 bit operands, you need to use PCMPEQQ

PCMPEQQ  XMM0, [yourmem128] ; compare two 64 bit words
PEXTRQ   RAX, XMM0, 1       ; upper 64 bit
MOVQ     RBX, XMM0          ; lower 64 bit
OR       RAX, RBX
NEG      RAX
JZ       somewhere          ; jump if at least one word is zero
like image 45
Gunther Piez Avatar answered Dec 31 '22 14:12

Gunther Piez