|
| 1 | +Backport |
| 2 | +https://github.com/postgres/postgres/commit/a516b3f00d7469cbd1885a2c5903fbd62430a2ac |
| 3 | + |
| 4 | +diff --git a/meson.build b/meson.build |
| 5 | +index e19b737..1cdf332 100644 |
| 6 | +--- a/meson.build |
| 7 | ++++ b/meson.build |
| 8 | +@@ -2322,7 +2322,11 @@ int main(void) |
| 9 | + } |
| 10 | + ''' |
| 11 | + |
| 12 | +- if cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd without -march=armv8-a+crc', |
| 13 | ++ # Vendor-supported versions of Windows for AArch64 require at least ARMv8.1, |
| 14 | ++ # which is where CRC extension support became mandatory. Thus, use it |
| 15 | ++ # unconditionally on MSVC/AArch64. |
| 16 | ++ if (host_cpu == 'aarch64' and cc.get_id() == 'msvc') or \ |
| 17 | ++ cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd without -march=armv8-a+crc', |
| 18 | + args: test_c_args) |
| 19 | + # Use ARM CRC Extension unconditionally |
| 20 | + cdata.set('USE_ARMV8_CRC32C', 1) |
| 21 | +diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h |
| 22 | +index 29ac6cd..53b6ba1 100644 |
| 23 | +--- a/src/include/storage/s_lock.h |
| 24 | ++++ b/src/include/storage/s_lock.h |
| 25 | +@@ -688,13 +688,24 @@ typedef LONG slock_t; |
| 26 | + |
| 27 | + #define SPIN_DELAY() spin_delay() |
| 28 | + |
| 29 | +-/* If using Visual C++ on Win64, inline assembly is unavailable. |
| 30 | +- * Use a _mm_pause intrinsic instead of rep nop. |
| 31 | +- */ |
| 32 | +-#if defined(_WIN64) |
| 33 | ++#ifdef _M_ARM64 |
| 34 | ++static __forceinline void |
| 35 | ++spin_delay(void) |
| 36 | ++{ |
| 37 | ++ /* |
| 38 | ++ * Research indicates ISB is better than __yield() on AArch64. See |
| 39 | ++ * https://postgr.es/m/1c2a29b8-5b1e-44f7-a871-71ec5fefc120%40app.fastmail.com. |
| 40 | ++ */ |
| 41 | ++ __isb(_ARM64_BARRIER_SY); |
| 42 | ++} |
| 43 | ++#elif defined(_WIN64) |
| 44 | + static __forceinline void |
| 45 | + spin_delay(void) |
| 46 | + { |
| 47 | ++ /* |
| 48 | ++ * If using Visual C++ on Win64, inline assembly is unavailable. |
| 49 | ++ * Use a _mm_pause intrinsic instead of rep nop. |
| 50 | ++ */ |
| 51 | + _mm_pause(); |
| 52 | + } |
| 53 | + #else |
| 54 | +@@ -709,10 +720,20 @@ spin_delay(void) |
| 55 | + #include <intrin.h> |
| 56 | + #pragma intrinsic(_ReadWriteBarrier) |
| 57 | + |
| 58 | ++#ifdef _M_ARM64 |
| 59 | ++ |
| 60 | ++/* _ReadWriteBarrier() is insufficient on non-TSO architectures. */ |
| 61 | ++#pragma intrinsic(_InterlockedExchange) |
| 62 | ++#define S_UNLOCK(lock) _InterlockedExchange(lock, 0) |
| 63 | ++ |
| 64 | ++#else |
| 65 | ++ |
| 66 | ++#pragma intrinsic(_ReadWriteBarrier) |
| 67 | + #define S_UNLOCK(lock) \ |
| 68 | + do { _ReadWriteBarrier(); (*(lock)) = 0; } while (0) |
| 69 | + |
| 70 | + #endif |
| 71 | ++#endif |
| 72 | + |
| 73 | + |
| 74 | + #endif /* !defined(HAS_TEST_AND_SET) */ |
| 75 | +diff --git a/src/port/pg_crc32c_armv8.c b/src/port/pg_crc32c_armv8.c |
| 76 | +index d47d838..e48ae2c 100644 |
| 77 | +--- a/src/port/pg_crc32c_armv8.c |
| 78 | ++++ b/src/port/pg_crc32c_armv8.c |
| 79 | +@@ -14,7 +14,11 @@ |
| 80 | + */ |
| 81 | + #include "c.h" |
| 82 | + |
| 83 | ++#ifdef _MSC_VER |
| 84 | ++#include <intrin.h> |
| 85 | ++#else |
| 86 | + #include <arm_acle.h> |
| 87 | ++#endif |
| 88 | + |
| 89 | + #include "port/pg_crc32c.h" |
| 90 | + |
| 91 | +diff --git a/src/tools/msvc_gendef.pl b/src/tools/msvc_gendef.pl |
| 92 | +index 404076d..18f1f72 100644 |
| 93 | +--- a/src/tools/msvc_gendef.pl |
| 94 | ++++ b/src/tools/msvc_gendef.pl |
| 95 | +@@ -120,9 +120,9 @@ sub writedef |
| 96 | + { |
| 97 | + my $isdata = $def->{$f} eq 'data'; |
| 98 | + |
| 99 | +- # Strip the leading underscore for win32, but not x64 |
| 100 | ++ # Strip the leading underscore for win32, but not x64 and aarch64 |
| 101 | + $f =~ s/^_// |
| 102 | +- unless ($arch eq "x86_64"); |
| 103 | ++ unless ($arch eq "x86_64" || $arch eq "aarch64"); |
| 104 | + |
| 105 | + # Emit just the name if it's a function symbol, or emit the name |
| 106 | + # decorated with the DATA option for variables. |
| 107 | +@@ -143,7 +143,7 @@ sub writedef |
| 108 | + sub usage |
| 109 | + { |
| 110 | + die("Usage: msvc_gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files-or-directories\n" |
| 111 | +- . " arch: x86 | x86_64\n" |
| 112 | ++ . " arch: x86 | x86_64 | aarch64\n" |
| 113 | + . " deffile: path of the generated file\n" |
| 114 | + . " tempdir: directory for temporary files\n" |
| 115 | + . " files or directories: object files or directory containing object files\n" |
| 116 | +@@ -160,7 +160,7 @@ GetOptions( |
| 117 | + 'tempdir:s' => \$tempdir,) or usage(); |
| 118 | + |
| 119 | + usage("arch: $arch") |
| 120 | +- unless ($arch eq 'x86' || $arch eq 'x86_64'); |
| 121 | ++ unless ($arch eq 'x86' || $arch eq 'x86_64' || $arch eq 'aarch64'); |
| 122 | + |
| 123 | + my @files; |
| 124 | + |
0 commit comments