v1-0003-WIP-Attempt-alignment-preamble-better-suited-to-W.patch

application/x-patch

Filename: v1-0003-WIP-Attempt-alignment-preamble-better-suited-to-W.patch
Type: application/x-patch
Part: 2
Message: vectorized CRC on ARM64

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0003
Subject: WIP: Attempt alignment preamble better suited to WAL
File+
src/port/pg_crc32c_armv8.c 19 0
From a0aad5bf044170e6a8ceaf368fcfff68177cb9fb Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Wed, 14 May 2025 01:59:41 +0700
Subject: [PATCH v1 3/3] WIP: Attempt alignment preamble better suited to WAL

---
 src/port/pg_crc32c_armv8.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/port/pg_crc32c_armv8.c b/src/port/pg_crc32c_armv8.c
index f67de2016b4..da6116efa21 100644
--- a/src/port/pg_crc32c_armv8.c
+++ b/src/port/pg_crc32c_armv8.c
@@ -119,6 +119,24 @@ pg_comp_crc32c_pmull(pg_crc32c crc, const void *data, size_t len)
 	const char *buf = data;
 
 	/* Align to 16 bytes to prevent straddling cacheline boundaries. */
+#if 1
+
+	/*
+	 * WIP: WAL is 4-byte aligned, so in that case the the first loop will be skipped. Is this
+	 * better?
+	 */
+	for (; len && ((uintptr_t) buf & 3); --len)
+	{
+		crc0 = __crc32cb(crc0, *buf++);
+	}
+	if (((uintptr_t) buf & 12) && len >= 4)
+	{
+		crc0 = __crc32cw(crc0, *(const uint64_t *) buf);
+		buf += 4;
+		len -= 4;
+	}
+#else
+	/* original */
 	for (; len && ((uintptr_t) buf & 7); --len)
 	{
 		crc0 = __crc32cb(crc0, *buf++);
@@ -129,6 +147,7 @@ pg_comp_crc32c_pmull(pg_crc32c crc, const void *data, size_t len)
 		buf += 8;
 		len -= 8;
 	}
+#endif
 
 	if (len >= 64)
 	{
-- 
2.49.0