From 9e50fd33dc5a1fdae95f946c3bdeb8a0e2639ee6 Mon Sep 17 00:00:00 2001 From: 87 Date: Sun, 4 Jan 2026 22:25:57 +0100 Subject: [PATCH 1/2] pinner speedup Bench: 13398527 --- src/geometry.hpp | 10 ++++++++++ src/position.cpp | 13 +++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/geometry.hpp b/src/geometry.hpp index 9aeb82a0..07b37e8e 100644 --- a/src/geometry.hpp +++ b/src/geometry.hpp @@ -54,6 +54,16 @@ forceinline u64 closest(u64 occupied) { return x & occupied; } +forceinline m8x64 ray_fill(m8x64 x) { +#if LPS_AVX512 + u64 y = (x.raw + 0x7E7E7E7E7E7E7E7E) & 0x8080808080808080; + return m8x64{(y - (y >> 7)) << 1}; +#else + u64x8 y = std::bit_cast(x) + u64x8::splat(0x7FFFFFFFFFFFFFFE); + return std::bit_cast(u64x8::zero() - y.shr<63>()); +#endif +} + forceinline m8x64 attackers_from_rays(u8x64 ray_places) { constexpr u8 K = 1 << 0; constexpr u8 WP = 1 << 1; diff --git a/src/position.cpp b/src/position.cpp index b80d8731..738cc2ae 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -573,16 +573,9 @@ std::tuple Position::calc_pin_mask() const { // Pinners are second-closest pieces that are enemy sliders of the correct type. m8x64 pinner = maybe_pinner1 & maybe_pinner2; -// Does this ray have a pinner? -#if LPS_AVX512 - const m8x16 has_attacker_vecmask = u8x16{_mm_set1_epi64x(pinner.raw)}.nonzeros(); - const m8x64 pinned = m8x64{static_cast( - _mm_cvtsi128_si64(has_attacker_vecmask.mask(u8x16{_mm_set1_epi64x(maybe_pinned.raw)}).raw))}; -#else - m8x64 no_pinner_mask = std::bit_cast(std::bit_cast(pinner).to_vector().zeros()); - m8x64 pinned = maybe_pinned.andnot(no_pinner_mask); -#endif - + // Does this ray have a pinner? + const m8x64 has_pinner = geometry::ray_fill(pinner); + const m8x64 pinned = maybe_pinned & has_pinner; u8x64 nonmasked_pinned_ids = geometry::lane_broadcast(pinned.mask(ray_places & u8x64::splat(0xF))); From 5b6a00f566b4ac6916469e8e6ea281cfdf7ff37e Mon Sep 17 00:00:00 2001 From: 87 Date: Mon, 5 Jan 2026 03:06:59 +0100 Subject: [PATCH 2/2] Bench: 13398527 --- src/geometry.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/geometry.hpp b/src/geometry.hpp index 07b37e8e..66d82562 100644 --- a/src/geometry.hpp +++ b/src/geometry.hpp @@ -59,8 +59,7 @@ forceinline m8x64 ray_fill(m8x64 x) { u64 y = (x.raw + 0x7E7E7E7E7E7E7E7E) & 0x8080808080808080; return m8x64{(y - (y >> 7)) << 1}; #else - u64x8 y = std::bit_cast(x) + u64x8::splat(0x7FFFFFFFFFFFFFFE); - return std::bit_cast(u64x8::zero() - y.shr<63>()); + return std::bit_cast(std::bit_cast(x).nonzeros()); #endif }