mirror of https://github.com/postgres/postgres
We now maintain an array of booleans that indicate which features were detected at runtime. When code wants to check for a given feature, the array is automatically checked if it has been initialized and if not, a single function checks all features at once. Move all x86 feature detection to pg_cpu_x86.c, and move the CRC function choosing logic to the file where the hardware-specific functions are defined, consistent with more recent hardware-specific files in src/port. Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com> Discussion: https://postgr.es/m/CANWCAZbgEUFw7LuYSVeJ=Tj98R5HoOB1Ffeqk3aLvbw5rU5NTw@mail.gmail.commaster
parent
d6d9b96b40
commit
16743db061
@ -0,0 +1,50 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_cpu.h |
||||
* Runtime CPU feature detection |
||||
* |
||||
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* src/include/port/pg_cpu.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_CPU_H |
||||
#define PG_CPU_H |
||||
|
||||
#if defined(USE_SSE2) || defined(__i386__) |
||||
|
||||
typedef enum X86FeatureId |
||||
{ |
||||
/* Have we run feature detection? */ |
||||
INIT_PG_X86, |
||||
|
||||
/* scalar registers and 128-bit XMM registers */ |
||||
PG_SSE4_2, |
||||
PG_POPCNT, |
||||
|
||||
/* 512-bit ZMM registers */ |
||||
PG_AVX512_BW, |
||||
PG_AVX512_VL, |
||||
PG_AVX512_VPCLMULQDQ, |
||||
PG_AVX512_VPOPCNTDQ, |
||||
} X86FeatureId; |
||||
#define X86FeaturesSize (PG_AVX512_VPOPCNTDQ + 1) |
||||
|
||||
extern PGDLLIMPORT bool X86Features[]; |
||||
|
||||
extern void set_x86_features(void); |
||||
|
||||
static inline bool |
||||
x86_feature_available(X86FeatureId feature) |
||||
{ |
||||
if (X86Features[INIT_PG_X86] == false) |
||||
set_x86_features(); |
||||
|
||||
return X86Features[feature]; |
||||
} |
||||
|
||||
#endif /* defined(USE_SSE2) || defined(__i386__) */ |
||||
|
||||
#endif /* PG_CPU_H */ |
||||
Loading…
Reference in new issue