Hi, I'm wiritng some code that needs to do something, anyway I have a register, say MM0 that has an array of 8 bytes, I want to convert the lower 4 bytes to WORDS, so I can use the PMULLW instruction and then convert the result back, anyone want to help me go about this? Your help is very much appreciated.
Posted on 2003-03-24 15:28:27 by x86asm
a word is 2 bytes...

are you saying you have:
MM0 dq 0000AAAA0000BBBB0000CCCC0000DDDD

where (A-D) represent a word number and 0s are padding and you want to multiply the individual parts?

assuming you want to multiply by:
MM1 dq 0000aaaa0000bbbb0000cccc0000dddd

pmullw mm0,mm1

and you get



where each part encompased by a square bracket is a word. result is in mm0.

if you're trying to do this:
MM0 dq 00000000AAAAAAAA00000000BBBBBBBB
x MM1 dq 00000000aaaaaaaa00000000bbbbbbbb


i have some ugly code =D (don't think there is a pror instruction...)
movq eax,mm0
movq ebx,mm1

imul ebx
movq mm2,mm0

movq mm3,mm1
psrlq mm2,32

psrlq mm3,32
movq mm0,eax

push eax

movq eax,mm2
movq ebx,mm3

imul ebx

movq mm0,eax

pop eax
psllq mm0,32

movq mm0,eax

gives you


where each bracket is a DWORD.
Posted on 2003-03-24 16:16:05 by jademtech

a word is 2 bytes...

are you saying you have:
MM0 dq 0000AAAA0000BBBB0000CCCC0000DDDD

where (A-D) represent a word number and 0s are padding and you want to multiply the individual parts?

assuming you want to multiply by:
MM1 dq 0000aaaa0000bbbb0000cccc0000dddd

pmullw mm0,mm1

and you get



where each part encompased by a square bracket is a word. result is in mm0.

if you're trying to do this:
MM0 dq 00000000AAAAAAAA00000000BBBBBBBB
x MM1 dq 00000000aaaaaaaa00000000bbbbbbbb


i have some ugly code =D (don't think there is a pror instruction...)
movq eax,mm0
movq ebx,mm1

imul ebx
movq mm2,mm0

movq mm3,mm1
psrlq mm2,32

psrlq mm3,32
movq mm0,eax

push eax

movq eax,mm2
movq ebx,mm3

imul ebx

movq mm0,eax

pop eax
psllq mm0,32

movq mm0,eax

gives you


where each bracket is a DWORD.


ya, but you see the tricky part is the unpack and pack instructions they are confusing the heck out of me, I'll give you a diagram as well (I think I should have done that the first time around, ah well :) )

say I have MM0 like this (each digit is a nibble)
MM0={00000000AABBCCDD}

I want to get lets say MM2 to be like this:
MM2={00AA00BB00CC00DD}

Then once the PMULLW finishes I would like to put it back to the original format.
I think I can do this with the PUNPCK

These are the instruction, I have yet to test it as I havent finished the code, but I hope this is the right way:


punpcklbw mm2,mm0
packuswb mm2,mm0 ;Convert the data back to bytes
Posted on 2003-03-24 20:19:24 by x86asm
if you want each of AA, BB, CC, and DD to be multiplied by something else, and then stored, saturated such that if AA*aa>255(d), then store 255 in the original location of AA, then that code seems correct.
Posted on 2003-03-24 21:57:53 by jademtech

if you want each of AA, BB, CC, and DD to be multiplied by something else, and then stored, saturated such that if AA*aa>255(d), then store 255 in the original location of AA, then that code seems correct.


Thanks man, BTW r u in OAC, which University did u get in?
Posted on 2003-03-25 07:16:21 by x86asm
aye. OAC - sorta. i go to UTS, which combined grade 7/8/9 into two years, so i'd normally be in grade 12. i applied for Waterloo and Trinity College @ UT... somehow, i have the feeling i'm not getting in :rolleyes: stupid algeo marks... Waterloo won't even begin looking at applications until the end of this month.
Posted on 2003-03-25 08:08:20 by jademtech