diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c index 7ba92c2c481..eb932d4bd8a 100644 --- a/src/backend/utils/adt/encode.c +++ b/src/backend/utils/adt/encode.c @@ -317,6 +317,9 @@ static inline bool hex_decode_simd_helper(const Vector8 src, Vector8 *dst) { Vector8 sub; + // TODO: set one and use bitwise NOT for the other + Vector8 maskupper = vector8_set(0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0); + Vector8 masklower = vector8_set(0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, 0xff); Vector8 msk; bool ret; @@ -334,9 +337,9 @@ hex_decode_simd_helper(const Vector8 src, Vector8 *dst) *dst = vector8_issub(src, sub); ret = !vector8_has_ge(*dst, 0x10); - msk = vector8_and(*dst, vector8_broadcast_u32(0xff00ff00)); + msk = vector8_and(*dst, masklower); msk = vector8_shift_right_byte(msk); - *dst = vector8_and(*dst, vector8_broadcast_u32(0x00ff00ff)); + *dst = vector8_and(*dst, maskupper); *dst = vector8_shift_left_nibble(*dst); *dst = vector8_or(*dst, msk); return ret; diff --git a/src/include/port/simd.h b/src/include/port/simd.h index 531d8b8b6d1..56e810ce081 100644 --- a/src/include/port/simd.h +++ b/src/include/port/simd.h @@ -101,6 +101,33 @@ static inline Vector8 vector8_min(const Vector8 v1, const Vector8 v2); static inline Vector32 vector32_eq(const Vector32 v1, const Vector32 v2); #endif +/* + * Populate a vector element-wise with the arguments. + */ +#ifndef USE_NO_SIMD +#if defined(USE_NEON) +// from a patch by Thomas Munro +static inline Vector8 +vector8_set(uint8 v0, uint8 v1, uint8 v2, uint8 v3, + uint8 v4, uint8 v5, uint8 v6, uint8 v7, + uint8 v8, uint8 v9, uint8 v10, uint8 v11, + uint8 v12, uint8 v13, uint8 v14, uint8 v15) +{ + uint8 pg_attribute_aligned(16) values[16] = { + v0, v1, v2, v3, + v4, v5, v6, v7, + v8, v9, v10, v11, + v12, v13, v14, v15 + }; + return vld1q_u8(values); +} +#elif defined(USE_SSE2) +#ifndef vector8_set +#define vector8_set(...) _mm_setr_epi8(__VA_ARGS__) +#endif +#endif +#endif /* ! USE_NO_SIMD */ + /* * Load a chunk of memory into the given vector. */ @@ -368,6 +395,7 @@ vector8_highbit_mask(const Vector8 v) * returns a uint64, making it inconvenient to combine mask values from * multiple vectors. */ + // TODO: use vector8_set static const uint8 mask[16] = { 1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7,