PostgreSQL Source Code git master
Macros | Typedefs | Functions
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 59 of file simd.h.

Typedef Documentation

Vector8

typedef uint64 Vector8

Definition at line 60 of file simd.h.

Function Documentation

vector8_broadcast()

static Vector8 vector8_broadcast ( const uint8  c )
inlinestatic

Definition at line 134 of file simd.h.

135{
136#if defined(USE_SSE2)
137 return _mm_set1_epi8(c);
138#elif defined(USE_NEON)
139 return vdupq_n_u8(c);
140#else
141 return ~UINT64CONST(0) / 0xFF * c;
142#endif
143}
c
char * c
Definition: preproc-cursor.c:31

Referenced by 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 161 of file simd.h.

162{
163 bool result;
164
165 /* pre-compute the result for assert checking */
166#ifdef USE_ASSERT_CHECKING
167 bool assert_result = false;
168
169 for (Size i = 0; i < sizeof(Vector8); i++)
170 {
171 if (((const uint8 *) &v)[i] == c)
172 {
173 assert_result = true;
174 break;
175 }
176 }
177#endif /* USE_ASSERT_CHECKING */
178
179#if defined(USE_NO_SIMD)
180 /* any bytes in v equal to c will evaluate to zero via XOR */
181 result = vector8_has_zero(v ^ vector8_broadcast(c));
182#else
183 result = vector8_is_highbit_set(vector8_eq(v, vector8_broadcast(c)));
184#endif
185
186 Assert(assert_result == result);
187 return result;
188}
uint8_t uint8
Definition: c.h:536
size_t Size
Definition: c.h:610
Assert(PointerIsAligned(start, uint64))
i
int i
Definition: isn.c:77
static Vector8 vector8_broadcast(const uint8 c)
Definition: simd.h:134
static bool vector8_has_zero(const Vector8 v)
Definition: simd.h:194
uint64 Vector8
Definition: simd.h:60
static bool vector8_is_highbit_set(const Vector8 v)
Definition: simd.h:272

References Assert(), 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 212 of file simd.h.

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

References Assert(), 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 194 of file simd.h.

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

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 272 of file simd.h.

273{
274#ifdef USE_SSE2
275 return _mm_movemask_epi8(v) != 0;
276#elif defined(USE_NEON)
277 return vmaxvq_u8(v) > 0x7F;
278#else
279 return v & vector8_broadcast(0x80);
280#endif
281}

References vector8_broadcast().

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

vector8_load()

static void vector8_load ( Vector8v,
const uint8s 
)
inlinestatic

Definition at line 107 of file simd.h.

108{
109#if defined(USE_SSE2)
110 *v = _mm_loadu_si128((const __m128i *) s);
111#elif defined(USE_NEON)
112 *v = vld1q_u8(s);
113#else
114 memcpy(v, s, sizeof(Vector8));
115#endif
116}

Referenced by escape_json_with_len(), 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 339 of file simd.h.

340{
341#ifdef USE_SSE2
342 return _mm_or_si128(v1, v2);
343#elif defined(USE_NEON)
344 return vorrq_u8(v1, v2);
345#else
346 return v1 | v2;
347#endif
348}

Referenced by is_valid_ascii().

AltStyle によって変換されたページ (->オリジナル) /