Const Function Parameters?

Michael Carlson corfe83dev at gmail.com
Tue Jul 26 11:45:19 CDT 2005


I've been doing some oprofille tests with wine running fce ultra, the
8-bit Nintendo emulator. I found that when running a rom for 60
seconds, more than 99% of the CPU utilization for winex11drv (which
uses the most of all components of wine in this case) is in the same
function : convert_888_to_0888_asis (in dlls/x11drv/dib_convert.c).

I've also found that marking a couple of parameters of that function
const (that I believe should be marked const anyways), CPU usage in
that function drops measurably with oprofile. As far as I know,
parameters that aren't modified in a function should be marked const
anyways, to send the right hint to the compiler. Since it actually
turns out to be faster too, it seems worth it to me.

Here are the results from oprofile before the change:

21982    99.2012  convert_888_to_0888_asis
22078    99.1735  convert_888_to_0888_asis
22207    99.1605  convert_888_to_0888_asis
22161    99.1544  convert_888_to_0888_asis
22158    99.2253  convert_888_to_0888_asis

and after:

21828    99.1731  convert_888_to_0888_asis
21769    99.2296  convert_888_to_0888_asis
21835    99.3313  convert_888_to_0888_asis
21868    99.1027  convert_888_to_0888_asis
21601    99.1508  convert_888_to_0888_asis

On average, it went from 22117 (context switches I believe?) to 21780,
about a 1.5% improvement. The same test was run with a script each
time (run fceu with the same rom, kill it after 60 seconds). I'm
assuming the percentages (the second column in this chart) don't
matter much, because this function we're examining takes up an
overwhelming amount of the function's CPU (> 99%), so its percentage
depends largely on how many context switches other functions took up.

I've taken the liberty of providing a diff that patches all the
functions in this file to use const parameters where appropriate. I
don't get any compiler warnings with this compiling with gcc 4.0.1.
Should I submit this to wine-patches? This would be my first patch to
wine (or any open-source project, period). I'd appreciate some
feedback before I try for it.

Thanks in advance!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-patch
Size: 22783 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20050726/fea9ab1b/patch.bin


More information about the wine-devel mailing list