mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-23 05:07:14 +00:00
Consistent Integer Types
example of using, to avoid mixed usage of std::uint/std::int and uint/int... ```cpp using u64 = std::uint64_t; using u32 = std::uint32_t; using u16 = std::uint16_t; using u8 = std::uint8_t; using i64 = std::int64_t; using i32 = std::int32_t; using i16 = std::int16_t; using i8 = std::int8_t; using usize = std::size_t; using isize = std::ptrdiff_t; #if defined(__GNUC__) && defined(IS_64BIT) __extension__ using u128 = unsigned __int128; __extension__ using i128 = signed __int128; #endif ``` closes https://github.com/official-stockfish/Stockfish/pull/6874 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
e4a635486a
commit
dd3e1c4a50
+22
-25
@@ -24,7 +24,6 @@
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <initializer_list>
|
||||
#include <iostream>
|
||||
@@ -67,7 +66,7 @@ using namespace Search;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint64_t NODES_LIMIT_OUTPUT = 10'000'000;
|
||||
constexpr u64 NODES_LIMIT_OUTPUT = 10'000'000;
|
||||
|
||||
constexpr int SEARCHEDLIST_CAPACITY = 32;
|
||||
using SearchedList = ValueList<Move, SEARCHEDLIST_CAPACITY>;
|
||||
@@ -130,7 +129,7 @@ void update_correction_history(const Position& pos,
|
||||
}
|
||||
|
||||
// Add a small random component to draw evaluations to avoid 3-fold blindness
|
||||
Value value_draw(size_t nodes) { return VALUE_DRAW - 1 + Value(nodes & 0x2); }
|
||||
Value value_draw(usize nodes) { return VALUE_DRAW - 1 + Value(nodes & 0x2); }
|
||||
Value value_to_tt(Value v, int ply);
|
||||
Value value_from_tt(Value v, int ply, int r50c);
|
||||
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus);
|
||||
@@ -160,9 +159,9 @@ bool is_shuffling(Move move, Stack* const ss, const Position& pos) {
|
||||
|
||||
Search::Worker::Worker(SharedState& sharedState,
|
||||
std::unique_ptr<ISearchManager> sm,
|
||||
size_t threadId,
|
||||
size_t numaThreadId,
|
||||
size_t numaTotalThreads,
|
||||
usize threadId,
|
||||
usize numaThreadId,
|
||||
usize numaTotalThreads,
|
||||
NumaReplicatedAccessToken token) :
|
||||
// Unpack the SharedState struct into member variables
|
||||
sharedHistory(sharedState.sharedHistories.at(token.get_numa_index())),
|
||||
@@ -306,13 +305,13 @@ bool Search::Worker::iterative_deepening() {
|
||||
mainThread->iterValue.fill(mainThread->bestPreviousScore);
|
||||
}
|
||||
|
||||
size_t multiPV = size_t(options["MultiPV"]);
|
||||
usize multiPV = usize(options["MultiPV"]);
|
||||
Skill skill(options["Skill Level"], options["UCI_LimitStrength"] ? int(options["UCI_Elo"]) : 0);
|
||||
|
||||
// When playing with strength handicap enable MultiPV search that we will
|
||||
// use behind-the-scenes to retrieve a set of possible moves.
|
||||
if (skill.enabled())
|
||||
multiPV = std::max(multiPV, size_t(4));
|
||||
multiPV = std::max(multiPV, usize(4));
|
||||
|
||||
multiPV = std::min(multiPV, rootMoves.size());
|
||||
|
||||
@@ -343,8 +342,8 @@ bool Search::Worker::iterative_deepening() {
|
||||
for (RootMove& rm : rootMoves)
|
||||
rm.previousScore = rm.score;
|
||||
|
||||
size_t pvFirst = 0;
|
||||
pvLast = 0;
|
||||
usize pvFirst = 0;
|
||||
pvLast = 0;
|
||||
|
||||
if (!threads.increaseDepth)
|
||||
searchAgainCounter++;
|
||||
@@ -530,8 +529,7 @@ bool Search::Worker::iterative_deepening() {
|
||||
// Do we have time for the next iteration? Can we stop searching now?
|
||||
if (limits.use_time_management() && !threads.stop && !mainThread->stopOnPonderhit)
|
||||
{
|
||||
uint64_t nodesEffort =
|
||||
rootMoves[0].effort * 100000 / std::max(uint64_t(1), uint64_t(nodes));
|
||||
u64 nodesEffort = rootMoves[0].effort * 100000 / std::max(u64(1), u64(nodes));
|
||||
|
||||
double fallingEval = (11.87 + 2.21 * (mainThread->bestPreviousAverageScore - bestValue)
|
||||
+ 1.0 * (mainThread->iterValue[iterIdx] - bestValue))
|
||||
@@ -548,8 +546,7 @@ bool Search::Worker::iterative_deepening() {
|
||||
double bestMoveInstability = 1.096 + 2.29 * totBestMoveChanges / threads.size();
|
||||
|
||||
double highBestMoveEffort = std::clamp(
|
||||
interpolate(int64_t(nodesEffort), int64_t(79219), int64_t(101822), 0.924, 0.71), 0.71,
|
||||
0.924);
|
||||
interpolate(i64(nodesEffort), i64(79219), i64(101822), 0.924, 0.71), 0.71, 0.924);
|
||||
|
||||
double totalTime = mainThread->tm.optimum() * fallingEval * reduction
|
||||
* bestMoveInstability * highBestMoveEffort;
|
||||
@@ -652,7 +649,7 @@ void Search::Worker::clear() {
|
||||
for (auto& h : to)
|
||||
h.fill(-552);
|
||||
|
||||
for (size_t i = 1; i < reductions.size(); ++i)
|
||||
for (usize i = 1; i < reductions.size(); ++i)
|
||||
reductions[i] = int(2834 / 128.0 * std::log(i));
|
||||
|
||||
refreshTable.clear(network[numaAccessToken]);
|
||||
@@ -712,7 +709,7 @@ Value Search::Worker::search(
|
||||
maxValue = VALUE_INFINITE;
|
||||
|
||||
ss->followPV = rootNode
|
||||
|| ((ss - 1)->followPV && static_cast<size_t>(ss->ply - 1) < lastIterationPV.size()
|
||||
|| ((ss - 1)->followPV && static_cast<usize>(ss->ply - 1) < lastIterationPV.size()
|
||||
&& (ss - 1)->currentMove == lastIterationPV[ss->ply - 1]);
|
||||
|
||||
// Check for the available remaining time
|
||||
@@ -1241,7 +1238,7 @@ moves_loop: // When in check, search starts here
|
||||
extension = -2;
|
||||
}
|
||||
|
||||
uint64_t nodeCount = rootNode ? uint64_t(nodes) : 0;
|
||||
u64 nodeCount = rootNode ? u64(nodes) : 0;
|
||||
|
||||
// Step 16. Make the move
|
||||
do_move(pos, move, st, givesCheck, ss);
|
||||
@@ -1885,7 +1882,7 @@ void update_all_stats(const Position& pos,
|
||||
if (!PvNode)
|
||||
// Important: don't remove the cast to a 64-bit number else the multiplication
|
||||
// can overflow on 32-bit platforms which would change the bench signature
|
||||
bonus += bonus * uint64_t(quietsSearched.size() + capturesSearched.size()) / 256;
|
||||
bonus += bonus * u64(quietsSearched.size() + capturesSearched.size()) / 256;
|
||||
|
||||
if (!pos.capture_stage(bestMove))
|
||||
{
|
||||
@@ -1969,7 +1966,7 @@ void update_quiet_histories(
|
||||
|
||||
// When playing with strength handicap, choose the best move among a set of
|
||||
// RootMoves using a statistical rule dependent on 'level'. Idea by Heinz van Saanen.
|
||||
Move Skill::pick_best(const RootMoves& rootMoves, size_t multiPV) {
|
||||
Move Skill::pick_best(const RootMoves& rootMoves, usize multiPV) {
|
||||
static PRNG rng(now()); // PRNG sequence should be non-deterministic
|
||||
|
||||
// RootMoves are already sorted by score in descending order
|
||||
@@ -1981,7 +1978,7 @@ Move Skill::pick_best(const RootMoves& rootMoves, size_t multiPV) {
|
||||
// Choose best move. For each move score we add two terms, both dependent on
|
||||
// weakness. One is deterministic and bigger for weaker levels, and one is
|
||||
// random. Then we choose the move with the resulting highest score.
|
||||
for (size_t i = 0; i < multiPV; ++i)
|
||||
for (usize i = 0; i < multiPV; ++i)
|
||||
{
|
||||
// This is our magic formula
|
||||
int push = int(weakness * int(topScore - rootMoves[i].score)
|
||||
@@ -2058,7 +2055,7 @@ void syzygy_extend_pv(const OptionsMap& options,
|
||||
int ply = 1;
|
||||
|
||||
// Step 1, walk the PV to the last position in TB with correct decisive score
|
||||
while (size_t(ply) < rootMove.pv.size())
|
||||
while (usize(ply) < rootMove.pv.size())
|
||||
{
|
||||
Move& pvMove = rootMove.pv[ply];
|
||||
|
||||
@@ -2154,7 +2151,7 @@ void syzygy_extend_pv(const OptionsMap& options,
|
||||
v = VALUE_DRAW;
|
||||
|
||||
// Undo the PV moves
|
||||
for (size_t i = rootMove.pv.size(); i > 0; --i)
|
||||
for (usize i = rootMove.pv.size(); i > 0; --i)
|
||||
pos.undo_move(rootMove.pv[i - 1]);
|
||||
|
||||
// Inform if we couldn't get a full extension in time
|
||||
@@ -2172,10 +2169,10 @@ void SearchManager::pv(Search::Worker& worker,
|
||||
const auto nodes = threads.nodes_searched();
|
||||
auto& rootMoves = worker.rootMoves;
|
||||
auto& pos = worker.rootPos;
|
||||
size_t multiPV = std::min(size_t(worker.options["MultiPV"]), rootMoves.size());
|
||||
uint64_t tbHits = threads.tb_hits() + (worker.tbConfig.rootInTB ? rootMoves.size() : 0);
|
||||
usize multiPV = std::min(usize(worker.options["MultiPV"]), rootMoves.size());
|
||||
u64 tbHits = threads.tb_hits() + (worker.tbConfig.rootInTB ? rootMoves.size() : 0);
|
||||
|
||||
for (size_t i = 0; i < multiPV; ++i)
|
||||
for (usize i = 0; i < multiPV; ++i)
|
||||
{
|
||||
bool usePreviousScore = rootMoves[i].score == -VALUE_INFINITE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user