Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: About compiler optimizations

Author: David Rasmussen

Date: 13:32:04 12/20/02

Go up one level in this thread


On December 20, 2002 at 14:51:03, Eugene Nalimov wrote:

>I'll be happy if you do that.
>

I haven't gone through the tedious task of creating a simple test case, so all I
can show you is some code that in the context it is in, fails with MSVC++.NET.
This is from an old version of Chezzz:

	// Generate the attack masks for attacks on a file
	for (Square square = A1; square <= H8; ++square)
	{
		minus8Direction[square] = 0;
		plus8Direction[square] = 0;
		for (BitBoard state = 0; state <= 255; ++state)
		{
			BitBoard tmp = 0;
			BitBoard shiftState = state << FileShift(square);
			for (Square to = square - 8; to >= A1; to -= 8)
			{
				tmp |= Mask(to);
				if (Mask(rotate90Left[to]) & shiftState)
					break;
				if (state == 0)
				{
					minus8Direction[square] |= Mask(to);
					directions[square][to] = -8;
				}
			}
                        // Look at this loop:
			for (Square to = square + 8; to <= H8; to += 8)
			{
				tmp |= mask[to];
				if (Mask(rotate90Left[to]) & shiftState)
					break;
			}
                        // And then look at this:
			for (Square to = square + 8; to <= H8; to += 8)
			{
				if (state == 0)
				{
					plus8Direction[square] |= Mask(to);
					directions[square][to] = 8;
				}
				else
					break;
			}
			fileAttack[square][int(state)] = tmp;
		}
	}

As you can see, the commented loops could be one loop instead of two. I have
several blocks like this one, to generate attack masks. All of them, except this
one, has only one loop where this one needs two. If I put them together,
something goes wrong. Back when it happened, I _did_ examine it very carefully
on several platforms with several compilers and with a debugger. I found out
precisely where the problem occured with MSVC++.NET, but I can't remember now.
The important thing is that I just tried to compile the version with the loops
combined, and it showed the error again. And this wasn't even with
optimizations, this was in the standard Debug configuration! I guess, to be
really useful, you would have to have access to the whole source file containing
this code, and I'm not sure I want to do that. But I guess I could send you the
produced assember output for the two versions of the file, if you tell me how to
create files with assembler output in MSVC++.NET, a feature I never use. Or do
you have a better idea?

I have more code that fails with MSVC++.NET. A (simple) part of my book code
fails when compiled with some specific set of optimization options turned on.
This doesn't crash. A very simple test is just always false, so no book moves
are never available to the program. That happened to me at CCT4 after a
recompile, when I enabled some optimization.

/David



This page took 0.01 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.