delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/05/09:45:52

Message-ID: <3669548A.AD73784F@maths.unine.ch>
Date: Sat, 05 Dec 1998 15:43:07 +0000
From: Gautier <gautier DOT demontmollin AT maths DOT unine DOT ch>
Organization: Universite de Neuchatel
X-Mailer: Mozilla 4.05 (Macintosh; I; PPC)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Assembler / optimization
NNTP-Posting-Host: mac13-23.unine.ch
Lines: 88
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi. I am curious about the quality of the inline assembler in the code below -
an attempt from me to optimize a line drawing routine in a buffer.
What is sure is that the code produced without inline assembler is
near to it when compiled with -O2 -m486 options; so are the performances.
I only wonder if there is some forgotten trick or a beginner mistake in my asm...

-- 
Gautier

The concerned portion of code:

         S_X := 1;
         D_X := abs (Right - Left);
         if Left > Right then
            S_X := -1;
         end if;

         S_Y := 1;
         D_Y := abs (Bottom - Top);

         if Top > Bottom then
            S_Y := -1;
         end if;

         D_X_2 := 2*D_X;
         D_Y_2 := 2*D_Y;

         Line_S_Y := Buffer.Width * S_Y;
--         Left_Top_Line := Left + Buffer.Width * Top;

         if D_Y > D_X then
         ASM(
                             -- for I in reverse 0 .. D_Y loop
"   .align 2,0x90  " & LF &
"0: movb  %0, (%3) " & LF &  --   Buffer_Data(Left_Top_Line) := Color;
"   testl %2, %2   " & LF &  --   while Limit >= 0 loop
"   jl    3f       " & LF &
"   .align 2,0x90  " & LF &
"2: addl  %4, %3   " & LF &  --     Left_Top_Line := Left_Top_Line + S_X;
"   subl  %7, %2   " & LF &  --     Limit := Limit - D_Y_2;
"   jns   2b       " & LF &  --   end loop;
"3: addl  %5, %3   " & LF &  --   Left_Top_Line := Left_Top_Line + Line_S_Y;
"   addl  %6, %2   " & LF &  --   Limit := Limit + D_X_2;
"   decl  %1       " & LF &  -- end loop;
"   jns   0b",
             No_Output_Operands,
             (byte'Asm_Input    ("b", Color),           -- %0 = Color
              integer'Asm_Input ("r", D_Y),             -- %1 = I in reverse 0
.. D_Y
              integer'Asm_Input ("r", D_X_2 - D_Y),     -- %2 = Limit := D_X_2
- D_Y
              address'Asm_Input ("r", Buffer_Data(Left + Buffer.Width *
Top)'address), -- %3 = start
              integer'Asm_Input ("g", S_X),        -- %4
              integer'Asm_Input ("g", Line_S_Y),   -- %5
              integer'Asm_Input ("g", D_X_2),      -- %6
              integer'Asm_Input ("g", D_Y_2)       -- %7
));
         else
         ASM(
                             -- for I in reverse 0 .. D_X loop
"   .align 2,0x90  " & LF &
"0: movb  %0, (%3) " & LF &  --   Buffer_Data(Left_Top_Line) := Color;
"   testl %2, %2   " & LF &  --   while Limit >= 0 loop
"   jl    3f       " & LF &
"   .align 2,0x90  " & LF &
"2: addl  %5, %3   " & LF &  --     Left_Top_Line := Left_Top_Line + Line_S_Y;
"   subl  %6, %2   " & LF &  --     Limit := Limit - D_X_2;
"   jns   2b       " & LF &  --   end loop;
"3: addl  %4, %3   " & LF &  --   Left_Top_Line := Left_Top_Line + S_X;
"   addl  %7, %2   " & LF &  --   Limit := Limit + D_Y_2;
"   decl  %1       " & LF &  -- end loop;
"   jns   0b",
             No_Output_Operands,
             (byte'Asm_Input    ("b", Color),           -- %0 = Color
              integer'Asm_Input ("r", D_X),             -- %1 = I in reverse 0
.. D_X
              integer'Asm_Input ("r", D_Y_2 - D_X),     -- %2 = Limit := D_Y_2
- D_X;
              address'Asm_Input ("r", Buffer_Data(Left + Buffer.Width *
Top)'address), -- %3 = start
              integer'Asm_Input ("g", S_X),        -- %4
              integer'Asm_Input ("g", Line_S_Y),   -- %5
              integer'Asm_Input ("g", D_X_2),      -- %6
              integer'Asm_Input ("g", D_Y_2)       -- %7
));
         end if;
         Buffer_Data(Right + Buffer.Width * Bottom) := Color;

- Raw text -


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