Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize order of a few conditions in search
Also fix size of KingDanger array to reduce memory footprint. Small speed up of around 0.5% No functional change.
- Loading branch information
Showing
2 changed files
with
5 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5cffc03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some doubt about the second condition, because bestValue > VALUE_MATED_IN_MAX_PLY should be quite rare unless the game is over anyway and speed stops to matter...
5cffc03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syzygy1 bestValue > VALUE_MATED_IN_MAX_PLY is almost always true(not rare like you say). VALUE_MATED_IN_MAX_PLY is a negative value.
VALUE_MATE_IN_MAX_PLY = VALUE_MATE - 2 * MAX_PLY,
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
5cffc03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the result when I do a
dbg_hit_on(bestValue > VALUE_MATED_IN_MAX_PLY);
Total 143538024 Hits 127883669 hit rate (%) 89
5cffc03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right that bestValue > VALUE_MATED_IN_MAX_PLY is the common case. I confused it with VALUE_MATE_IN_MAX_PLY and was not thinking.
However, I kind of made two mistakes that cancel each other out.
If the condition is almost always true, it might be faster to first test the more expensive condition which might more often be false. Since the conditions are chained together with && it makes sense to first test conditions that are more often false.
On the other hand, the bestValue test is really cheap. So if this has tested faster...
Btw, I am a bit surprised to see the tMove == MOVE_NONE condition for razoring. Of course that was already there and I'm sure it has been tested, but it seems funny to prune more just because we don't have a tt move.
5cffc03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, that it might be faster to test the more expensive condition since its true most of the time. Thats why I measured how frequently it is true. I expected it be around 99% of the time. But it was only 89%. So I guess we have to rely on the bench measurements which did give a small speedup for me and lucas.
Regarding the razoring condition, I too don't know the history behind why it was added. maybe there is a reason.