Skip to content

Commit

Permalink
lib: [cpu feature] XSAVE feature detection and check to fix issue #153
Browse files Browse the repository at this point in the history
This code change adds XSAVE feature detection and makes AVX architecture depend on it.
Note that AVX2 and AVX512 architectures also depend on all AVX features and consequently depend on XSAVE feature, too.
  • Loading branch information
tkanteck committed Jul 17, 2024
1 parent 203d23f commit a3a08f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/intel-ipsec-mb.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ typedef int (*imb_self_test_cb_t)(void *cb_arg, const IMB_SELF_TEST_CALLBACK_DAT
#define IMB_FEATURE_SM3NI (1ULL << 24)
#define IMB_FEATURE_SM4NI (1ULL << 25)
#define IMB_FEATURE_SHA512NI (1ULL << 26)
#define IMB_FEATURE_XSAVE (1ULL << 27)

/**
* Self test defines
Expand All @@ -937,7 +938,7 @@ typedef int (*imb_self_test_cb_t)(void *cb_arg, const IMB_SELF_TEST_CALLBACK_DAT
#define IMB_CPUFLAGS_SSE (IMB_CPUFLAGS_NO_AESNI | IMB_FEATURE_AESNI | IMB_FEATURE_PCLMULQDQ)
#define IMB_CPUFLAGS_SSE_T2 (IMB_CPUFLAGS_SSE | IMB_FEATURE_SHANI)
#define IMB_CPUFLAGS_SSE_T3 (IMB_CPUFLAGS_SSE_T2 | IMB_FEATURE_GFNI)
#define IMB_CPUFLAGS_AVX (IMB_CPUFLAGS_SSE | IMB_FEATURE_AVX)
#define IMB_CPUFLAGS_AVX (IMB_CPUFLAGS_SSE | IMB_FEATURE_AVX | IMB_FEATURE_XSAVE)
#define IMB_CPUFLAGS_AVX2 (IMB_CPUFLAGS_AVX | IMB_FEATURE_AVX2 | IMB_FEATURE_BMI2)
#define IMB_CPUFLAGS_AVX512 (IMB_CPUFLAGS_AVX2 | IMB_FEATURE_AVX512_SKX)
#define IMB_CPUFLAGS_AVX512_T2 \
Expand Down
10 changes: 9 additions & 1 deletion lib/x86_64/cpu_feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ detect_sm4ni(void)
#endif
}

static uint32_t
detect_xsave(void)
{
/* Check presence of XSAVE - bit 26 of ECX */
return (cpuid_1_0.ecx & (1UL << 26));
}

uint64_t
cpu_feature_detect(void)
{
Expand Down Expand Up @@ -249,7 +256,8 @@ cpu_feature_detect(void)
{ 7, IMB_FEATURE_HYBRID, detect_hybrid },
{ 7, IMB_FEATURE_SM3NI, detect_sm3ni },
{ 7, IMB_FEATURE_SM4NI, detect_sm4ni },
{ 7, IMB_FEATURE_SHA512NI, detect_sha512ni } };
{ 7, IMB_FEATURE_SHA512NI, detect_sha512ni },
{ 1, IMB_FEATURE_XSAVE, detect_xsave } };
struct cpuid_regs r;
unsigned hi_leaf_number = 0;
uint64_t features = 0;
Expand Down

0 comments on commit a3a08f0

Please sign in to comment.