Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6a43c2

Browse files
committed
Fix broken cast on MSVC
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
1 parent 82739d4 commit c6a43c2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/include/port/pg_lfind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pg_lfind32(uint32 key, uint32 *base, uint32 nelem)
151151
result = vector32_or(tmp1, tmp2);
152152

153153
/* see if there was a match */
154-
if (vector8_is_highbit_set((Vector8) result))
154+
if (vector32_is_highbit_set(result))
155155
{
156156
Assert(assert_result == true);
157157
return true;

src/include/port/simd.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,28 @@ vector8_is_highbit_set(const Vector8 v)
274274
#endif
275275
}
276276

277+
/*
278+
* Exactly like vector32_is_highbit_set except for the input type, so it
279+
* looks at each byte separately.
280+
*
281+
* XXX x86 uses the same underlying type for 8-bit, 16-bit, and 32-bit
282+
* integer elements, but Arm does not, hence the need for a separate
283+
* function. We could instead adopt the behavior of Arm's vmaxvq_u32(), i.e.
284+
* check each 32-bit element, but that would require an additional mask
285+
* operation on x86.
286+
*/
287+
#ifndef USE_NO_SIMD
288+
static inline bool
289+
vector32_is_highbit_set(const Vector32 v)
290+
{
291+
#if defined(USE_NEON)
292+
return vector8_is_highbit_set((Vector8) v);
293+
#else
294+
return vector8_is_highbit_set(v);
295+
#endif
296+
}
297+
#endif /* ! USE_NO_SIMD */
298+
277299
/*
278300
* Return the bitwise OR of the inputs
279301
*/

0 commit comments

Comments
 (0)