PostgreSQL Source Code git master
Loading...
Searching...
No Matches
simd.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define USE_NO_SIMD
 

Typedefs

typedef uint64 Vector8
 

Functions

static void vector8_load (Vector8 *v, const uint8 *s)
 
static Vector8 vector8_broadcast (const uint8 c)
 
static bool vector8_has (const Vector8 v, const uint8 c)
 
static bool vector8_has_zero (const Vector8 v)
 
static bool vector8_has_le (const Vector8 v, const uint8 c)
 
static bool vector8_is_highbit_set (const Vector8 v)
 
static Vector8 vector8_or (const Vector8 v1, const Vector8 v2)
 

Macro Definition Documentation

◆ USE_NO_SIMD

#define USE_NO_SIMD

Definition at line 46 of file simd.h.

Typedef Documentation

◆ Vector8

Definition at line 47 of file simd.h.

Function Documentation

◆ vector8_broadcast()

static Vector8 vector8_broadcast ( const uint8  c)
inlinestatic

Definition at line 136 of file simd.h.

137{
138#if defined(USE_SSE2)
139 return _mm_set1_epi8(c);
140#elif defined(USE_NEON)
141 return vdupq_n_u8(c);
142#else
143 return ~UINT64CONST(0) / 0xFF * c;
144#endif
145}
char * c
static int fb(int x)

References fb().

Referenced by hex_encode(), is_valid_ascii(), RT_NODE_16_GET_INSERTPOS(), RT_NODE_16_SEARCH_EQ(), vector8_has(), vector8_has_le(), and vector8_is_highbit_set().

◆ vector8_has()

static bool vector8_has ( const Vector8  v,
const uint8  c 
)
inlinestatic

Definition at line 163 of file simd.h.

164{
165 bool result;
166
167 /* pre-compute the result for assert checking */
168#ifdef USE_ASSERT_CHECKING
169 bool assert_result = false;
170
171 for (Size i = 0; i < sizeof(Vector8); i++)
172 {
173 if (((const uint8 *) &v)[i] == c)
174 {
175 assert_result = true;
176 break;
177 }
178 }
179#endif /* USE_ASSERT_CHECKING */
180
181#if defined(USE_NO_SIMD)
182 /* any bytes in v equal to c will evaluate to zero via XOR */
183 result = vector8_has_zero(v ^ vector8_broadcast(c));
184#else
186#endif
187
188 Assert(assert_result == result);
189 return result;
190}
uint8_t uint8
Definition c.h:544
#define Assert(condition)
Definition c.h:873
size_t Size
Definition c.h:619
int i
Definition isn.c:77
static Vector8 vector8_broadcast(const uint8 c)
Definition simd.h:136
static bool vector8_has_zero(const Vector8 v)
Definition simd.h:196
uint64 Vector8
Definition simd.h:47
static bool vector8_is_highbit_set(const Vector8 v)
Definition simd.h:293

References Assert, fb(), i, vector8_broadcast(), vector8_has_zero(), and vector8_is_highbit_set().

Referenced by escape_json_with_len(), pg_lfind8(), and vector8_has_zero().

◆ vector8_has_le()

static bool vector8_has_le ( const Vector8  v,
const uint8  c 
)
inlinestatic

Definition at line 214 of file simd.h.

215{
216 bool result = false;
217#ifdef USE_SSE2
220#endif
221
222 /* pre-compute the result for assert checking */
223#ifdef USE_ASSERT_CHECKING
224 bool assert_result = false;
225
226 for (Size i = 0; i < sizeof(Vector8); i++)
227 {
228 if (((const uint8 *) &v)[i] <= c)
229 {
230 assert_result = true;
231 break;
232 }
233 }
234#endif /* USE_ASSERT_CHECKING */
235
236#if defined(USE_NO_SIMD)
237
238 /*
239 * To find bytes <= c, we can use bitwise operations to find bytes < c+1,
240 * but it only works if c+1 <= 128 and if the highest bit in v is not set.
241 * Adapted from
242 * https://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord
243 */
244 if ((int64) v >= 0 && c < 0x80)
245 result = (v - vector8_broadcast(c + 1)) & ~v & vector8_broadcast(0x80);
246 else
247 {
248 /* one byte at a time */
249 for (Size i = 0; i < sizeof(Vector8); i++)
250 {
251 if (((const uint8 *) &v)[i] <= c)
252 {
253 result = true;
254 break;
255 }
256 }
257 }
258#elif defined(USE_SSE2)
260 cmpe = vector8_eq(umin, v);
262#elif defined(USE_NEON)
263 result = vminvq_u8(v) <= c;
264#endif
265
266 Assert(assert_result == result);
267 return result;
268}
int64_t int64
Definition c.h:543

References Assert, fb(), i, vector8_broadcast(), and vector8_is_highbit_set().

Referenced by escape_json_with_len(), pg_lfind8_le(), and vector8_has_zero().

◆ vector8_has_zero()

static bool vector8_has_zero ( const Vector8  v)
inlinestatic

Definition at line 196 of file simd.h.

197{
198#if defined(USE_NO_SIMD)
199 /*
200 * We cannot call vector8_has() here, because that would lead to a
201 * circular definition.
202 */
203 return vector8_has_le(v, 0);
204#else
205 return vector8_has(v, 0);
206#endif
207}
static bool vector8_has_le(const Vector8 v, const uint8 c)
Definition simd.h:214
static bool vector8_has(const Vector8 v, const uint8 c)
Definition simd.h:163

References vector8_has(), and vector8_has_le().

Referenced by vector8_has().

◆ vector8_is_highbit_set()

static bool vector8_is_highbit_set ( const Vector8  v)
inlinestatic

Definition at line 293 of file simd.h.

294{
295#ifdef USE_SSE2
296 return _mm_movemask_epi8(v) != 0;
297#elif defined(USE_NEON)
298 return vmaxvq_u8(v) > 0x7F;
299#else
300 return v & vector8_broadcast(0x80);
301#endif
302}

References fb(), and vector8_broadcast().

Referenced by is_valid_ascii(), vector8_has(), and vector8_has_le().

◆ vector8_load()

static void vector8_load ( Vector8 v,
const uint8 s 
)
inlinestatic

Definition at line 94 of file simd.h.

95{
96#if defined(USE_SSE2)
97 *v = _mm_loadu_si128((const __m128i *) s);
98#elif defined(USE_NEON)
99 *v = vld1q_u8(s);
100#else
101 memcpy(v, s, sizeof(Vector8));
102#endif
103}

References fb().

Referenced by escape_json_with_len(), hex_decode_safe(), hex_encode(), is_valid_ascii(), pg_lfind8(), pg_lfind8_le(), RT_NODE_16_GET_INSERTPOS(), and RT_NODE_16_SEARCH_EQ().

◆ vector8_or()

static Vector8 vector8_or ( const Vector8  v1,
const Vector8  v2 
)
inlinestatic

Definition at line 360 of file simd.h.

361{
362#ifdef USE_SSE2
363 return _mm_or_si128(v1, v2);
364#elif defined(USE_NEON)
365 return vorrq_u8(v1, v2);
366#else
367 return v1 | v2;
368#endif
369}

References fb().

Referenced by is_valid_ascii().