Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Incredibly slow MMX? (Developers)

posted by Laaca Homepage, Czech republic, 08.03.2009, 22:04
(edited by Laaca on 08.03.2009, 22:46)

I write another routine for testing MMX. It is darkening procedure for sprite (again for 16 bpp mode). Without MMX is it quite complicated and MMX is here a better speed gain.

I figured that MMX access to VRAM is much slower than 386 access to VRAM.
So, never use MMX for direct VRAM output. It is always better to draw into RAM buffer and then result copy into screen.

Procedure DecreaseMMXSpriteLightness(var sprite:virtualwindow;r,g,b:longint);assembler;
asm
push es
mov esi,sprite
mov ecx,[esi+6]                 {size}
mov ax,[esi+0]
mov esi,[esi+2]
mov es,ax
cmp ecx,8
jl @zbytek
cmp cpu_info_mmx,0

jz @zbytek

movd mm5,r
punpcklwd mm5,mm5
punpcklwd mm5,mm5               {R je rozepsane do celeho mm5}

movd mm6,g
punpcklwd mm6,mm6
punpcklwd mm6,mm6               {G je rozepsane do celeho mm6}


movd mm7,b
punpcklwd mm7,mm7
punpcklwd mm7,mm7               {B je rozepsane do celeho mm7}


@smycka:
movq mm1,es:[esi]             { pro R slozku }
movq mm2,mm1                  { pro G slozku }
movq mm3,mm1                  { pro B slozku }

psrlw mm1,11                  { R slozka osamostatnena }
psllw mm2,5
psrlw mm2,5+5                 { G slozka osamostatnena }
psllw mm3,11
psrlw mm3,11                  { B slozka osamostatnena }


psubusw mm1,mm5               { provede odecet R slozky }
psubusw mm2,mm6               { ...G slozky }
psubusw mm3,mm7               { ...B slozky }

psllw mm1,11                  { R na sve misto }
psllw mm2,5                   { G na sve misto }
                              { B na svem miste uz je }

por mm1,mm2
por mm1,mm3

movq es:[esi],mm1
add esi,8

sub ecx,8
cmp ecx,8
jge @smycka

emms
jecxz @konec

{-}@zbytek: {---------------------------}
shr ecx,1
{}@cykl_zbytku:
movzx eax,word ptr es:[esi]  {v EAX R}
mov ebx,eax                  {v EBX G}
mov edx,eax                  {v EDX B}
shr eax,11
shr ebx,5
and ebx,63
and edx,31
sub eax,r
sub ebx,g
sub edx,b
cmp eax,0
jge @r_ok
xor eax,eax
{}@r_ok:
cmp ebx,0
jge @g_ok
xor ebx,ebx
{}@g_ok:
cmp edx,0
jge @b_ok
xor edx,edx
{}@b_ok:
shl eax,11
shl ebx,5
or eax,ebx
or eax,edx
mov es:[esi],ax
add esi,2
dec ecx
jnz @cykl_zbytku


{---------------------------------------}
@konec:
pop es
end;

---
DOS-u-akbar!

 

Complete thread:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 241 users online (0 registered, 241 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum