PostgreSQL Source Code  git master
test_lfind.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "port/pg_lfind.h"
Include dependency graph for test_lfind.c:

Go to the source code of this file.

Macros

#define LEN_NO_TAIL(vectortype)   (2 * sizeof(vectortype))
 
#define LEN_WITH_TAIL(vectortype)   (LEN_NO_TAIL(vectortype) + 3)
 
#define TEST_ARRAY_SIZE   135
 

Functions

static void test_lfind8_internal (uint8 key)
 
 PG_FUNCTION_INFO_V1 (test_lfind8)
 
Datum test_lfind8 (PG_FUNCTION_ARGS)
 
static void test_lfind8_le_internal (uint8 key)
 
 PG_FUNCTION_INFO_V1 (test_lfind8_le)
 
Datum test_lfind8_le (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_lfind32)
 
Datum test_lfind32 (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Macro Definition Documentation

◆ LEN_NO_TAIL

#define LEN_NO_TAIL (   vectortype)    (2 * sizeof(vectortype))

Definition at line 23 of file test_lfind.c.

◆ LEN_WITH_TAIL

#define LEN_WITH_TAIL (   vectortype)    (LEN_NO_TAIL(vectortype) + 3)

Definition at line 24 of file test_lfind.c.

◆ TEST_ARRAY_SIZE

#define TEST_ARRAY_SIZE   135

Function Documentation

◆ PG_FUNCTION_INFO_V1() [1/3]

PG_FUNCTION_INFO_V1 ( test_lfind32  )

◆ PG_FUNCTION_INFO_V1() [2/3]

PG_FUNCTION_INFO_V1 ( test_lfind8  )

◆ PG_FUNCTION_INFO_V1() [3/3]

PG_FUNCTION_INFO_V1 ( test_lfind8_le  )

◆ test_lfind32()

Datum test_lfind32 ( PG_FUNCTION_ARGS  )

Definition at line 120 of file test_lfind.c.

121 {
122 #define TEST_ARRAY_SIZE 135
123  uint32 test_array[TEST_ARRAY_SIZE] = {0};
124 
125  test_array[8] = 1;
126  test_array[64] = 2;
127  test_array[TEST_ARRAY_SIZE - 1] = 3;
128 
129  if (pg_lfind32(1, test_array, 4))
130  elog(ERROR, "pg_lfind32() found nonexistent element");
131  if (!pg_lfind32(1, test_array, TEST_ARRAY_SIZE))
132  elog(ERROR, "pg_lfind32() did not find existing element");
133 
134  if (pg_lfind32(2, test_array, 32))
135  elog(ERROR, "pg_lfind32() found nonexistent element");
136  if (!pg_lfind32(2, test_array, TEST_ARRAY_SIZE))
137  elog(ERROR, "pg_lfind32() did not find existing element");
138 
139  if (pg_lfind32(3, test_array, 96))
140  elog(ERROR, "pg_lfind32() found nonexistent element");
141  if (!pg_lfind32(3, test_array, TEST_ARRAY_SIZE))
142  elog(ERROR, "pg_lfind32() did not find existing element");
143 
144  if (pg_lfind32(4, test_array, TEST_ARRAY_SIZE))
145  elog(ERROR, "pg_lfind32() found nonexistent element");
146 
147  PG_RETURN_VOID();
148 }
unsigned int uint32
Definition: c.h:506
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define PG_RETURN_VOID()
Definition: fmgr.h:349
static bool pg_lfind32(uint32 key, const uint32 *base, uint32 nelem)
Definition: pg_lfind.h:153
#define TEST_ARRAY_SIZE

References elog, ERROR, pg_lfind32(), PG_RETURN_VOID, and TEST_ARRAY_SIZE.

◆ test_lfind8()

Datum test_lfind8 ( PG_FUNCTION_ARGS  )

Definition at line 59 of file test_lfind.c.

60 {
69 
71 }
static void test_lfind8_internal(uint8 key)
Definition: test_lfind.c:30

References PG_RETURN_VOID, and test_lfind8_internal().

◆ test_lfind8_internal()

static void test_lfind8_internal ( uint8  key)
static

Definition at line 30 of file test_lfind.c.

31 {
32  uint8 charbuf[LEN_WITH_TAIL(Vector8)];
33  const int len_no_tail = LEN_NO_TAIL(Vector8);
34  const int len_with_tail = LEN_WITH_TAIL(Vector8);
35 
36  memset(charbuf, 0xFF, len_with_tail);
37  /* search tail to test one-byte-at-a-time path */
38  charbuf[len_with_tail - 1] = key;
39  if (key > 0x00 && pg_lfind8(key - 1, charbuf, len_with_tail))
40  elog(ERROR, "pg_lfind8() found nonexistent element '0x%x'", key - 1);
41  if (key < 0xFF && !pg_lfind8(key, charbuf, len_with_tail))
42  elog(ERROR, "pg_lfind8() did not find existing element '0x%x'", key);
43  if (key < 0xFE && pg_lfind8(key + 1, charbuf, len_with_tail))
44  elog(ERROR, "pg_lfind8() found nonexistent element '0x%x'", key + 1);
45 
46  memset(charbuf, 0xFF, len_with_tail);
47  /* search with vector operations */
48  charbuf[len_no_tail - 1] = key;
49  if (key > 0x00 && pg_lfind8(key - 1, charbuf, len_no_tail))
50  elog(ERROR, "pg_lfind8() found nonexistent element '0x%x'", key - 1);
51  if (key < 0xFF && !pg_lfind8(key, charbuf, len_no_tail))
52  elog(ERROR, "pg_lfind8() did not find existing element '0x%x'", key);
53  if (key < 0xFE && pg_lfind8(key + 1, charbuf, len_no_tail))
54  elog(ERROR, "pg_lfind8() found nonexistent element '0x%x'", key + 1);
55 }
unsigned char uint8
Definition: c.h:504
static bool pg_lfind8(uint8 key, uint8 *base, uint32 nelem)
Definition: pg_lfind.h:26
uint64 Vector8
Definition: simd.h:60
#define LEN_NO_TAIL(vectortype)
Definition: test_lfind.c:23
#define LEN_WITH_TAIL(vectortype)
Definition: test_lfind.c:24

References elog, ERROR, sort-test::key, LEN_NO_TAIL, LEN_WITH_TAIL, and pg_lfind8().

Referenced by test_lfind8().

◆ test_lfind8_le()

Datum test_lfind8_le ( PG_FUNCTION_ARGS  )

Definition at line 104 of file test_lfind.c.

105 {
114 
115  PG_RETURN_VOID();
116 }
static void test_lfind8_le_internal(uint8 key)
Definition: test_lfind.c:75

References PG_RETURN_VOID, and test_lfind8_le_internal().

◆ test_lfind8_le_internal()

static void test_lfind8_le_internal ( uint8  key)
static

Definition at line 75 of file test_lfind.c.

76 {
77  uint8 charbuf[LEN_WITH_TAIL(Vector8)];
78  const int len_no_tail = LEN_NO_TAIL(Vector8);
79  const int len_with_tail = LEN_WITH_TAIL(Vector8);
80 
81  memset(charbuf, 0xFF, len_with_tail);
82  /* search tail to test one-byte-at-a-time path */
83  charbuf[len_with_tail - 1] = key;
84  if (key > 0x00 && pg_lfind8_le(key - 1, charbuf, len_with_tail))
85  elog(ERROR, "pg_lfind8_le() found nonexistent element <= '0x%x'", key - 1);
86  if (key < 0xFF && !pg_lfind8_le(key, charbuf, len_with_tail))
87  elog(ERROR, "pg_lfind8_le() did not find existing element <= '0x%x'", key);
88  if (key < 0xFE && !pg_lfind8_le(key + 1, charbuf, len_with_tail))
89  elog(ERROR, "pg_lfind8_le() did not find existing element <= '0x%x'", key + 1);
90 
91  memset(charbuf, 0xFF, len_with_tail);
92  /* search with vector operations */
93  charbuf[len_no_tail - 1] = key;
94  if (key > 0x00 && pg_lfind8_le(key - 1, charbuf, len_no_tail))
95  elog(ERROR, "pg_lfind8_le() found nonexistent element <= '0x%x'", key - 1);
96  if (key < 0xFF && !pg_lfind8_le(key, charbuf, len_no_tail))
97  elog(ERROR, "pg_lfind8_le() did not find existing element <= '0x%x'", key);
98  if (key < 0xFE && !pg_lfind8_le(key + 1, charbuf, len_no_tail))
99  elog(ERROR, "pg_lfind8_le() did not find existing element <= '0x%x'", key + 1);
100 }
static bool pg_lfind8_le(uint8 key, uint8 *base, uint32 nelem)
Definition: pg_lfind.h:58

References elog, ERROR, sort-test::key, LEN_NO_TAIL, LEN_WITH_TAIL, and pg_lfind8_le().

Referenced by test_lfind8_le().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 26 of file test_lfind.c.