PostgreSQL Source Code  git master
pg_crc32c_armv8_choose.c File Reference
#include "postgres.h"
#include <setjmp.h>
#include <signal.h>
#include "port/pg_crc32c.h"
Include dependency graph for pg_crc32c_armv8_choose.c:

Go to the source code of this file.

Functions

static void illegal_instruction_handler (SIGNAL_ARGS)
 
static bool pg_crc32c_armv8_available (void)
 
static pg_crc32c pg_comp_crc32c_choose (pg_crc32c crc, const void *data, size_t len)
 

Variables

static sigjmp_buf illegal_instruction_jump
 
pg_crc32c(* pg_comp_crc32c )(pg_crc32c crc, const void *data, size_t len) = pg_comp_crc32c_choose
 

Function Documentation

◆ illegal_instruction_handler()

static void illegal_instruction_handler ( SIGNAL_ARGS  )
static

Definition at line 40 of file pg_crc32c_armv8_choose.c.

References illegal_instruction_jump.

Referenced by pg_crc32c_armv8_available().

41 {
42  siglongjmp(illegal_instruction_jump, 1);
43 }
static sigjmp_buf illegal_instruction_jump

◆ pg_comp_crc32c_choose()

static pg_crc32c pg_comp_crc32c_choose ( pg_crc32c  crc,
const void *  data,
size_t  len 
)
static

Definition at line 85 of file pg_crc32c_armv8_choose.c.

References pg_comp_crc32c, pg_comp_crc32c_armv8(), pg_comp_crc32c_sb8(), and pg_crc32c_armv8_available().

86 {
89  else
91 
92  return pg_comp_crc32c(crc, data, len);
93 }
static bool pg_crc32c_armv8_available(void)
pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len)
Definition: pg_crc32c_sb8.c:35
pg_crc32c(* pg_comp_crc32c)(pg_crc32c crc, const void *data, size_t len)
pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)

◆ pg_crc32c_armv8_available()

static bool pg_crc32c_armv8_available ( void  )
static

Definition at line 46 of file pg_crc32c_armv8_choose.c.

References DEBUG1, elog, ERROR, illegal_instruction_handler(), illegal_instruction_jump, pg_comp_crc32c_armv8(), pg_comp_crc32c_sb8(), pqsignal(), and SIG_DFL.

Referenced by pg_comp_crc32c_choose().

47 {
48  uint64 data = 42;
49  int result;
50 
51  /*
52  * Be careful not to do anything that might throw an error while we have
53  * the SIGILL handler set to a nonstandard value.
54  */
56  if (sigsetjmp(illegal_instruction_jump, 1) == 0)
57  {
58  /* Rather than hard-wiring an expected result, compare to SB8 code */
59  result = (pg_comp_crc32c_armv8(0, &data, sizeof(data)) ==
60  pg_comp_crc32c_sb8(0, &data, sizeof(data)));
61  }
62  else
63  {
64  /* We got the SIGILL trap */
65  result = -1;
66  }
67  pqsignal(SIGILL, SIG_DFL);
68 
69 #ifndef FRONTEND
70  /* We don't expect this case, so complain loudly */
71  if (result == 0)
72  elog(ERROR, "crc32 hardware and software results disagree");
73 
74  elog(DEBUG1, "using armv8 crc32 hardware = %d", (result > 0));
75 #endif
76 
77  return (result > 0);
78 }
#define DEBUG1
Definition: elog.h:25
pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len)
Definition: pg_crc32c_sb8.c:35
static sigjmp_buf illegal_instruction_jump
#define ERROR
Definition: elog.h:43
pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
#define SIG_DFL
Definition: win32_port.h:148
#define elog(elevel,...)
Definition: elog.h:228
static void illegal_instruction_handler(SIGNAL_ARGS)

Variable Documentation

◆ illegal_instruction_jump

sigjmp_buf illegal_instruction_jump
static

◆ pg_comp_crc32c

pg_crc32c(* pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len) = pg_comp_crc32c_choose

Definition at line 95 of file pg_crc32c_armv8_choose.c.

Referenced by pg_comp_crc32c_choose().