From: Jeff Weeks Newsgroups: comp.os.msdos.djgpp Subject: tips on optomizing my (inline asm) horizontal line function Date: Wed, 16 Jul 1997 10:36:15 -0400 Organization: Code X Software Lines: 62 Message-ID: <33CCDC5F.49A58E52@execulink.com> NNTP-Posting-Host: ppp25.mars.execulink.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk I've written a fairly simple horizontal line function, and it works fast compared to the others I've tried, but it uses up a lot of registers, and there's probably a better way to do some things. I was wondering if anybody had any tips to pass along to reduce register use, or anything to increase speed even more. Every little bit counts. Here's what it currently looks like. Since I don't know how to do comments in inline assembly I'll briefly describe it here. First it checks for an odd address, if so it movs a bytes, then it checks for a word aligned address, if so it movs a word. The rest is all dword aligned dword writes, for maximum speed. I currently don't have any code to draw the remaining (up to 3) pixels of the end of the line (the pixels that won't fit in a dword), so if anybody has fast code to do that, it would also be appreciated. Here it is: void aligned_dwords(int x1, int x2, int y, char c) { if(x1 == x2) return; if(x1 > x2) { x1 ^= x2; x2 ^= x1; x1 ^= x2; } __asm__ __volatile__(" movb %1, %%al; movb %%al, %%ah; shl $16, %%eax; movb %1, %%al; movb %%al, %%ah; test $1, %%edi; jz 0f; stosb; dec %%cx; 0: movl %%edi, %%ebx; andl $2, %%ebx; jz 1f; stosw; 1: shr $2, %%cx; rep; stosl" : : "D" (0xA0000+__djgpp_conventional_base+y*320+x1), "g" (c), "c" ((long)(x2-x1)) : "ax", "bx", "cx", "di", "memory" ); } Thank you very much, Jeff Weeks -------------------------------------------- - Code X Software - Programming to a Higher Power email: mailto:pweeks AT execulink DOT com web: http://www.execulink.com/~pweeks/ --------------------------------------------