News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

MASM FOR FUN - REBORN - #0 Extract low order bytes from dwords

Started by frktons, November 25, 2012, 02:48:06 AM

Previous topic - Next topic

frktons

Quote from: qWord on November 29, 2012, 04:50:32 AM
What do you want to compare? FP or integer value?

xmm integer packed data is what I'd like to compare.

I want to know, for example, if xmm0 is equal to xmm1.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

qWord

Quote from: frktons on November 29, 2012, 04:54:25 AM
Quote from: qWord on November 29, 2012, 04:50:32 AM
What do you want to compare? FP or integer value?

xmm integer packed data is what I'd like to compare.

I want to know, for example, if xmm0 is equal to xmm1.
so, you are rigth with PCMPEQxx + PMOVMSKB.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: qWord on November 29, 2012, 04:50:32 AM
What do you want to compare? FP or integer value?

Test for equality only, so FP or INT won't make a difference. Although I wonder how CMPNEQPS aka CMPPS xmmDest, xmmSrc, 4 handles exotic cases (NaN vs 0 etc). In any case, PCMPEQxx is the right choice, as qWord already wrote.


qWord

Quote from: jj2007 on November 29, 2012, 05:02:03 AM
Although I wonder how CMPNEQPS aka CMPPS xmmDest, xmmSrc, 4 handles exotic cases (NaN vs 0 etc).
can't wok because there are N possibilities to represent a NaN, whereas CMPxxPS returns true for all pairs of NaNs.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: qWord on November 29, 2012, 05:07:05 AM
can't wok because there are N possibilities to represent a NaN, whereas CMPxxPS returns true for all pairs of NaNs.

Grazie, good to know :t

qWord

Quote from: jj2007 on November 29, 2012, 05:13:34 AM
Quote from: qWord on November 29, 2012, 05:07:05 AM
can't wok because there are N possibilities to represent a NaN, whereas CMPxxPS returns true for all pairs of NaNs.

Grazie, good to know :t
ups..., that applies for the unordered compare, for CMPEQPS it allways return false.
MREAL macros - when you need floating point arithmetic while assembling!

frktons

I'm glad to see everybody agreed eventually.  :t

Now let's go further.

How do I compare for greater than?
:P

Same registers, same data type.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave


qWord

Quote from: frktons on November 29, 2012, 05:24:12 AM
Now let's go further.

How do I compare for greater than?
:P

Same registers, same data type.
PCMPGTD  ::)
MREAL macros - when you need floating point arithmetic while assembling!

frktons

Quote from: qWord on November 29, 2012, 06:20:50 AM
Quote from: frktons on November 29, 2012, 05:24:12 AM
Now let's go further.

How do I compare for greater than?
:P

Same registers, same data type.
PCMPGTD  ::)

Thanks qWord, maybe this time I'll take less time to get the info.
Well it looks quite simple to manage:
Quote
If a data element in the destination operand is greater
than the corresponding date element in the source operand, the corresponding data
element in the destination operand is set to all 1s; otherwise, it is set to all 0s.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

nidud

deleted

nidud

deleted

frktons

Quote from: nidud on November 29, 2012, 08:32:39 AM
To conclude:

pcmpeqb compares 16 bytes, pcmpeqd compares 4 doublewords, result in xmm0 is the same.
pcmpgtb compares 16 bytes, pcmpgtd compares 4 doublewords, result in xmm0 is not the same.


pcmpeqb xmm0,xmm1 ; xmm0 to FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFh if equal
pmovmskb eax,xmm0 ; eax to 0000FFFFh
cmp ax,0FFFFh
je is_equal

pcmpgtb xmm0,xmm1 ; xmm0 to FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFh if greater
pmovmskb eax,xmm0 ; eax to 0000FFFFh
cmp ax,8000h ; ?
jle is_great



I don't think so about the test for GT. So far I got:

when we use pcmpgtb
we have FF only in the bytes that are greater, not all of them,
and the same for the dword, with pcmpgtd,only the dword that are greater
are switched to FF, the remaining of them are switched to
00 if are equal or less than.

Instead of this:

pcmpgtb xmm0,xmm1 ; xmm0 to FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFh if greater
pmovmskb eax,xmm0 ; eax to 0000FFFFh
cmp ax,8000h ; ?
jle is_great


Something like:


pcmpgtd xmm0,xmm1
pmovmskb eax,xmm0
        .if bit ax, 15
            jmp IsGreater
        .endif


If bit 15 not 1 The way is longer, and we have to test
other things:


pcmpgtd xmm2,xmm3; same values in reverse order
pmovmskb ebx,xmm2
        .if bit bx, 15
            jmp IsGreater;  The second original value tested
        .endif
        .if ax == bx
            jmp AreEqual
        .elseif ax > bx
            jmp IsGreater
        .else
            jmp IsLessThan
        .endif


Not already tested, but this is the idea.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

nidud

deleted

frktons

Quote from: nidud on November 29, 2012, 10:59:37 AM

The upper byte should always be the same (FF,? or FFFFFFFF,? if greater)

Yes and not. It depends if the byte or dword tested is greater, not the whole xmm register.
But if upper byte or word or dword is FF, you know the entire xmm register is greater, otherwise
you have to check other things.

Quote from: frktons on November 29, 2012, 09:52:49 AM

pcmpgtd xmm2,xmm3; same values in reverse order
pmovmskb ebx,xmm2
        .if bit bx, 15
            jmp IsGreater;  The second original value tested
        .endif
        .if ax == bx
            jmp AreEqual
        .else
            jmp IsLessThan; The second original value tested
        .endif

Not already tested, but this is the idea.

assuming ax is zero, I think that is correct
[/quote]

I modified the code, there was a logical error, have a look.
It should work with whatever value ax and bx assume.

Quote
same as:
test ah,80h
jnz is_great
test ax,ax
jz is_equal
jmp is_less



I think you have to use 2 registers not only ax. According to my understanding
you cannot check if greater, equal or less than with a single passage. Only
if you are lucky you can find the answer in the first check, if the upper byte is FF
you can say xmm0 is greater than xmm1.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama