From: Gautier Newsgroups: comp.lang.asm.x86,comp.os.msdos.djgpp Subject: Assembler / optimization Date: 5 Dec 1998 14:43:00 GMT Organization: Universite de Neuchatel Lines: 89 Approved: Message-ID: <74bgpk$7fl$4@winter.news.rcn.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: 5ZGACGNAs9vVOEzQcEUnjxhrDqq+MKh7ybipGdFxzMg= X-Complaints-To: abuse AT rcn DOT com NNTP-Posting-Date: 5 Dec 1998 14:43:00 GMT X-Mailer: Mozilla 4.05 (Macintosh; I; PPC) 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;