Author: Dieter Buerssner
Date: 13:00:30 12/11/03
Go up one level in this thread
Franz, I think 10% is just inside the random noise, one can expect from random
changes that should not effect the speed. I saw few percent speedup by adding
debug code (one if (something) printf(...) added to code). I saw 10% speed
difference by calling the same function under same conditions in 2 different
parts of the code (caller needs no time, and signficant time is needed in the
called function). Gerd mentioned linking order. I saw the same - and one minor
change and a different linking order works better. Because you mentioned K6-2.
Here a nice example. The following code worked almost an order of magnitude
faster without the const, when compiled with some version of gcc (DJGPP):
unsigned long mwc32(void)
{
unsigned long l1, l2;
ul64 res;
/* Uncommenting the const, can make this very slow on AMD K6-2 */
static /* const */ unsigned long mul=999996864UL;
l1 = (unsigned long)(zseed & 0xffffffffUL);
l2 = zseed>>32;
res = l2+l1*(ul64)mul;
zseed = res;
return (unsigned long)(res & 0xffffffffUL);
}
I carefully investigated this. The compiler produces almost exactly the same
code. Only difference: Once the two constants are in the code segment, and once
in the data segment. Adding a small spacer between the constants (when in the
code segment) and the actual function code - and the speed was normal again. The
same code compiled with MSVC did not show this behaviour (with and without const
the same speed). The same code compiled with the same compiler under Linux
(creating the same assembly) did not show this strange behaviour.
When I added that const, I thought I had made the code a bit better. Later I
found that my simulation program, that used that function heavily was running
much slower. It took me a long time to find out that that const was the reason
(and probably a bug/misfeature in the AMD-CPU). After I saw that, I changed all
my const in the chess engine to some #define, and by default I am not using
const anymore. In the chess engine, it did not make a difference, however.
http://www.google.de/groups?hl=de&lr=&ie=UTF-8&oe=UTF-8&threadm=200004271315.JAA03722%40delorie.com&rnum=1&prev=/groups%3Fq%3DK6%2Bconst%2Bauthor:Buerssner%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D200004271315.JAA03722%2540delorie.com%26rnum%3D1
Regards,
Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.