Author: Dave Gomboc
Date: 23:23:18 02/13/00
Go up one level in this thread
On February 14, 2000 at 00:42:25, Dan Newman wrote:
>On February 13, 2000 at 18:58:00, Tom Kerrigan wrote:
>
>>On February 13, 2000 at 17:32:33, Dan Newman wrote:
>>
>>>I've wondered about this. In isolation (which is usually when I end up
>>>bloating my move generator like this) it's certainly faster to unroll loops,
>>>etc., but once you get a bunch of other things put in this could of course
>>>be a problem. But whenever I fiddle around with this code, it just tends to
>>>get slower... I just looked at the .obj for the move generator and it's
>>>14k and make/unmake is 16k (for the 0x88). For the bitboard engine these
>>>are even larger: 22k and 34 k resp. They are in fact the largest modules
>>>in the program with search coming in a close third...
>>
>>Yeah, unrolling loops can be good and bad.
>>
>>But in the code you posted, you unrolled a loop at the expense of a switch
>>statement. I don't think this is a very good tradeoff.
>>
>>If you keep the entries in your piece list in order, you can possibly avoid the
>>switch statement. Although this involves more code bloat.
>>
>>-Tom
>
>Switch statements aren't as good as I'd like. Ideally they'd just give you
>a quick dispatch to the right piece of code, unfortunately they do a little
>more work than is needed in this case. I've looked at the code generated for
>switch statements, and it would be much better if it didn't have to check the
>argument for the default case--since I know there isn't one. I looked for a
>pragma or something to disable those extra, uneeded tests, but couldn't find
>anything (MSVC 5.0). There are occasions, though, when you can avoid multiple
>if-tests and/or looping overhead by going to a switch statement form. It's
>also pretty straight forward and transparently easy to understand...
Visual C++ 6.0 has __assume.
Dave
--- visual c++ 6.0 documentation quoted below ---
__assume
Microsoft Specific
__assume(expression)
The __assume keyword passes a hint to the optimizer. The optimizer assumes that
the condition represented by expression is true at the point where the keyword
appears and remains true until expression is altered (for example, by assignment
to a variable). Selective use of hints passed to the optimizer by __assume can
improve optimization.
The most common use of __assume is with the default case of a switch statement,
as shown below.
Example
#ifdef DEGUG
# define ASSERT(e) ( ((e) || assert(__FILE__, __LINE__) )
#else
# define ASSERT(e) ( __assume(e) )
#endif
void gloo(int p)
{
switch(p){
case 1:
blah(1);
break;
case 2:
blah(-1);
break;
default:
__assume(0);
// This tells the optimizer that the default
// cannot be reached. As so it does not have to generate
// the extra code to check that 'p' has a value
// not represented by a case arm. This makes the switch
// run faster.
}
}
The use of __assume(0) tells the optimizer that the default case cannot be
reached. As a result, the compiler does not generate code to test whether p has
a value not represented in a case statement. Note that __assume(0) must be the
first statement in the body of the default case for this to work.
Because the compiler generates code based on the __assume statement, that code
may not correctly if the expression inside the __assume statement is false at
runtime. If you are not sure that the expression will always be true at runtime,
you can use the assert function to protect the code:
Example
# define ASSERT(e) ( ((e) || assert(__FILE__, __LINE__)), __assume(e) )
Unfortunately, this use of assert prevents the compiler from performing the
default-case optimization shown above. Therefore, you may want to use a separate
macro instead:
Example
#ifdef DEBUG
# define NODEFAULT ASSERT(0)
#else
# define NODEFAULT __assume(0)
#endif
default:
NODEFAULT;
END Microsoft Specific
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.