official-stockfish/Stockfish — pull request #19 by Britvich (2014-07-07 04:56:08+00:00)
Title: TT Loop Optimizations

Optimizations to the loops in the `TT` have been shown to **increase Elo by ~2 points** (under heavy cache pressure):

![image](https://cloud.githubusercontent.com/assets/7193012/3491447/a72ddaec-0591-11e4-8c36-d901af32a4cd.png)

_Note: This patch is a boiled-down version of `tt_sailfish` that only includes the **minimal changes** necessary to perform these loop optimizations._

The loop in `store` that finds the best entry to replace has been optimized so the check for a better replacement candidate never takes place against the first entry of a given cluster. Since this line:

```
tte = replace = first_entry(key);
```

...already sets `replace` to the first entry in a cluster, there is **no need consider the first entry again** as a better replacement candidate. This means the check:

```
// Is the next entry a better candidate for replacement?
if ((tte->gen() == generation || tte->bound() == BOUND_EXACT)
- (replace->gen() == generation)
- (tte->depth8 < replace->depth8) < 0)
```

...only needs to be executed a maximum of **2 times**, instead of the current maximum of 3 times.

In addition, the `probe` loop has been unrolled, avoiding some unnecessary housekeeping instructions.

**No functional change**