From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Derbyshire To: egcs@egcs.cygnus.com Subject: Re: Code gen question Date: Fri, 12 Feb 1999 17:34:00 -0000 Message-id: <3.0.6.32.19990212203311.0083e6d0@pop.netaddress.com> In-reply-to: < u990e3kxq8.fsf@yorick.cygnus.com > References: <12> <1999> <15:07:44> <-0800> <3.0.6.32.19990212180551.00841100.cygnus.egcs@pop.netaddress.com> X-SW-Source: 1999-02/msg00485.html At 03:29 PM 2/12/99 -0800, you wrote: >>>>>> Paul Derbyshire writes: > > > Which will cause cc1plus to generate better code? > > inline int myclass::myfunc (int j) { return j*j*j; } > > > inline int myclass::myfunc (const int &j) { return j*j*j; } > > > My guess would be the latter, since the latter when inlined won't make a > > copy of the argument passed. > >Neither will the former. It won't? So it will observe that j is never modified making copying unnecessary? >The difference is that the latter refers to its >arguments address, which impairs optimization (though not as much as it >used to). It does? If the address isn't used except to dereference, I'd expect the compiler to turn int j, k; j = compute_something(); k = myclass::myfunc(j); into something that resembles: compute_something(); ; j is in eax. movl %eax, %ebx ; k is in ebx now. Hmm, it is copied anyways in a ; sense. mul %eax, %ebx ; k == j*j mul %eax, %ebx ; k == j*j*j >Absolutely pass scalars by value. Does this also apply to stock GCC? PGCC? Most of the differences among these three gccs, except for namespace support (and extern inline behavior :-)), are optimization differences. -- .*. "Clouds are not spheres, mountains are not cones, coastlines are not -() < circles, and bark is not smooth, nor does lightning travel in a `*' straight line." ------------------------------------------------- -- B. Mandelbrot | http://surf.to/pgd.net _____________________ ____|________ Paul Derbyshire pderbysh@usa.net Programmer & Humanist|ICQ: 10423848| From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Derbyshire To: egcs@egcs.cygnus.com Subject: Re: Code gen question Date: Sun, 28 Feb 1999 22:53:00 -0000 Message-ID: <3.0.6.32.19990212203311.0083e6d0@pop.netaddress.com> References: <12> <1999> <15:07:44> <-0800> <3.0.6.32.19990212180551.00841100.cygnus.egcs@pop.netaddress.com> X-SW-Source: 1999-02n/msg00480.html Message-ID: <19990228225300.9lJx9lfmsKfoRrwFrLLqBayt8QIE2Q66zAlOfD7vlO0@z> At 03:29 PM 2/12/99 -0800, you wrote: >>>>>> Paul Derbyshire writes: > > > Which will cause cc1plus to generate better code? > > inline int myclass::myfunc (int j) { return j*j*j; } > > > inline int myclass::myfunc (const int &j) { return j*j*j; } > > > My guess would be the latter, since the latter when inlined won't make a > > copy of the argument passed. > >Neither will the former. It won't? So it will observe that j is never modified making copying unnecessary? >The difference is that the latter refers to its >arguments address, which impairs optimization (though not as much as it >used to). It does? If the address isn't used except to dereference, I'd expect the compiler to turn int j, k; j = compute_something(); k = myclass::myfunc(j); into something that resembles: compute_something(); ; j is in eax. movl %eax, %ebx ; k is in ebx now. Hmm, it is copied anyways in a ; sense. mul %eax, %ebx ; k == j*j mul %eax, %ebx ; k == j*j*j >Absolutely pass scalars by value. Does this also apply to stock GCC? PGCC? Most of the differences among these three gccs, except for namespace support (and extern inline behavior :-)), are optimization differences. -- .*. "Clouds are not spheres, mountains are not cones, coastlines are not -() < circles, and bark is not smooth, nor does lightning travel in a `*' straight line." ------------------------------------------------- -- B. Mandelbrot | http://surf.to/pgd.net _____________________ ____|________ Paul Derbyshire pderbysh@usa.net Programmer & Humanist|ICQ: 10423848|