News:

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

Main Menu

MMX Question

Started by Farabi, December 17, 2012, 05:11:07 PM

Previous topic - Next topic

Farabi

I had 4 data of bytes, I want to convert it to a 4 data of words. How to do that using MMX? All data are integers.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

qWord

hi,
MMX is outdated and should no longer used - use SSEx instead. For you question, see the unpack instructions:
mov eax,04030201h
movd xmm0,eax
pxor xmm1,xmm1
punpcklbw xmm0,xmm1
movq QWORD ptr ...,xmm0 ; store 4 WORDs

note that you could process 8 bytes in one XMM register. Also, it works only for unsigned integers.
(For an array of DWORDs, there are much better implementation possible.)
MREAL macros - when you need floating point arithmetic while assembling!

Farabi

http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

frktons

Quote from: qWord on December 17, 2012, 05:53:09 PM
hi,
MMX is outdated and should no longer used - use SSEx instead. For you question, see the unpack instructions:
mov eax,04030201h
movd xmm0,eax
pxor xmm1,xmm1
punpcklbw xmm0,xmm1
movq QWORD ptr ...,xmm0 ; store 4 WORDs

note that you could process 8 bytes in one XMM register. Also, it works only for unsigned integers.
(For an array of DWORDs, there are much better implementation possible.)

With these instructions you are creating 8 words in a 16 byte register.
If you need only 4 words, you can also use MMX registers with the same
instructions, if I correctly remember.

This is the transformation of qWord code:

mov eax,04030201h
movd mm0,eax
pxor mm1,mm1
punpcklbw mm0,mm1
movq QWORD ptr ...,mm0 ; store 4 WORDs
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

frktons

This is how Intel shows the functioning of PUNPCKLBW.
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

Farabi

Quote from: frktons on December 24, 2012, 02:44:48 PM
This is how Intel shows the functioning of PUNPCKLBW.

Im still figuring out what this instruction used for in real life.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

frktons

Quote from: Farabi on December 17, 2012, 05:11:07 PM
I had 4 data of bytes, I want to convert it to a 4 data of words. How to do that using MMX? All data are integers.

Quote from: Farabi on December 24, 2012, 02:50:27 PM
Im still figuring out what this instruction used for in real life.

Why do you need to convert 4 bytes into 4 words? That's why they created PUNPCKLBW.
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

Farabi

Quote from: frktons on December 24, 2012, 02:59:08 PM
Quote from: Farabi on December 17, 2012, 05:11:07 PM
I had 4 data of bytes, I want to convert it to a 4 data of words. How to do that using MMX? All data are integers.

Quote from: Farabi on December 24, 2012, 02:50:27 PM
Im still figuring out what this instruction used for in real life.

Why do you need to convert 4 bytes into 4 words? That's why they created PUNPCKLBW.

I need that to make the substraction easy, sometime I need to multiply the byte data by 100 and then divide it by 200. Using byte data type it wont fit.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

frktons

Quote from: Farabi on December 24, 2012, 03:02:45 PM

I need that to make the substraction easy, sometime I need to multiply the byte data by 100 and then divide it by 200. Using byte data type it wont fit.

And then you can use PUNPCKLBW to have 4/8 single bytes moved
into 4/8 words in one instruction. Isn't it useful?
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

shr al,1
or, if you are nit-picking
shr al,1
adc al,0


:P

Farabi

Quote from: frktons on December 24, 2012, 03:11:12 PM
Quote from: Farabi on December 24, 2012, 03:02:45 PM

I need that to make the substraction easy, sometime I need to multiply the byte data by 100 and then divide it by 200. Using byte data type it wont fit.

And then you can use PUNPCKLBW to have 4/8 single bytes moved
into 4/8 words in one instruction. Isn't it useful?

Yeah it should be usefull if I understand it right.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

dedndave

if you use PCMGTB first, you could use it to sign-extend bytes to words   :P

frktons

It is not too difficult to understand:

mov eax,04030201h
movd mm0,eax
pxor mm1,mm1
punpcklbw mm0,mm1
movq QWORD ptr ...,mm0 ; store 4 WORDs


1) you move your 4 bytes into a register (EAX)
2) you move EAX to an MMX register
3) you put zero to another MMX register
4) you intermix bytes from dest MMX and src MMX
5) you have 4 words into the MMX dest register
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

frktons

Have a look at Intel Manuals:

http://www.intel.it/content/www/it/it/search.html?keyword=developer%CA%B9s+manual
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

Farabi

Quote from: frktons on December 24, 2012, 02:44:48 PM
This is how Intel shows the functioning of PUNPCKLBW.

O I get it. If I want to fill the high order of the word fill it on the src, if the other wise, fill it on the dest.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165