v6-0004-Widen-the-ASCII-fast-path-stride-in-the-fallback-.patch

application/octet-stream

Filename: v6-0004-Widen-the-ASCII-fast-path-stride-in-the-fallback-.patch
Type: application/octet-stream
Part: 3
Message: Re: [POC] verifying UTF-8 using SIMD instructions

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 v6-0004
Subject: Widen the ASCII fast path stride in the fallback UTF-8 validator from 8 to 16 bytes.
File+
src/include/port/pg_utf8.h 8 6
From e08cc93238e647c8d13ecd6acaaa85ab7bca9ec2 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@2ndquadrant.com>
Date: Wed, 24 Feb 2021 11:52:58 -0400
Subject: [PATCH v6 4/4] Widen the ASCII fast path stride in the fallback UTF-8
 validator from 8 to 16 bytes.

---
 src/include/port/pg_utf8.h | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/include/port/pg_utf8.h b/src/include/port/pg_utf8.h
index a19fc55c1e..89132243b0 100644
--- a/src/include/port/pg_utf8.h
+++ b/src/include/port/pg_utf8.h
@@ -58,22 +58,24 @@ extern int	pg_validate_utf8_fallback(const unsigned char *s, int len);
 static inline int
 check_ascii(const unsigned char *s, int len)
 {
-	uint64		chunk,
+	uint64		half1,
+				half2,
 				highbits_set;
 
-	if (len >= sizeof(uint64))
+	if (len >= 2 * sizeof(uint64))
 	{
-		memcpy(&chunk, s, sizeof(uint64));
+		memcpy(&half1, s, sizeof(uint64));
+		memcpy(&half2, s + sizeof(uint64), sizeof(uint64));
 
 		/* If there are zero bytes, bail and let the slow path handle it. */
-		if (HAS_ZERO(chunk))
+		if (HAS_ZERO(half1) || HAS_ZERO(half2))
 			return 0;
 
 		/* Check if any bytes in this chunk have the high bit set. */
-		highbits_set = (chunk & UINT64CONST(0x8080808080808080));
+		highbits_set = ((half1 | half2) & UINT64CONST(0x8080808080808080));
 
 		if (!highbits_set)
-			return sizeof(uint64);
+			return 2 * sizeof(uint64);
 		else
 			return 0;
 	}
-- 
2.22.0