mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 19:46:55 +08:00
Remove unused immintring. Include intrin.h only on some platforms, otherwise builtins are used.
This commit is contained in:
@@ -39,17 +39,11 @@ THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <array>
|
||||
#include <immintrin.h>
|
||||
|
||||
#ifdef linux
|
||||
#include <x86intrin.h>
|
||||
#else
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
#include <nmmintrin.h>
|
||||
#include <limits>
|
||||
|
||||
#if (defined(_MSC_VER) || defined(__INTEL_COMPILER)) && !defined(__clang__)
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
namespace chess
|
||||
{
|
||||
@@ -177,87 +171,12 @@ namespace chess
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template <typename IntT>
|
||||
[[nodiscard]] constexpr IntT mulSaturate(IntT lhs, IntT rhs)
|
||||
{
|
||||
static_assert(std::is_unsigned_v<IntT>); // currently no support for signed
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
|
||||
if (lhs == 0) return 0;
|
||||
|
||||
const IntT result = lhs * rhs;
|
||||
return result / lhs == rhs ? result : std::numeric_limits<IntT>::max();
|
||||
|
||||
#elif defined (__GNUC__)
|
||||
|
||||
IntT result{};
|
||||
return __builtin_mul_overflow(lhs, rhs, &result) ? std::numeric_limits<IntT>::max() : result;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
[[nodiscard]] constexpr IntT addSaturate(IntT lhs, IntT rhs)
|
||||
{
|
||||
static_assert(std::is_unsigned_v<IntT>); // currently no support for signed
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
|
||||
const IntT result = lhs + rhs;
|
||||
return result >= lhs ? result : std::numeric_limits<IntT>::max();
|
||||
|
||||
#elif defined (__GNUC__)
|
||||
|
||||
IntT result{};
|
||||
return __builtin_add_overflow(lhs, rhs, &result) ? std::numeric_limits<IntT>::max() : result;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
[[nodiscard]] constexpr bool addOverflows(IntT lhs, IntT rhs)
|
||||
{
|
||||
#if defined (_MSC_VER)
|
||||
|
||||
return static_cast<IntT>(lhs + rhs) < lhs;
|
||||
|
||||
#elif defined (__GNUC__)
|
||||
|
||||
IntT result{};
|
||||
__builtin_add_overflow(lhs, rhs, &result);
|
||||
return result;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
[[nodiscard]] constexpr IntT floorLog2(IntT value)
|
||||
{
|
||||
return intrin::msb_constexpr(value);
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
constexpr std::size_t maxFibonacciNumberIndexForType()
|
||||
{
|
||||
static_assert(std::is_unsigned_v<IntT>);
|
||||
|
||||
switch (sizeof(IntT))
|
||||
{
|
||||
case 8:
|
||||
return 93;
|
||||
case 4:
|
||||
return 47;
|
||||
case 2:
|
||||
return 24;
|
||||
case 1:
|
||||
return 13;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
constexpr auto computeMasks()
|
||||
{
|
||||
@@ -278,26 +197,6 @@ namespace chess
|
||||
template <typename IntT>
|
||||
constexpr auto nbitmask = computeMasks<IntT>();
|
||||
|
||||
template <typename IntT>
|
||||
constexpr auto computeFibonacciNumbers()
|
||||
{
|
||||
constexpr std::size_t size = maxFibonacciNumberIndexForType<IntT>() + 1;
|
||||
std::array<IntT, size> numbers{};
|
||||
numbers[0] = 0;
|
||||
numbers[1] = 1;
|
||||
|
||||
for (std::size_t i = 2; i < size; ++i)
|
||||
{
|
||||
numbers[i] = numbers[i - 1] + numbers[i - 2];
|
||||
}
|
||||
|
||||
return numbers;
|
||||
}
|
||||
|
||||
// F(0) = 0, F(1) = 1
|
||||
template <typename IntT>
|
||||
constexpr auto fibonacciNumbers = computeFibonacciNumbers<IntT>();
|
||||
|
||||
template <std::size_t N, typename FromT, typename ToT = std::make_signed_t<FromT>>
|
||||
inline ToT signExtend(FromT value)
|
||||
{
|
||||
@@ -2700,7 +2599,7 @@ namespace chess
|
||||
return Bitboard::square(sq0) | sq1;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Bitboard operator""_bb(std::uint64_t bits)
|
||||
[[nodiscard]] constexpr Bitboard operator""_bb(unsigned long long bits)
|
||||
{
|
||||
return Bitboard::fromBits(bits);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user