mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +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
-24
@@ -67,8 +67,8 @@ namespace Detail {
|
||||
template<typename T>
|
||||
bool read_parameters(std::istream& stream, T& reference) {
|
||||
|
||||
std::uint32_t header;
|
||||
header = read_little_endian<std::uint32_t>(stream);
|
||||
u32 header;
|
||||
header = read_little_endian<u32>(stream);
|
||||
if (!stream || header != T::get_hash_value())
|
||||
return false;
|
||||
return reference.read_parameters(stream);
|
||||
@@ -78,7 +78,7 @@ bool read_parameters(std::istream& stream, T& reference) {
|
||||
template<typename T>
|
||||
bool write_parameters(std::ostream& stream, const T& reference) {
|
||||
|
||||
write_little_endian<std::uint32_t>(stream, T::get_hash_value());
|
||||
write_little_endian<u32>(stream, T::get_hash_value());
|
||||
return reference.write_parameters(stream);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ NetworkOutput Network::evaluate(const Position& pos,
|
||||
AccumulatorStack& accumulatorStack,
|
||||
AccumulatorCaches& cache) const {
|
||||
|
||||
constexpr uint64_t alignment = CacheLineSize;
|
||||
constexpr u64 alignment = CacheLineSize;
|
||||
|
||||
alignas(alignment) TransformedFeatureType transformedFeatures[FeatureTransformer::BufferSize];
|
||||
|
||||
@@ -188,7 +188,7 @@ void Network::verify(std::string evalfilePath,
|
||||
|
||||
if (f)
|
||||
{
|
||||
size_t size = sizeof(featureTransformer) + sizeof(NetworkArchitecture) * LayerStacks;
|
||||
usize size = sizeof(featureTransformer) + sizeof(NetworkArchitecture) * LayerStacks;
|
||||
f("NNUE evaluation using " + evalfilePath + " (" + std::to_string(size / (1024 * 1024))
|
||||
+ "MiB, (" + std::to_string(featureTransformer.InputDimensions) + ", "
|
||||
+ std::to_string(network[0].TransformedFeatureDimensions) + ", "
|
||||
@@ -202,7 +202,7 @@ NnueEvalTrace Network::trace_evaluate(const Position& pos,
|
||||
AccumulatorStack& accumulatorStack,
|
||||
AccumulatorCaches& cache) const {
|
||||
|
||||
constexpr uint64_t alignment = CacheLineSize;
|
||||
constexpr u64 alignment = CacheLineSize;
|
||||
|
||||
alignas(alignment) TransformedFeatureType transformedFeatures[FeatureTransformer::BufferSize];
|
||||
|
||||
@@ -241,7 +241,7 @@ void Network::load_internal() {
|
||||
// C++ way to prepare a buffer for a memory stream
|
||||
class MemoryBuffer: public std::basic_streambuf<char> {
|
||||
public:
|
||||
MemoryBuffer(char* p, size_t n) {
|
||||
MemoryBuffer(char* p, usize n) {
|
||||
setg(p, p, p + n);
|
||||
setp(p, p + n);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void Network::load_internal() {
|
||||
#endif
|
||||
|
||||
MemoryBuffer buffer(const_cast<char*>(reinterpret_cast<const char*>(gEmbeddedNNUEData)),
|
||||
size_t(gEmbeddedNNUESize));
|
||||
usize(gEmbeddedNNUESize));
|
||||
|
||||
std::istream stream(&buffer);
|
||||
auto description = load(stream);
|
||||
@@ -287,11 +287,11 @@ std::optional<std::string> Network::load(std::istream& stream) {
|
||||
}
|
||||
|
||||
|
||||
std::size_t Network::get_content_hash() const {
|
||||
usize Network::get_content_hash() const {
|
||||
if (!initialized)
|
||||
return 0;
|
||||
|
||||
std::size_t h = 0;
|
||||
usize h = 0;
|
||||
hash_combine(h, featureTransformer);
|
||||
for (auto&& layerstack : network)
|
||||
hash_combine(h, layerstack);
|
||||
@@ -300,12 +300,12 @@ std::size_t Network::get_content_hash() const {
|
||||
}
|
||||
|
||||
// Read network header
|
||||
bool Network::read_header(std::istream& stream, std::uint32_t* hashValue, std::string* desc) const {
|
||||
std::uint32_t version, size;
|
||||
bool Network::read_header(std::istream& stream, u32* hashValue, std::string* desc) const {
|
||||
u32 version, size;
|
||||
|
||||
version = read_little_endian<std::uint32_t>(stream);
|
||||
*hashValue = read_little_endian<std::uint32_t>(stream);
|
||||
size = read_little_endian<std::uint32_t>(stream);
|
||||
version = read_little_endian<u32>(stream);
|
||||
*hashValue = read_little_endian<u32>(stream);
|
||||
size = read_little_endian<u32>(stream);
|
||||
if (!stream || version != Version)
|
||||
return false;
|
||||
desc->resize(size);
|
||||
@@ -315,26 +315,24 @@ bool Network::read_header(std::istream& stream, std::uint32_t* hashValue, std::s
|
||||
|
||||
|
||||
// Write network header
|
||||
bool Network::write_header(std::ostream& stream,
|
||||
std::uint32_t hashValue,
|
||||
const std::string& desc) const {
|
||||
write_little_endian<std::uint32_t>(stream, Version);
|
||||
write_little_endian<std::uint32_t>(stream, hashValue);
|
||||
write_little_endian<std::uint32_t>(stream, std::uint32_t(desc.size()));
|
||||
bool Network::write_header(std::ostream& stream, u32 hashValue, const std::string& desc) const {
|
||||
write_little_endian<u32>(stream, Version);
|
||||
write_little_endian<u32>(stream, hashValue);
|
||||
write_little_endian<u32>(stream, u32(desc.size()));
|
||||
stream.write(&desc[0], desc.size());
|
||||
return !stream.fail();
|
||||
}
|
||||
|
||||
|
||||
bool Network::read_parameters(std::istream& stream, std::string& netDescription) {
|
||||
std::uint32_t hashValue;
|
||||
u32 hashValue;
|
||||
if (!read_header(stream, &hashValue, &netDescription))
|
||||
return false;
|
||||
if (hashValue != Network::hash)
|
||||
return false;
|
||||
if (!Detail::read_parameters(stream, featureTransformer))
|
||||
return false;
|
||||
for (std::size_t i = 0; i < LayerStacks; ++i)
|
||||
for (usize i = 0; i < LayerStacks; ++i)
|
||||
{
|
||||
if (!Detail::read_parameters(stream, network[i]))
|
||||
return false;
|
||||
@@ -348,7 +346,7 @@ bool Network::write_parameters(std::ostream& stream, const std::string& netDescr
|
||||
return false;
|
||||
if (!Detail::write_parameters(stream, featureTransformer))
|
||||
return false;
|
||||
for (std::size_t i = 0; i < LayerStacks; ++i)
|
||||
for (usize i = 0; i < LayerStacks; ++i)
|
||||
{
|
||||
if (!Detail::write_parameters(stream, network[i]))
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user