flat assembler
Message board for the users of flat assembler.
Index
> Main > Fade effect using MMX assembler |
Author |
|
Madis731 13 Aug 2007, 11:24
^o) why is it so complicated? Usually you will win performance-wise if you converted it to 24-bit, then faded and converted the 24-bit back to 16.
MMX is for unified data, this algorithm suggestion is not and very hard to make it take advantage of SIMD. If you really can't afford the convert, then I will try to make one, but I won't start one if you're not 100% sure! |
|||
13 Aug 2007, 11:24 |
|
r22 13 Aug 2007, 18:54
The color format makes it difficult to optimize.
Here's a straight forward solution. Someone can likely take it and optimize it further if necessary. Code: .data align 16 MaskB dq 001F001F001F001Fh align 16 MaskG dq 07E007E007E007E0h align 16 MaskR dq F800F800F800F800h align 16 Sub1 dq 0000000100000001h align 16 Sub2 dq 0000000200000002h .code ;;example fade loop mov ebx,32 mov edi,PixelBuffer mov eax,640*480*2 .fade2black: call FadeMMX call RenderToScreen sub ebx,1 jnz .fade2black ;; ;;... ;; FadeMMX: mov ecx,eax sub ecx,16 movq mm0,[Sub1] movq mm7,[Sub2] ;;assumes EAX will always be greater than 15 ;;this loop also assumes EAX will be divisible by 16 ;;unless your using an odd resolution this should be fine .fade: ;;load and copy movq mm1,[esi+ecx] movq mm2,[esi+ecx+8] movq mm3,mm1 movq mm4,mm2 movq mm5,mm1 movq mm6,mm2 ;;mask the needed bits pand mm1,qword[MaskB] pand mm2,qword[MaskB] pand mm3,qword[MaskG] pand mm4,qword[MaskG] pand mm5,qword[MaskR] pand mm6,qword[MaskR] ;;get the bits to the lowest byte psrlw mm3,5 psrlw mm4,5 psrlw mm5,11 psrlw mm6,11 ;;subtract with saturate psubusb mm1,mm0 psubusb mm2,mm0 psubusb mm3,mm7 psubusb mm4,mm7 psubusb mm5,mm0 psubusb mm6,mm0 ;;shift the bits back into position psllw mm3,5 psllw mm4,5 psllw mm5,11 psllw mm6,11 ;;combine the bits back into the 16bit color por mm1,mm3 por mm2,mm4 por mm1,mm5 por mm2,mm6 ;;store movq qword[esi+ecx],mm1 movq qword[esi+ecx+8],mm2 sub ecx,16 jns .fade ;; loop while ecx >= 0 ret 0 This wasn't tested and was written in the webbrowser reply window, but there's a good chance it could be useful. |
|||
13 Aug 2007, 18:54 |
|
DOS386 14 Aug 2007, 06:32
Welcome to FASM forum
Laaca wrote: Who can provide me a fadding routine for 16-bit graphics mode in MMX assembly? Thanks! Just make it darker ? Code: ; IN: Buffer: [ES:EDI] || size: ECX ; OUT: Nothing ; TSH: EDI, EAX, ECX ; rrrrrggg gggbbbbb rrrrrggg gggbbbbb dark: shr ecx,2 dark2: mov eax,[es:edi] ; Pick 2 pixels ; movntq [es:edi],mm0 ; Uncomment if trouble required and eax,$FFDFFFDF ; Remove 2 offending green bits test al,$1F ; Test blue 5 bits jz @f dec al ; DEC blue @@: test eax,$07E0 ; Test green 5/6 bits jz @f sub eax,$20 ; DEC green @@: test eax,$F800 ; Test red 5 bits jz @f sub eax,$800 @@: test eax,$001F0000 ; Test blue 5 bits jz @f sub eax,$10000 ; DEC blue @@: test eax,$07E00000 ; Test green 5/6 bits jz @f sub eax,$00200000 ; DEC green @@: test eax,$F8000000 ; Test red 5 bits jz @f sub eax,$08000000 @@: stosd ; And write them back loop dark2 ret ;------ Sorry no MMX Untested, no 16bpp VESA available _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
14 Aug 2007, 06:32 |
|
Laaca 15 Aug 2007, 16:29
Wow! Thanks r22, I'll try it.
NTOSKRNL_VXE: Your code is not optimized at all. Your jumps very slow down the routine. |
|||
15 Aug 2007, 16:29 |
|
DOS386 15 Aug 2007, 22:07
> is not optimized at all
For compatibility. > jumps very slow down Feel free to compare and post results. |
|||
15 Aug 2007, 22:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.