mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-23 05:07:14 +00:00
Avoid branching before ValueList::push_back
Instead of checking whether a threat index is valid and then writing to a vector if it isn't, we can instead always write to the buffer of the vector, and only increase the size of the vector if the index is valid. This saves some branch mispredictions. passed STC: https://tests.stockfishchess.org/tests/view/69ceb1689f7a7e3fdfc9a44b LLR: 2.95 (-2.94,2.94) <0.00,2.00> Total: 205760 W: 53109 L: 52561 D: 100090 Ptnml(0-2): 603, 22552, 56076, 22992, 657 local speedtest shows ``` Result of 100 runs (cycles) =========================== base (...ockfish.orig) = 296886 +/- 1645 test (...kfish.df0822) = 298862 +/- 1662 speedup % = +0.67 +/- 0.19 [95% CI; t-statistic] p(speedup > 0) = 1.0000 p(speedup > .5%) = 0.9562 CPU: 16 x Intel(R) Core(TM) Ultra 9 185H Hyperthreading: on ``` closes https://github.com/official-stockfish/Stockfish/pull/6703 No functional change
This commit is contained in:
committed by
Disservin
parent
ead7e650da
commit
df01cb7ed3
@@ -201,6 +201,12 @@ class ValueList {
|
||||
assert(size_ < MaxSize);
|
||||
values_[size_++] = value;
|
||||
}
|
||||
// pushes back value if value < max
|
||||
void push_back_if_lt(const T& value, const T& max) {
|
||||
assert(size_ < MaxSize);
|
||||
values_[size_] = value;
|
||||
size_ += (value < max);
|
||||
}
|
||||
const T* begin() const { return values_; }
|
||||
const T* end() const { return values_ + size_; }
|
||||
const T& operator[](int index) const { return values_[index]; }
|
||||
|
||||
Reference in New Issue
Block a user