delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/16/20:30:41

Date: Thu, 17 Jul 1997 12:32:34 +0000
From: Bill Currie <billc AT blackmagic DOT tait DOT co DOT nz>
Subject: Re: tips on optomizing my (inline asm) horizontal line function
To: Jeff Weeks <pweeks AT execulink DOT com>
Cc: djgpp AT delorie DOT com
Reply-to: billc AT blackmagic DOT tait DOT co DOT nz
Message-id: <33CE10E2.6F31@blackmagic.tait.co.nz>
Organization: Tait Electronics NZ
MIME-version: 1.0
References: <33CCDC5F DOT 49A58E52 AT execulink DOT com>

Jeff Weeks wrote:
> Here it is:
> 
  void aligned_dwords(int x1, int x2, int y, unsigned char c) {
    unsigned long col;
    
>   if(x1 == x2) return;

    /* let gcc 'longise' c so it can pick the registers (use -O or -O2)
*/
    col=(c<<8)|c;
    col=(col<<16)|col;

>   if(x1 > x2) {
>     x1 ^= x2;
>     x2 ^= x1;
>     x1 ^= x2;
>   }
> 
>   __asm__ __volatile__("
      # %eax,%edi,%ecx already initialised
>     test $1, %%edi;
>     jz 0f;
>     stosb;
      # dec %%cx;  not needed (should be ecx anyway)
>   0:
      # movl %%edi, %%ebx;  no longer needed
      testl $2, %%edi;     # is edi dword aligned?
>     jz 1f;
>     stosw;
>   1:
      shr $2, %%ecx;  # should be ecx rather than cx (saves a byte and
maybe a cylcle)
      rep; stosl"     /* uses ecx as the count (this comment is out side
the quotes) */
>     :
      : "D" (0xA0000+__djgpp_conventional_base+y*320+x1), "a" (col), "c"
((long)(x2-x1))
      : "ecx", "edi", "memory"
>   );
> }

Any lines I've added or modifed have the '>' removed.  I've commented
out or removed (the settup of eax) code that isn't needed.

Other than the few things, it was pretty good code IMO.

Hope this helps (also demonstrates how to comment inline asm).
Bill
-- 
Leave others their otherness.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019