From 66c407545f4ca32d739637cc489cac9551ddea98 Mon Sep 17 00:00:00 2001
From: Greg Burd <greg@burd.me>
Date: Fri, 20 Mar 2026 15:55:39 -0400
Subject: [PATCH v3 5/5] Spin delay on Windows ARM64/MSVC should use
 __isb(_ARM64_BARRIER_SY)

On Windows AArch64 research indicates that ISB performs better than the
YIELD hint instruction at scale.

This matches the pattern used for __aarch64__ with GCC/Clang, which
uses the ISB instruction.

Discussion: https://postgr.es/m/1c2a29b8-5b1e-44f7-a871-71ec5fefc120%40app.fastmail.com
---
 src/include/port/spin_delay.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/include/port/spin_delay.h b/src/include/port/spin_delay.h
index be475f5853c..a3634290cbf 100644
--- a/src/include/port/spin_delay.h
+++ b/src/include/port/spin_delay.h
@@ -67,14 +67,20 @@ pg_spin_delay(void)
 
 #ifdef _MSC_VER
 
+#if defined(_M_ARM64) || defined(_M_ARM64EC)
 	/*
-	 * If using Visual C++ on Win64, inline assembly is unavailable.  Use a
-	 * _mm_pause intrinsic instead of rep nop.
+	 * Research indicates ISB is better than __yield() on AArch64.  See
+	 * https://postgr.es/m/1c2a29b8-5b1e-44f7-a871-71ec5fefc120%40app.fastmail.com.
+	 */
+	__isb(_ARM64_BARRIER_SY);
+#elif defined(_WIN64)
+	/*
+	 * x86_64: inline assembly is unavailable. Use _mm_pause intrinsic
+	 * instead of rep nop.
 	 */
-#if defined(_WIN64)
 	_mm_pause();
 #else
-	/* See comment for gcc code. Same code, MASM syntax */
+	/* x86 32-bit: Use inline assembly. Same code as gcc, MASM syntax */
 	__asm		rep nop;
 #endif
 #endif							/* _MSC_VER */
-- 
2.51.2

