X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fnnue%2Fnnue_common.h;h=d41e02377ac34b35378a969034682a9b3029190b;hb=a0e2debe3f1d14f84984a9a2c1482dc41f695548;hp=8c54f9baeebb46eeac67138f3d56665612054124;hpb=b748b46714d5f8e0acca0a042ede1fc95e4f5190;p=stockfish 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