From 58d1b495afc0791b6ab4dfaa421cee2bc09d5359 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Thu, 19 Feb 2026 15:04:35 +0700
Subject: [PATCH v4 5/6] Rename CRC Arm-v8 "choose" file for future general
 purpose

---
 configure                                             | 2 +-
 configure.ac                                          | 2 +-
 src/port/Makefile                                     | 1 +
 src/port/meson.build                                  | 1 +
 src/port/{pg_crc32c_armv8_choose.c => pg_cpu_armv8.c} | 8 ++++++--
 5 files changed, 10 insertions(+), 4 deletions(-)
 rename src/port/{pg_crc32c_armv8_choose.c => pg_cpu_armv8.c} (95%)

diff --git a/configure b/configure
index 2d2c6308005..ec76278f9c1 100755
--- a/configure
+++ b/configure
@@ -18266,7 +18266,7 @@ $as_echo "ARMv8 CRC instructions" >&6; }
 
 $as_echo "#define USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK 1" >>confdefs.h
 
-        PG_CRC32C_OBJS="pg_crc32c_armv8.o pg_crc32c_sb8.o pg_crc32c_armv8_choose.o"
+        PG_CRC32C_OBJS="pg_crc32c_armv8.o pg_crc32c_sb8.o"
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: ARMv8 CRC instructions with runtime check" >&5
 $as_echo "ARMv8 CRC instructions with runtime check" >&6; }
       else
diff --git a/configure.ac b/configure.ac
index 0b4c3970b68..5a3971bad63 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2269,7 +2269,7 @@ else
     else
       if test x"$USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK" = x"1"; then
         AC_DEFINE(USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK, 1, [Define to 1 to use ARMv8 CRC Extension with a runtime check.])
-        PG_CRC32C_OBJS="pg_crc32c_armv8.o pg_crc32c_sb8.o pg_crc32c_armv8_choose.o"
+        PG_CRC32C_OBJS="pg_crc32c_armv8.o pg_crc32c_sb8.o"
         AC_MSG_RESULT(ARMv8 CRC instructions with runtime check)
       else
         if test x"$USE_LOONGARCH_CRC32C" = x"1"; then
diff --git a/src/port/Makefile b/src/port/Makefile
index 47cfea1507d..4ed7e1902fb 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -44,6 +44,7 @@ OBJS = \
 	noblock.o \
 	path.o \
 	pg_bitutils.o \
+	pg_cpu_armv8.o \
 	pg_cpu_x86.o \
 	pg_localeconv_r.o \
 	pg_numa.o \
diff --git a/src/port/meson.build b/src/port/meson.build
index edb2e5632bd..0b26218be7a 100644
--- a/src/port/meson.build
+++ b/src/port/meson.build
@@ -7,6 +7,7 @@ pgport_sources = [
   'noblock.c',
   'path.c',
   'pg_bitutils.c',
+  'pg_cpu_armv8.c',
   'pg_cpu_x86.c',
   'pg_localeconv_r.c',
   'pg_numa.c',
diff --git a/src/port/pg_crc32c_armv8_choose.c b/src/port/pg_cpu_armv8.c
similarity index 95%
rename from src/port/pg_crc32c_armv8_choose.c
rename to src/port/pg_cpu_armv8.c
index a1f0e540c6b..6c22704b5fa 100644
--- a/src/port/pg_crc32c_armv8_choose.c
+++ b/src/port/pg_cpu_armv8.c
@@ -1,6 +1,6 @@
 /*-------------------------------------------------------------------------
  *
- * pg_crc32c_armv8_choose.c
+ * pg_cpu_armv8.c
  *	  Choose between ARMv8 and software CRC-32C implementation.
  *
  * On first call, checks if the CPU we're running on supports the ARMv8
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *	  src/port/pg_crc32c_armv8_choose.c
+ *	  src/port/pg_cpu_armv8.c
  *
  *-------------------------------------------------------------------------
  */
@@ -24,6 +24,8 @@
 #include "postgres_fe.h"
 #endif
 
+#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
+
 #if defined(HAVE_ELF_AUX_INFO) || defined(HAVE_GETAUXVAL)
 #include <sys/auxv.h>
 /* Ancient glibc releases don't include the HWCAPxxx macros in sys/auxv.h */
@@ -124,3 +126,5 @@ pg_comp_crc32c_choose(pg_crc32c crc, const void *data, size_t len)
 }
 
 pg_crc32c	(*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len) = pg_comp_crc32c_choose;
+
+#endif      /* __arm__ || __arm || __aarch64__ */
-- 
2.53.0

