mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 09:39:36 +00:00
Microptimize MoveList loop
Add MOVE_NONE at the tail, this allows to loop across MoveList checking for *it != MOVE_NONE, and because *it is used imediately after compiler is able to reuse it. With this small patch perft speed increased of 3% And it is also a semplification ! No functional change.
This commit is contained in:
parent
38cfbeeb50
commit
d3608c4e79
6 changed files with 6 additions and 7 deletions
|
@ -436,7 +436,7 @@ Move PolyglotBook::probe(const Position& pos, const string& fName, bool pickBest
|
||||||
move = make<PROMOTION>(from_sq(move), to_sq(move), PieceType(pt + 1));
|
move = make<PROMOTION>(from_sq(move), to_sq(move), PieceType(pt + 1));
|
||||||
|
|
||||||
// Add 'special move' flags and verify it is legal
|
// Add 'special move' flags and verify it is legal
|
||||||
for (MoveList<LEGAL> it(pos); !it.end(); ++it)
|
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||||
if (move == (*it ^ type_of(*it)))
|
if (move == (*it ^ type_of(*it)))
|
||||||
return *it;
|
return *it;
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,9 @@ MoveStack* generate(const Position& pos, MoveStack* mlist);
|
||||||
template<GenType T>
|
template<GenType T>
|
||||||
struct MoveList {
|
struct MoveList {
|
||||||
|
|
||||||
explicit MoveList(const Position& pos) : cur(mlist), last(generate<T>(pos, mlist)) {}
|
explicit MoveList(const Position& pos) : cur(mlist), last(generate<T>(pos, mlist)) { last->move = MOVE_NONE; }
|
||||||
void operator++() { cur++; }
|
void operator++() { cur++; }
|
||||||
Move operator*() const { return cur->move; }
|
Move operator*() const { return cur->move; }
|
||||||
bool end() const { return cur == last; }
|
|
||||||
size_t size() const { return last - mlist; }
|
size_t size() const { return last - mlist; }
|
||||||
bool contains(Move m) const {
|
bool contains(Move m) const {
|
||||||
for (const MoveStack* it(mlist); it != last; ++it) if (it->move == m) return true;
|
for (const MoveStack* it(mlist); it != last; ++it) if (it->move == m) return true;
|
||||||
|
|
|
@ -89,7 +89,7 @@ Move move_from_uci(const Position& pos, string& str) {
|
||||||
if (str.length() == 5) // Junior could send promotion piece in uppercase
|
if (str.length() == 5) // Junior could send promotion piece in uppercase
|
||||||
str[4] = char(tolower(str[4]));
|
str[4] = char(tolower(str[4]));
|
||||||
|
|
||||||
for (MoveList<LEGAL> it(pos); !it.end(); ++it)
|
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||||
if (str == move_to_uci(*it, pos.is_chess960()))
|
if (str == move_to_uci(*it, pos.is_chess960()))
|
||||||
return *it;
|
return *it;
|
||||||
|
|
||||||
|
|
|
@ -408,7 +408,7 @@ const string Position::pretty(Move move) const {
|
||||||
ss << square_to_string(pop_lsb(&b)) << " ";
|
ss << square_to_string(pop_lsb(&b)) << " ";
|
||||||
|
|
||||||
ss << "\nLegal moves: ";
|
ss << "\nLegal moves: ";
|
||||||
for (MoveList<LEGAL> it(*this); !it.end(); ++it)
|
for (MoveList<LEGAL> it(*this); *it; ++it)
|
||||||
ss << move_to_san(*const_cast<Position*>(this), *it) << " ";
|
ss << move_to_san(*const_cast<Position*>(this), *it) << " ";
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
|
|
|
@ -163,7 +163,7 @@ size_t Search::perft(Position& pos, Depth depth) {
|
||||||
size_t cnt = 0;
|
size_t cnt = 0;
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
for (MoveList<LEGAL> it(pos); !it.end(); ++it)
|
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||||
{
|
{
|
||||||
pos.do_move(*it, st, ci, pos.move_gives_check(*it, ci));
|
pos.do_move(*it, st, ci, pos.move_gives_check(*it, ci));
|
||||||
cnt += perft(pos, depth - ONE_PLY);
|
cnt += perft(pos, depth - ONE_PLY);
|
||||||
|
|
|
@ -371,7 +371,7 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
||||||
SetupStates = states; // Ownership transfer here
|
SetupStates = states; // Ownership transfer here
|
||||||
RootMoves.clear();
|
RootMoves.clear();
|
||||||
|
|
||||||
for (MoveList<LEGAL> it(pos); !it.end(); ++it)
|
for (MoveList<LEGAL> it(pos); *it; ++it)
|
||||||
if ( searchMoves.empty()
|
if ( searchMoves.empty()
|
||||||
|| std::count(searchMoves.begin(), searchMoves.end(), *it))
|
|| std::count(searchMoves.begin(), searchMoves.end(), *it))
|
||||||
RootMoves.push_back(RootMove(*it));
|
RootMoves.push_back(RootMove(*it));
|
||||||
|
|
Loading…
Add table
Reference in a new issue