From 787beb8a33676669f95d4fec7ab990b24c1cf62f Mon Sep 17 00:00:00 2001 From: Ryan Hechenberger Date: Fri, 26 Jun 2026 12:05:37 +1000 Subject: [PATCH 1/2] update intrin BMI2 to work within constexpr functions --- include/warthog/domain/grid.h | 18 ++++++++++++++---- include/warthog/util/intrin.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/warthog/domain/grid.h b/include/warthog/domain/grid.h index 455edac..0862855 100644 --- a/include/warthog/domain/grid.h +++ b/include/warthog/domain/grid.h @@ -572,10 +572,15 @@ dir_unit_point(direction_id d) noexcept | (0b0000 << NORTHWEST_ID * 4) | (0b1010 << SOUTHEAST_ID * 4) | (0b1000 << SOUTHWEST_ID * 4); #if WARTHOG_INTRIN_HAS(BMI2) - res.v = _pdep_u32(packed_reldir >> d * 4, 0xC000'C000u); -#else + if !consteval { + // _pdep_u32 may not be constexpr + res.v = _pdep_u32(packed_reldir >> d * 4, 0xC000'C000u); + } else { +#endif res.p.x = (packed_reldir >> d * 4) & 0b11; res.p.y = (packed_reldir >> (d * 4 + 2)) & 0b11; +#if WARTHOG_INTRIN_HAS(BMI2) + } // end if !consteval #endif res.p.x -= 1; res.p.y -= 1; @@ -605,10 +610,15 @@ dir_unit_point_secic(direction_id d) noexcept // for second-intercardinal, return the intercardinal d = d < 8 ? d : secic_intercardinal(d); #if WARTHOG_INTRIN_HAS(BMI2) - res.v = _pdep_u32(packed_reldir >> d * 4, 0xC000'C000u); -#else + if !consteval { + // _pdep_u32 may not be constexpr + res.v = _pdep_u32(packed_reldir >> d * 4, 0xC000'C000u); + } else { +#endif res.p.x = (packed_reldir >> d * 4) & 0b11; res.p.y = (packed_reldir >> (d * 4 + 2)) & 0b11; +#if WARTHOG_INTRIN_HAS(BMI2) + } // end if !consteval #endif res.p.x -= 1; res.p.y -= 1; diff --git a/include/warthog/util/intrin.h b/include/warthog/util/intrin.h index 010a6c9..ddd8a8b 100644 --- a/include/warthog/util/intrin.h +++ b/include/warthog/util/intrin.h @@ -14,6 +14,8 @@ // Check // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html +#include + #if defined(__x86_64__) && __has_include() #include #define WARTHOG_INTRIN From e5901f31f4ce0e9de70db8c08cb6130d23d3ed5a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 02:22:05 +0000 Subject: [PATCH 2/2] auto clang-format action --- include/warthog/domain/grid.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/include/warthog/domain/grid.h b/include/warthog/domain/grid.h index 0862855..b5e8ab3 100644 --- a/include/warthog/domain/grid.h +++ b/include/warthog/domain/grid.h @@ -572,13 +572,16 @@ dir_unit_point(direction_id d) noexcept | (0b0000 << NORTHWEST_ID * 4) | (0b1010 << SOUTHEAST_ID * 4) | (0b1000 << SOUTHWEST_ID * 4); #if WARTHOG_INTRIN_HAS(BMI2) - if !consteval { + if !consteval + { // _pdep_u32 may not be constexpr res.v = _pdep_u32(packed_reldir >> d * 4, 0xC000'C000u); - } else { + } + else + { #endif - res.p.x = (packed_reldir >> d * 4) & 0b11; - res.p.y = (packed_reldir >> (d * 4 + 2)) & 0b11; + res.p.x = (packed_reldir >> d * 4) & 0b11; + res.p.y = (packed_reldir >> (d * 4 + 2)) & 0b11; #if WARTHOG_INTRIN_HAS(BMI2) } // end if !consteval #endif @@ -610,13 +613,16 @@ dir_unit_point_secic(direction_id d) noexcept // for second-intercardinal, return the intercardinal d = d < 8 ? d : secic_intercardinal(d); #if WARTHOG_INTRIN_HAS(BMI2) - if !consteval { + if !consteval + { // _pdep_u32 may not be constexpr res.v = _pdep_u32(packed_reldir >> d * 4, 0xC000'C000u); - } else { + } + else + { #endif - res.p.x = (packed_reldir >> d * 4) & 0b11; - res.p.y = (packed_reldir >> (d * 4 + 2)) & 0b11; + res.p.x = (packed_reldir >> d * 4) & 0b11; + res.p.y = (packed_reldir >> (d * 4 + 2)) & 0b11; #if WARTHOG_INTRIN_HAS(BMI2) } // end if !consteval #endif