]> git.sesse.net Git - stockfish/blobdiff - src/nnue/nnue_common.h
New NNUE architecture and net
[stockfish] / src / nnue / nnue_common.h
index 8c54f9baeebb46eeac67138f3d56665612054124..dc70006120dca4bef8502d7e6428c63425f106ce 100644 (file)
@@ -46,7 +46,7 @@
 namespace Stockfish::Eval::NNUE {
 
   // Version of the evaluation file
-  constexpr std::uint32_t Version = 0x7AF32F16u;
+  constexpr std::uint32_t Version = 0x7AF32F20u;
 
   // Constant used in evaluation value calculation
   constexpr int OutputScale = 16;
@@ -99,6 +99,24 @@ namespace Stockfish::Eval::NNUE {
       return result;
   }
 
+  template <typename IntType>
+  inline void write_little_endian(std::ostream& stream, IntType value) {
+
+      std::uint8_t u[sizeof(IntType)];
+      typename std::make_unsigned<IntType>::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<char*>(u), sizeof(IntType));
+  }
 }  // namespace Stockfish::Eval::NNUE
 
 #endif // #ifndef NNUE_COMMON_H_INCLUDED