v3-0001-Enable-postgres-native-build-for-windows-arm64-pl.patch
application/octet-stream
Filename: v3-0001-Enable-postgres-native-build-for-windows-arm64-pl.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch v3-0001
Subject: Enable postgres native build for windows-arm64 platform
| File | + | − |
|---|---|---|
| src/include/storage/s_lock.h | 9 | 1 |
| src/port/pg_crc32c_armv8.c | 2 | 0 |
| src/tools/msvc/gendef.pl | 4 | 4 |
| src/tools/msvc/Mkvcbuild.pm | 7 | 2 |
| src/tools/msvc/MSBuildProject.pm | 12 | 4 |
| src/tools/msvc/Solution.pm | 7 | 2 |
From db7b0def74f4cbd525fd77b96971c523cdf82035 Mon Sep 17 00:00:00 2001
From: Niyas Sait <niyas.sait@linaro.org>
Date: Tue, 22 Feb 2022 13:07:24 +0000
Subject: [PATCH v3] Enable postgres native build for windows-arm64 platform
Following changes are included
- Extend MSVC scripts to handle ARM64 platform
- Add arm64 definition of spin_delay function
- Exclude arm_acle.h import for MSVC
---
src/include/storage/s_lock.h | 10 +++++++++-
src/port/pg_crc32c_armv8.c | 2 ++
src/tools/msvc/MSBuildProject.pm | 16 ++++++++++++----
src/tools/msvc/Mkvcbuild.pm | 9 +++++++--
src/tools/msvc/Solution.pm | 9 +++++++--
src/tools/msvc/gendef.pl | 8 ++++----
6 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 8b19ab160f..bf6a6dba35 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -708,13 +708,21 @@ typedef LONG slock_t;
#define SPIN_DELAY() spin_delay()
/* If using Visual C++ on Win64, inline assembly is unavailable.
- * Use a _mm_pause intrinsic instead of rep nop.
+ * Use _mm_pause (x64) or __isb(arm64) intrinsic instead of rep nop.
*/
#if defined(_WIN64)
static __forceinline void
spin_delay(void)
{
+#ifdef _M_ARM64
+ /*
+ * arm64 way of hinting processor for spin loops optimisations
+ * ref: https://community.arm.com/support-forums/f/infrastructure-solutions-forum/48654/ssetoneon-faq
+ */
+ __isb(_ARM64_BARRIER_SY);
+#else
_mm_pause();
+#endif
}
#else
static __forceinline void
diff --git a/src/port/pg_crc32c_armv8.c b/src/port/pg_crc32c_armv8.c
index 9e301f96f6..981718752f 100644
--- a/src/port/pg_crc32c_armv8.c
+++ b/src/port/pg_crc32c_armv8.c
@@ -14,7 +14,9 @@
*/
#include "c.h"
+#ifndef _MSC_VER
#include <arm_acle.h>
+#endif
#include "port/pg_crc32c.h"
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 58590fdac2..caf390d982 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -310,10 +310,18 @@ sub WriteItemDefinitionGroup
: ($self->{type} eq "dll" ? 'DynamicLibrary' : 'StaticLibrary');
my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ';');
- my $targetmachine =
- $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
- my $arch =
- $self->{platform} eq 'Win32' ? 'x86' : 'x86_64';
+ my $targetmachine;
+ my $arch;
+ if ($self->{platform} eq 'Win32') {
+ $targetmachine = 'MachineX86';
+ $arch = 'x86';
+ } elsif ($self->{platform} eq 'ARM64'){
+ $targetmachine = 'MachineARM64';
+ $arch = 'arm64';
+ } else {
+ $targetmachine = 'MachineX64';
+ $arch = 'x86_64';
+ }
my $includes = join ';', @{ $self->{includes} }, "";
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 83a3e40425..71baed26e9 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -123,8 +123,13 @@ sub mkvcbuild
if ($vsVersion >= '9.00')
{
- push(@pgportfiles, 'pg_crc32c_sse42_choose.c');
- push(@pgportfiles, 'pg_crc32c_sse42.c');
+ if ($solution->{platform} eq 'ARM64') {
+ push(@pgportfiles, 'pg_crc32c_armv8_choose.c');
+ push(@pgportfiles, 'pg_crc32c_armv8.c');
+ } else {
+ push(@pgportfiles, 'pg_crc32c_sse42_choose.c');
+ push(@pgportfiles, 'pg_crc32c_sse42.c');
+ }
push(@pgportfiles, 'pg_crc32c_sb8.c');
}
else
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index c2acb58df0..e3fa0f968e 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -67,8 +67,13 @@ sub DeterminePlatform
# Examine CL help output to determine if we are in 32 or 64-bit mode.
my $output = `cl /help 2>&1`;
$? >> 8 == 0 or die "cl command not found";
- $self->{platform} =
- ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
+ if ($output =~ /^\/favor:<.+AMD64/m) {
+ $self->{platform} = 'x64';
+ } elsif($output =~ /for ARM64$/m) {
+ $self->{platform} = 'ARM64';
+ } else {
+ $self->{platform} = 'Win32';
+ }
}
else
{
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index d6bed1ce15..f1e0ff446b 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -120,9 +120,9 @@ sub writedef
{
my $isdata = $def->{$f} eq 'data';
- # Strip the leading underscore for win32, but not x64
+ # Strip the leading underscore for win32, but not x64 and arm64
$f =~ s/^_//
- unless ($arch eq "x86_64");
+ unless ($arch ne "x86");
# Emit just the name if it's a function symbol, or emit the name
# decorated with the DATA option for variables.
@@ -143,7 +143,7 @@ sub writedef
sub usage
{
die("Usage: gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files-or-directories\n"
- . " arch: x86 | x86_64\n"
+ . " arch: x86 | x86_64 | arm64 \n"
. " deffile: path of the generated file\n"
. " tempdir: directory for temporary files\n"
. " files or directories: object files or directory containing object files\n"
@@ -160,7 +160,7 @@ GetOptions(
'tempdir:s' => \$tempdir,) or usage();
usage("arch: $arch")
- unless ($arch eq 'x86' || $arch eq 'x86_64');
+ unless ($arch eq 'x86' || $arch eq 'x86_64' || $arch eq 'arm64');
my @files;
--
2.38.1