rayzor

view src/swapbuf.asm @ 10:235c8b764c0b

optimized swap_buffers
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Apr 2014 08:03:52 +0300
parents
children 5380ff64e83f
line source
1 ; vim:set ft=nasm:
2 segment code use32
4 ; void swap_buffers_asm(void *dest, void *src, int xsz, int ysz, int bpp)
5 ; dest -> eax
6 ; src -> edx
7 ; xsz -> ebx
8 ; ysz -> ecx
9 ; bpp -> [ebp + 8] (after pushing ebp)
10 global swap_buffers_asm_
11 swap_buffers_asm_:
12 push ebp
13 mov ebp, esp
15 mov edi, eax ; let's hold dest ptr in edi, frees up eax
16 mov esi, edx ; let's hold src ptr in esi, frees up edx
17 ; calculate pixel count -> ecx, frees up ebx
18 mov eax, ebx
19 mul ecx
20 mov ecx, eax ; now ecx = xsz * ysz
22 mov eax, [ebp + 8] ; eax <- bpp
23 cmp eax, 32
24 je .bpp32
25 cmp eax, 24
26 je .bpp24
27 cmp eax, 16
28 je .bpp16
29 ; invalid bpp, ignore
30 jmp .done
32 .bpp32: ; 32bit block transfer, no conversion
33 rep movsd ; esi, edi, and ecx already loaded, just go...
34 jmp .done
36 .bpp24: ; 32bpp -> 24bpp conversion (LSB-first), 1 byte overrun!
37 movsd ; transfer a full 32bit chunk and inc esi,edi by 4
38 dec edi ; backtrack dest one byte after last transfer
39 dec ecx
40 jnz .bpp24
41 jmp .done
43 .bpp16: ; fuck 16bpp for now (TODO)
44 .done:
45 pop ebp
46 ret