#ifndef NNUE_COMMON_H_INCLUDED
#define NNUE_COMMON_H_INCLUDED
+#include <cstring>
+#include <iostream>
+
#if defined(USE_AVX2)
#include <immintrin.h>
// compiled with older g++ crashes because the output memory is not aligned
// even though alignas is specified.
#if defined(USE_AVX2)
-#if defined(__GNUC__ ) && (__GNUC__ < 9)
+#if defined(__GNUC__ ) && (__GNUC__ < 9) && defined(_WIN32)
#define _mm256_loadA_si256 _mm256_loadu_si256
#define _mm256_storeA_si256 _mm256_storeu_si256
#else
#endif
#if defined(USE_AVX512)
-#if defined(__GNUC__ ) && (__GNUC__ < 9)
+#if defined(__GNUC__ ) && (__GNUC__ < 9) && defined(_WIN32)
#define _mm512_loadA_si512 _mm512_loadu_si512
#define _mm512_storeA_si512 _mm512_storeu_si512
#else
return (n + base - 1) / base * base;
}
+ // Read a signed or unsigned integer from a stream in little-endian order
+ template <typename IntType>
+ inline IntType read_le(std::istream& stream) {
+ // Read the relevant bytes from the stream in little-endian order
+ std::uint8_t u[sizeof(IntType)];
+ stream.read(reinterpret_cast<char*>(u), sizeof(IntType));
+ // Use unsigned arithmetic to convert to machine order
+ typename std::make_unsigned<IntType>::type v = 0;
+ for (std::size_t i = 0; i < sizeof(IntType); ++i)
+ v = (v << 8) | u[sizeof(IntType) - i - 1];
+ // Copy the machine-ordered bytes into a potentially signed value
+ IntType w;
+ std::memcpy(&w, &v, sizeof(IntType));
+ return w;
+ }
+
} // namespace Eval::NNUE
#endif // #ifndef NNUE_COMMON_H_INCLUDED