Xref: news2.mv.net comp.os.msdos.djgpp:6982 From: brennan AT mack DOT rt66 DOT com (Brennan "The Reverend Bas" Underwood) Newsgroups: comp.os.msdos.djgpp Subject: Re: buffer -> screen transfers Date: 8 Aug 1996 10:59:20 -0600 Organization: None, eh? Lines: 57 Message-ID: <4ud6d8$7j4@mack.rt66.com> References: <320647A3 DOT 5827 AT cadvision DOT com> NNTP-Posting-Host: mack.rt66.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <320647A3 DOT 5827 AT cadvision DOT com>, John Meilleur wrote: >Can anyone help me speed up this bit of code. I'm writing some hi-res graphics routines and would like to know >how i can speed up clearing the screen buffer and the buffer transfer. I know I should be able to do 32-bit >transfering but I've had no luck with it sofar. The "video_ds" is the selector to video memory and starts at >offset 0. Can any show me how to speed this up alot? TIA > >char *screen = malloc(640*480); >while (!kbhit()) >{ > for (i=0;i<640*480;i++) > screen[i]=0; asm volatile ( "rep\n\t" "stosl" : : "a" (0), "c" (640*480/4), "D" (screen) : "%edi", "%ecx" ); > drawstuff(screen); > > _farsetsel(video_ds); > for (i=0;i<640*480;i++) > _farnspokeb(i,screen[i]); asm volatile ( "movw %%es, %%dx\n\t" "movw %%bx, %%es\n\t" "rep\n\t" "movsl\n\t" "movw %%dx, %%es\n\t" /* put things back where you found 'em */ : : "b" (video_ds), "c" (640*480/4), "S" (screen), "D" (0) : "%ebx", "%ecx", "%edx", "%esi", "%edi" ); > >} I realize there are other tiny little optimizations, but they don't amount to more than a cycle or 3 per page. If at all possible, arrange to not have to clear the parts of the screen that are overwritten anyway. 640*480 makes for a lot of bytes. Don't write to them twice if you can. For clarity's sake, I'd just use memset instead of the first asm, and fmemcpy on the second. Well , *I* wouldn't, but I recommend it anyway. --Brennan -- brennan AT rt66 DOT com | fsck /u Unsolicited junk email may be returned to sender 1000 times or more.