POV-Ray : Newsgroups : povray.unofficial.patches : PovRay faster : Re: PovRay faster Server Time
1 Sep 2024 22:13:15 EDT (-0400)
  Re: PovRay faster  
From: Peter J  Holzer
Date: 6 Feb 2001 18:02:40
Message: <slrn980sf6.fb6.hjp-usenet@teal.h.hjp.at>
On 2001-02-06 13:17, Warp <war### [at] tagpovrayorg> wrote:
>  By the way, some times the compiler can go too far in this.
>  This is the case with gcc. When generating the assembler code, it will
>always convert the multiplication of an integer variable and an integer
>constant to shifts and ors/additions/substractions, no matter what is the
>constant value.
>  For example something like a*123456789 generates about 10-20 assembler
>operations.

Not always. E.g., egcs-2.91.66 for Intel will compile

    int foo (int a) {
	return a*123456789;
    }

    int bar (int a) {
	return a*4;
    }


into:


	    .file	"foo.c"
	    .version	"01.01"
    gcc2_compiled.:
    .text
	    .align 4
    .globl foo
	    .type	 foo,@function
    foo:
	    pushl %ebp
	    movl %esp,%ebp
	    imull $123456789,8(%ebp),%eax
	    leave
	    ret
    .Lfe1:
	    .size	 foo,.Lfe1-foo
	    .align 4
    .globl bar
	    .type	 bar,@function
    bar:
	    pushl %ebp
	    movl %esp,%ebp
	    movl 8(%ebp),%edx
	    leal 0(,%edx,4),%eax
	    leave
	    ret
    .Lfe2:
	    .size	 bar,.Lfe2-bar
	    .ident	"GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"

As you can see, the first multiplication is translated to an imul
instruction, while the second one is translated to a leal (which is
essentially a shift-and-add operation.

As far as I can remember, gcc has behaved like this since at least the
1.3x releases.

	hp

-- 
   _  | Peter J. Holzer    | All Linux applications run on Solaris,
|_|_) | Sysadmin WSR       | which is our implementation of Linux.
| |   | hjp### [at] wsracat      | 
__/   | http://www.hjp.at/ |	-- Scott McNealy, Dec. 2000


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.