Hi Guys, im trying to build a serie of routines to be converted to a macro using only MMX instructions.

The goals is to analyse the performance and speed gains to this kind of routines to improve developments in some OpenGL, DX demos or tutorials when facing loops for example.

For you get an idea of what im trying to do, I made a serie of macros related to FPU that i wanted to port also a similar usage for MMX (Not SSE.. only MMX due to processors compatibily. I mean, not all processors have SSE, but all since PI have MMX, right ?)

Example:

Fpu_If F$nSize <= F$nBottom
?  ?  ? mov D$bFlag 1
Fpu_End_If

That is:

FLD F$NBOTTOM
FLD F$NSIZE
FCOMPP
FSTSW AX
FWAIT
SAHF
JNBE R0>>
  mov D$bFlag 1
R0:



What is needed is a similar way to load the Variables in the MMX Registers and perform the comparition.

I read some MMX instructions sets, but im quite confused about its correct usage. I dont know how to load the value to the MMX register and neither how to perform the comparitions. Also for what i saw if on the app that uses MMX and also uses FPU coding we need to reset the MMX values using emms, right ?

The goal is making a serie of macros like:

MMX_If Variable (or any MMX register) > Variable2(or any MMX register)
(....)
MMX_End_If

MMX_If Variable (or any MMX register) >= Variable2(or any MMX register)
(....)
MMX_End_If

MMX_If Variable (or any MMX register) < Variable2(or any MMX register)
(....)
MMX_End_If

MMX_If Variable (or any MMX register) <= Variable2(or any MMX register)
(....)
MMX_End_If


MMX_If Variable (or any MMX register) = Variable2(or any MMX register)
(....)
MMX_End_If



MMX_While Variable (or any MMX register) = Variable2(or any MMX register)
(....)
MMX_End_While


and so on.


Have someone did anything like this before ? How can this be done ?


Best Regards,

Guga
Posted on 2006-07-12 13:52:39 by Beyond2000!
Hi Guys

Ok, The following code seems to work. It compares for equality of the variables, and place the MMX result in eax. IF the values are eqaul, eax = 0-1, otherwise it is 0.

But.. how to clear the MMX stack ? And also clear the FPU ? This is because after comparing, they inserts QNAN, NAN or INF results in FPU, and specify 0 or 0-1 in MMX. How to clear all of that after using the MMX ?

I mean, we could use finit to clear FPU.. but how is the usage for MMX ?




movq MM0 Q$Data1
movq MM1 Q$Data2
PCMPEQD MM0 MM1 ; compare for equal
movd eax MM0
test eax eax | jz L2> ; Eax = 0-1 equal. Eax = 0 not equal
?  ?  ? mov eax 1 ; If eqaul. Go Here
L2:


Best Regards,

Guga
Posted on 2006-07-12 15:17:36 by Beyond2000!
Ok, this sems to work as a If Data1 = Data2 comparition




movq MM0 Q$Data1
movq MM1 Q$Data2
PCMPEQD MM0 MM1 ; compare for equal
movd eax MM0?  ?  ; Copy the result to eax
pxor MM0 MM0 ; Clear MM0 Register
pxor MM1 MM1 ; Clear MM1 Register
finit ; Empty FPU Stack
emms ; empty mmx state
test eax eax | jz L2> ; Eax = 0-1 equal. Eax = 0 not equal
    mov eax 1 ; If equal. Go Here
L2:


Since im using pxor to clear the MMX registers, and emms to reset the state of them, it seems to be correct, right ?

Is the above teh correct way to clear and empty MMX and FPU registers ?

One question. The MMX instructions runs on AMD processor ? Will the above code work on AMD ?


Best Regards,

Guga
Posted on 2006-07-12 15:45:04 by Beyond2000!
The test isn't correct.

pcmpeqd  ?  MM0, MM1 ; compare for equal
movd  ?       eax, MM0?  ; Copy the result to eax

The PCMPEQD will compare corresponding dwords in MM0 and MM1
with the two results stored in MM0, both the upper and lower dword halves,
0 if a pair is unequal or -1 (all 32 bits set to 1) if equal.
But you only check if the lower dwords are equal by moving the lower
dword into eax.

You need this or an equivalent following the above instructions
psrlq mm0, 32
movd edx, mm0

then later

test eax, edx
Posted on 2006-07-12 18:56:21 by dsouza123