News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MMX mask question

Started by nunos, January 26, 2010, 01:23:39 AM

Previous topic - Next topic

nunos

This is very simple, but I haven't been able to figure it out yet.

This question is regarding a assembly mmx, but it's pure logic.

Imagine the following scenario:

    MM0: 04 03 02 01 04 03 02 01  <-- input 
    MM1: 02 02 02 02 02 02 02 02 
    MM2: 04 03 02 01 04 03 02 01  <-- copy of input
   
    after pcmpgtw MM0, MM1
   
    MM0: FF FF 00 00 FF FF 00 00  <-- words where MM0 is greater than MM1 (comparing words) 
    MM1: 02 02 02 02 02 02 02 02 
    MM2: 04 03 02 01 04 03 02 01
   
    after pand MM0, MM2 
   
    MM0: 04 03 00 00 04 03 00 00  <-- almost there...
    MM1: 02 02 02 02 02 02 02 02 
    MM2: 04 03 02 01 04 03 02 01 


What I want is to know fill the zeros of MM0 with 02. I suppose I would have to invert MM0 register in step2, changing the FF's to 00's and the 00's to FF's and then do a and to MM1 and finally a or to merge the two.

If I was able to get:

    MM3: 00 00 FF FF 00 00 FF FF
   
    then, pand MM2, MM3

    MM1: 04 03 00 00 04 03 00 00 
    MM2: 00 00 02 02 00 00 02 02
   
    finally por MM0, MM1 would give me the desired outcome:
   
    MM0: 04 03 02 02 04 03 02 02  <-- Aha!


Any answer is greatly appreciated. Thanks.

drizz

There are many ways to do a NOT in mmx ( too bad there isn't any instruction like pnot)


  •    pcmpeqd mm3,mm3
       pandn mm0,mm3

  •    pcmpeqd mm3,mm3
       pxor mm3,mm0;; XOR REG, 0FFFFFFFFh ;; invert all bits

  •    pxor mm3,mm3
       pcmpeqw mm0,mm3;; FFFF and 0000 words assumed



The truth cannot be learned ... it can only be recognized.

nunos

Quote from: drizz on January 26, 2010, 07:01:14 AM
There are many ways to do a NOT in mmx ( too bad there isn't any instruction like pnot)


  •    pcmpeqd mm3,mm3
       pandn mm0,mm3

  •    pcmpeqd mm3,mm3
       pxor mm3,mm0;; XOR REG, 0FFFFFFFFh ;; invert all bits

  •    pxor mm3,mm3
       pcmpeqw mm0,mm3;; FFFF and 0000 words assumed





That worked. Thanks for your reply.