Const Function Parameters?

Michael Carlson corfe83dev at gmail.com
Tue Jul 26 22:08:12 CDT 2005


On 7/26/05, Troy Rollo <wine at troy.rollo.name> wrote:
> On Wed, 27 Jul 2005 09:25, Felix Nawothnig wrote:
> > There is no need to make anything except the pointers const - I don't
> > think I've ever seen that in real world code. In theory this would give
> > the compiler slightly more information... but if the optimizer is unable
> > to figure out that the parameter is never used as an lvalue by himself
> > it sucks so badly that it probably won't do much better with that hints
> > anyway. :-)
> 
> In fact I don't know that making these const would make any difference - I'd
> like to see the assembly code generated by the two versions for comparison.

I agree, the compiler should realise the parameters aren't used as an
l-value in the function anywhere - but it apparently doesn't, or
marking the parameters const is having some other effect on the binary
- with gcc 4.0.1 (at least on my system, Debian sid), the compiled
size of winex11.drv.so changes with my patch (it increases by 368
bytes from 5335409 -> 5335777). Just changing the parameters to const
for the function in question (and none of the other functions in the
file) increases the size from the original size by 64 bytes.

I won't pretend to know why my patch increases the size of the binary,
but it shows that even without looking at the assembly code, this
patch is making some kind of difference (whether good or bad) in the
compiled code. I would look further into it, but I don't know
assembly.

> 
> The 1.5% appears to be within the noise.
> 
> A few of us analysed those routines to death on IRC a couple of months back
> and decided the real problem was that they were being called too frequently,
> not that there was a problem with the routines themselves. The routines could
> probably be made faster by rewriting them in assembly language, but bigger
> benefits could be gained by figuring out why there are so many calls and
> reducing the number of calls.
>
 
I agree it would be good to have these routines called less in the
future. However, until we reduce the number of times that routine is
called (whenever that may be), it would be nice to know we're doing
everything we can to make the routine as fast as possible.

Anyway, I'm the amateur wine-hacker here, so if you guys still say we
shouldn't change it, I won't argue the matter further. I just want to
point out that this patch is certainly doing SOMETHING to the
resulting binary, and it's possibly good.




More information about the wine-devel mailing list