Fix broken cast on MSVC
authorJohn Naylor <[email protected]>
Mon, 29 Aug 2022 10:25:59 +0000 (17:25 +0700)
committerJohn Naylor <[email protected]>
Mon, 29 Aug 2022 10:44:35 +0000 (17:44 +0700)
Per buildfarm animal drongo, casting a vector type to the same type
causes a compile error. We still need the cast on ARM64, so invent a
wrapper function that does the casting only where necessary.

Discussion: https://www.postgresql.org/message-id/CAFBsxsEouaTwbmpqV%2BEW2%3DwFbhw2vHRe26NQTRcd0%3DNaOFDy7A%40mail.gmail.com

src/include/port/pg_lfind.h
src/include/port/simd.h

index d575e733d34115259621cc484b391f7688e4edc5..0625cac6b59be71a2161e0e5e30ddfb3d8d9e088 100644 (file)
@@ -151,7 +151,7 @@ pg_lfind32(uint32 key, uint32 *base, uint32 nelem)
        result = vector32_or(tmp1, tmp2);
 
        /* see if there was a match */
-       if (vector8_is_highbit_set((Vector8) result))
+       if (vector32_is_highbit_set(result))
        {
            Assert(assert_result == true);
            return true;
index b538ac070f7d421b3785373349f700fcd9e9b5b8..0ff1549083af245df264a437de73ac771b7ea681 100644 (file)
@@ -274,6 +274,28 @@ vector8_is_highbit_set(const Vector8 v)
 #endif
 }
 
+/*
+ * Exactly like vector32_is_highbit_set except for the input type, so it
+ * looks at each byte separately.
+ *
+ * XXX x86 uses the same underlying type for 8-bit, 16-bit, and 32-bit
+ * integer elements, but Arm does not, hence the need for a separate
+ * function. We could instead adopt the behavior of Arm's vmaxvq_u32(), i.e.
+ * check each 32-bit element, but that would require an additional mask
+ * operation on x86.
+ */
+#ifndef USE_NO_SIMD
+static inline bool
+vector32_is_highbit_set(const Vector32 v)
+{
+#if defined(USE_NEON)
+   return vector8_is_highbit_set((Vector8) v);
+#else
+   return vector8_is_highbit_set(v);
+#endif
+}
+#endif                         /* ! USE_NO_SIMD */
+
 /*
  * Return the bitwise OR of the inputs
  */