X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fnnue%2Fnnue_common.h;h=d41e02377ac34b35378a969034682a9b3029190b;hp=8c54f9baeebb46eeac67138f3d56665612054124;hb=58054fd0fa6294510fc8cf76b0ba9673d5094c10;hpb=d777ea79fff0f651bd948c881946cd06bebd9381 diff --git a/src/nnue/nnue_common.h b/src/nnue/nnue_common.h index 8c54f9ba..d41e0237 100644 --- a/src/nnue/nnue_common.h +++ b/src/nnue/nnue_common.h @@ -99,6 +99,24 @@ namespace Stockfish::Eval::NNUE { return result; } + template + inline void write_little_endian(std::ostream& stream, IntType value) { + + std::uint8_t u[sizeof(IntType)]; + typename std::make_unsigned::type v = value; + + std::size_t i = 0; + // if constexpr to silence the warning about shift by 8 + if constexpr (sizeof(IntType) > 1) { + for (; i + 1 < sizeof(IntType); ++i) { + u[i] = v; + v >>= 8; + } + } + u[i] = v; + + stream.write(reinterpret_cast(u), sizeof(IntType)); + } } // namespace Stockfish::Eval::NNUE #endif // #ifndef NNUE_COMMON_H_INCLUDED