News:

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

MMX Graphics

Started by OceanJeff32, February 06, 2005, 04:44:25 AM

Previous topic - Next topic

OceanJeff32

 ::)
Ok, another question for you guys:

I'm working on MMX with a bitmap.

I want to use the MMX commands to shift the bits to the right by one in each BYTE. (divide by two), the closest command to what I want is: PSRLW, can I use this command and then AND or SUBtract something after the shift that will give me a BYTE shift, rather than the WORD shift.

I thought about subtracting 0080 from each WORD, is this right?

Just wait until I get into debugging...then we're all in trouble.

:wink

Jeff the experimenter.

:8)
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

UncannyDude

Quote from: OceanJeff32 on February 06, 2005, 04:44:25 AMI want to use the MMX commands to shift the bits to the right by one in each BYTE. (divide by two), the closest command to what I want is: PSRLW, can I use this command and then AND or SUBtract something after the shift that will give me a BYTE shift, rather than the WORD shift.

; assuming you have your data in mm1
WordToByteMask dq 00ff00ff00ff00ffh
...
movq mm2, WordToByteMask
psrlw mm1, 1
pand mm1, mm2


Quote from: OceanJeff32 on February 06, 2005, 04:44:25 AMI thought about subtracting 0080 from each WORD, is this right?
Subtracting 0080h only replaces a "divide by 2" when left operand is 0100h, thus we can conclude that it's not safe.

OceanJeff32

Thank you, but I got it to work!

Ok, I had to use PAND with a mask like this:

FF3FFF3F (I started with FF7FFF7F, because originally I wanted 1 bit shift)
I used the 3 version because I shifted the original 64-bit MMX register to the right 2 times.  Each Word was shifted to the right 2 bits, so this mask ZEROes out those high bits that get transferred into the low byte of each word.

Does that make sense?

I did this:

MOVDQU  MM7, (Mask: FF3FFF3F * 4)
PSRLW MM0,2
PAND MM0, MM7

Since the PSRLW shifts each WORD by 2 bits, and I want the BYTEs to all shift 2 bits, the BYTEs that are not on the boundaries of the WORD get 2 bits shifted into them, so I used the mask in the next line to ZERO out those BYTEs and simulate the BYTE command, which might look something like this: PSRLB... :U

Jeff
:wink

P.S. I see what you had in mind, and that would work if I wanted to save the low BYTEs in each word... :cheekygreen:

Thanks for the help though. :thumbu
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

UncannyDude

Yeah, I was working in a alpha blend routine, my shift was 8, this is why I choosed that pattern(reflected in constant name). I just copy'n'pasted my code... :red

But it's cool to see someone who can see the idea and go ahead. :U