]> git.sesse.net Git - stockfish/blobdiff - src/nnue/nnue_common.h
Exporting the currently loaded network file
[stockfish] / src / nnue / nnue_common.h
index 8c54f9baeebb46eeac67138f3d56665612054124..d41e02377ac34b35378a969034682a9b3029190b 100644 (file)
@@ -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