add simd id and cpu id

This commit is contained in:
Youmu Liu
2026-01-06 18:04:17 +08:00
parent 88fa653323
commit 3d488abd2e
17 changed files with 372 additions and 615 deletions
+14 -10
View File
@@ -56,7 +56,7 @@ static int xgetbv_has_avx512_state(void)
return ((xcr0 & mask) == mask);
}
static int is_intel_glue_avx512(int family, int model)
static int is_intel_dual_avx512(int family, int model)
{
return (family == 6) && (model == 0x55); /* SKX/CLX/CPX */
}
@@ -104,6 +104,7 @@ SN_API SIMDID SN_DECL sn_get_simd_level()
int has_avx = (ecx & (1 << 28)) != 0;
int has_osxsave = (ecx & (1 << 27)) != 0;
int has_fma = (ecx & (1 << 12)) != 0;
int has_f16c = (ecx & (1 << 29)) != 0;
uint64_t root = SIMDID_PACK_ROOT(SIMDID_ROOT_X86_64);
uint64_t manu = SIMDID_PACK_MANU(is_intel ? SIMDID_MANU_INTEL :
@@ -112,12 +113,15 @@ SN_API SIMDID SN_DECL sn_get_simd_level()
uint64_t main_lvl = SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_NONE);
uint64_t avx512_bits = 0;
uint64_t amx_bits = 0;
uint64_t avx_bits = 0;
/* Baseline main level */
if (has_sse42)
main_lvl = SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_SSE);
if (has_avx && has_osxsave && xgetbv_has_xmm_ymm()) {
avx_bits |= SIMDID_AVX;
/* CPUID.7.0 */
get_cpuid(7, 0, &eax, &ebx, &ecx, &edx);
const int has_bmi1 = (ebx & (1 << 3)) != 0;
@@ -142,13 +146,13 @@ SN_API SIMDID SN_DECL sn_get_simd_level()
const int has_amx_bf16 = (edx & (1 << 26)) != 0;
if (has_avx2) {
if (has_fma) {
main_lvl = SIMDID_PACK_MAIN((has_bmi1 && has_bmi2) ?
SIMDID_MAIN_LVL_AVX2_FMA_F16C :
SIMDID_MAIN_LVL_AVX2_FMA);
} else {
main_lvl = SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_AVX2);
}
avx_bits |= SIMDID_AVX2;
if (has_fma)
avx_bits |= SIMDID_AVX_FMA;
if (has_f16c)
avx_bits |= SIMDID_AVX_F16C;
main_lvl = SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_AVX2);
}
if (has_avx512f && xgetbv_has_avx512_state()) {
@@ -168,7 +172,7 @@ SN_API SIMDID SN_DECL sn_get_simd_level()
avx512_bits |= SIMDID_AVX512_VBMI2;
/* impl classification */
const int glue = is_amd || is_intel_glue_avx512(family, model);
const int glue = is_amd || is_intel_dual_avx512(family, model);
const int native512 = is_intel_native_avx512(family, model);
if (glue) {
avx512_bits |= SIMDID_AVX512_IMPL_DUAL;
@@ -194,7 +198,7 @@ SN_API SIMDID SN_DECL sn_get_simd_level()
}
global_simdid.mask = root | manu | main_lvl | SIMDID_PACK_AVX512(avx512_bits) |
SIMDID_PACK_AMX(amx_bits);
SIMDID_PACK_AMX(amx_bits) | SIMDID_PACK_AVX(avx_bits);
return global_simdid;
}