summaryrefslogtreecommitdiff
path: root/src/include/port/simd.h
diff options
context:
space:
mode:
authorJohn Naylor2022-08-26 08:01:24 +0000
committerJohn Naylor2022-08-26 08:48:49 +0000
commit121d2d3d70ecdb2113b340c5f3b99a61341291af (patch)
tree2fb2e21869ca777cb79a3a9282f0e5096ca409f6 /src/include/port/simd.h
parentab9717847a2b0c32b93121f873f4dff331e26eb0 (diff)
Use SSE2 in is_valid_ascii() where available.
Per flame graph from Jelte Fennema, COPY FROM ... USING BINARY shows input validation taking at least 5% of the profile, so it's worth trying to be more efficient here. With this change, validation of pure ASCII is nearly 40% faster on contemporary Intel hardware. To make this change legible and easier to adopt to additional architectures, use helper functions to abstract the platform details away. Reviewed by Nathan Bossart Discussion: https://www.postgresql.org/message-id/CAFBsxsG%3Dk8t%3DC457FXnoBXb%3D8iA4OaZkbFogFMachWif7mNnww%40mail.gmail.com
Diffstat (limited to 'src/include/port/simd.h')
-rw-r--r--src/include/port/simd.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/include/port/simd.h b/src/include/port/simd.h
index 61e4362258b..a425cd887b1 100644
--- a/src/include/port/simd.h
+++ b/src/include/port/simd.h
@@ -52,7 +52,18 @@ static inline Vector8 vector8_broadcast(const uint8 c);
static inline bool vector8_has(const Vector8 v, const uint8 c);
static inline bool vector8_has_zero(const Vector8 v);
static inline bool vector8_has_le(const Vector8 v, const uint8 c);
+static inline bool vector8_is_highbit_set(const Vector8 v);
+/* arithmetic operations */
+static inline Vector8 vector8_or(const Vector8 v1, const Vector8 v2);
+
+/* Different semantics for SIMD architectures. */
+#ifndef USE_NO_SIMD
+
+/* comparisons between vectors */
+static inline Vector8 vector8_eq(const Vector8 v1, const Vector8 v2);
+
+#endif /* ! USE_NO_SIMD */
/*
* Load a chunk of memory into the given vector.
@@ -193,4 +204,48 @@ vector8_has_le(const Vector8 v, const uint8 c)
return result;
}
+/*
+ * Return true if the high bit of any element is set
+ */
+static inline bool
+vector8_is_highbit_set(const Vector8 v)
+{
+#ifdef USE_SSE2
+ return _mm_movemask_epi8(v) != 0;
+#else
+ return v & vector8_broadcast(0x80);
+#endif
+}
+
+/*
+ * Return the bitwise OR of the inputs
+ */
+static inline Vector8
+vector8_or(const Vector8 v1, const Vector8 v2)
+{
+#ifdef USE_SSE2
+ return _mm_or_si128(v1, v2);
+#else
+ return v1 | v2;
+#endif
+}
+
+
+/* Different semantics for SIMD architectures. */
+#ifndef USE_NO_SIMD
+
+/*
+ * Return a vector with all bits set in each lane where the the corresponding
+ * lanes in the inputs are equal.
+ */
+static inline Vector8
+vector8_eq(const Vector8 v1, const Vector8 v2)
+{
+#ifdef USE_SSE2
+ return _mm_cmpeq_epi8(v1, v2);
+#endif
+}
+
+#endif /* ! USE_NO_SIMD */
+
#endif /* SIMD_H */