PDA

View Full Version : ASM



Gadget
28-01-2003, 07:17 PM
I am trying to get an MMX routine working using ASM and dont quite know how to get the 4 words out of mm0 back into my destination bitmap...

This is my test routine:-

for iX := 0 to Image1.Picture.Bitmap.Height - 1 do
begin
pSrc := Image1.Picture.Bitmap.ScanLine[iX];
pDest := Image2.Picture.Bitmap.ScanLine[iX];
iY := 0;
while iY < Image1.Picture.Bitmap.Width - 1 do
begin
asm
push EAX
push EDX
push ECX

mov EAX, pSrc
mov EDX, pDest
db $0F,$6F,$00 /// movq mm0, [EAX]
db $0F,$FD,$02 /// paddw mm0, [EDX]
db $0F,$7F,$01 /// movq [ECX], mm0
{this is the point I need to get the 4 x words out of mm0 into the scanline using pDest[iY], at the moment its outputting it to ECX}

pop ECX
pop EDX
pop EAX

end;
Inc(iY,4);
pSrc := Pointer(Cardinal(pSrc) + 4);
pDest := Pointer(Cardinal(pDest) + 4);
end;
end;


Any ideas?

Thanks

Gadget
28-01-2003, 07:31 PM
Bah, just noticed a couple of problems with this code anyways... I am putting a pointer into mm0 to start with instead of 4 x words, and I am only incrementing my pointers by 4 instead of 8... Assuming 8 is correct for 4 words? The pointers are type Pointer btw.

Gadget
28-01-2003, 07:40 PM
Sorted...

for iX := Image1.Picture.Bitmap.Height - 1 downto 0 do
begin
pSrc := Image1.Picture.Bitmap.ScanLine[iX];
pDest := Image2.Picture.Bitmap.ScanLine[iX];
iY := Image1.Picture.Bitmap.Width - 5;
while iY > 0 do
begin

IMASK64 := $F7DEF7DEF7DEF7DE;
PIMASK64 := @IMASK64;
// (src and $F7DE) shr 1 + (dest and $F7DE) shr 1
asm

{source}
mov EAX, pSrc
mov EDX, PIMASK64
mov ECX, pSrc
db $0F,$6F,$00 /// movq mm0, [EAX]
db $0F,$DB,$02 /// pand mm0, [EDX]
db $0F,$71,$D0,$01 /// psrlw mm0,1
db $0F,$7F,$01 /// movq [ECX], mm0

{destination}
mov EAX, pDest
mov EDX, PIMASK64
mov ECX, pDest
db $0F,$6F,$00 /// movq mm0, [EAX]
db $0F,$DB,$02 /// pand mm0, [EDX]
db $0F,$71,$D0,$01 /// psrlw mm0,1
db $0F,$7F,$01 /// movq [ECX], mm0


{add them together and output to dest}
mov EAX, pSrc
mov EDX, pDest
mov ECX, pDest
db $0F,$6F,$00 /// movq mm0, [EAX]
db $0F,$FD,$02 /// paddw mm0, [EDX]
db $0F,$7F,$01 /// movq [ECX], mm0

end;
Dec(iY,4);
pSrc := Pointer(Cardinal(pSrc) + 8);
pDest := Pointer(Cardinal(pDest) + 8);
end;
end;




EDIT: OK, this works for 50/50 effect, but I have the black background pixels bah... Need to find a way around it :P

2ND EDIT: I have been thinking about this... Maybe I could change the mask? or use another mask to remove those $0000 pixels... (scratches head)

Gadget
29-01-2003, 08:53 AM
Any idea how I can sort out the black background pixels? Normally they are taken care of with the Blit, but using this new routine I am blending the black pixels from the source with the destination image :P

I was thinking about adding a mask maybe? Background is $0000 btw.