diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 329f81cf9..173c207a2 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -29,6 +29,7 @@ By default the cpu is detected and the most advanced form of SIMD is used. But LIBYUV_DISABLE_AVX512VBMI2 LIBYUV_DISABLE_AVX512VBITALG LIBYUV_DISABLE_AVX10 + LIBYUV_DISABLE_AVX10_2 LIBYUV_DISABLE_AVXVNNI LIBYUV_DISABLE_AVXVNNIINT8 LIBYUV_DISABLE_AMXINT8 diff --git a/include/libyuv/cpu_id.h b/include/libyuv/cpu_id.h index 26845b602..44ea8c07c 100644 --- a/include/libyuv/cpu_id.h +++ b/include/libyuv/cpu_id.h @@ -54,9 +54,10 @@ static const int kCpuHasAVX512VBMI = 0x200000; static const int kCpuHasAVX512VBMI2 = 0x400000; static const int kCpuHasAVX512VBITALG = 0x800000; static const int kCpuHasAVX10 = 0x1000000; -static const int kCpuHasAVXVNNI = 0x2000000; -static const int kCpuHasAVXVNNIINT8 = 0x4000000; -static const int kCpuHasAMXINT8 = 0x8000000; +static const int kCpuHasAVX10_2 = 0x2000000; +static const int kCpuHasAVXVNNI = 0x4000000; +static const int kCpuHasAVXVNNIINT8 = 0x8000000; +static const int kCpuHasAMXINT8 = 0x10000000; // These flags are only valid on MIPS processors. static const int kCpuHasMIPS = 0x10; diff --git a/source/cpu_id.cc b/source/cpu_id.cc index 48a350c6e..f5cc968fb 100644 --- a/source/cpu_id.cc +++ b/source/cpu_id.cc @@ -409,6 +409,7 @@ static SAFEBUFFERS int GetCpuFlags(void) { int cpu_info1[4] = {0, 0, 0, 0}; int cpu_info7[4] = {0, 0, 0, 0}; int cpu_einfo7[4] = {0, 0, 0, 0}; + int cpu_info24[4] = {0, 0, 0, 0}; int cpu_amdinfo21[4] = {0, 0, 0, 0}; CpuId(0, 0, cpu_info0); CpuId(1, 0, cpu_info1); @@ -417,6 +418,9 @@ static SAFEBUFFERS int GetCpuFlags(void) { CpuId(7, 1, cpu_einfo7); CpuId(0x80000021, 0, cpu_amdinfo21); } + if (cpu_info0[0] >= 0x24) { + CpuId(0x24, 0, cpu_info24); + } cpu_info = kCpuHasX86 | ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) | ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) | ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) | @@ -445,6 +449,9 @@ static SAFEBUFFERS int GetCpuFlags(void) { ((cpu_info7[2] & 0x00001000) ? kCpuHasAVX512VBITALG : 0) | ((cpu_einfo7[3] & 0x00080000) ? kCpuHasAVX10 : 0) | ((cpu_info7[3] & 0x02000000) ? kCpuHasAMXINT8 : 0); + if (cpu_info0[0] >= 0x24 && (cpu_einfo7[3] & 0x00080000)) { + cpu_info |= ((cpu_info24[1] & 0xFF) >= 2) ? kCpuHasAVX10_2: 0; + } } } #endif diff --git a/unit_test/cpu_test.cc b/unit_test/cpu_test.cc index cb9bf1c40..ebae29264 100644 --- a/unit_test/cpu_test.cc +++ b/unit_test/cpu_test.cc @@ -190,6 +190,7 @@ TEST_F(LibYUVBaseTest, TestCpuHas) { int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2); int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG); int has_avx10 = TestCpuFlag(kCpuHasAVX10); + int has_avx10_2 = TestCpuFlag(kCpuHasAVX10_2); int has_avxvnni = TestCpuFlag(kCpuHasAVXVNNI); int has_avxvnniint8 = TestCpuFlag(kCpuHasAVXVNNIINT8); int has_amxint8 = TestCpuFlag(kCpuHasAMXINT8); @@ -211,6 +212,7 @@ TEST_F(LibYUVBaseTest, TestCpuHas) { printf("Has AVX512VBMI2 0x%x\n", has_avx512vbmi2); printf("Has AVX512VBITALG 0x%x\n", has_avx512vbitalg); printf("Has AVX10 0x%x\n", has_avx10); + printf("Has AVX10_2 0x%x\n", has_avx10_2); printf("HAS AVXVNNI 0x%x\n", has_avxvnni); printf("Has AVXVNNIINT8 0x%x\n", has_avxvnniint8); printf("Has AMXINT8 0x%x\n", has_amxint8); diff --git a/unit_test/unit_test.cc b/unit_test/unit_test.cc index 3fcbd4fac..d917f5343 100644 --- a/unit_test/unit_test.cc +++ b/unit_test/unit_test.cc @@ -164,6 +164,9 @@ static int TestCpuEnv(int cpu_info) { if (TestEnv("LIBYUV_DISABLE_AVX10")) { cpu_info &= ~libyuv::kCpuHasAVX10; } + if (TestEnv("LIBYUV_DISABLE_AVX10_2")) { + cpu_info &= ~libyuv::kCpuHasAVX10_2; + } if (TestEnv("LIBYUV_DISABLE_AVXVNNI")) { cpu_info &= ~libyuv::kCpuHasAVXVNNI; } diff --git a/util/cpuid.c b/util/cpuid.c index ab05cc1c1..0f54b4222 100644 --- a/util/cpuid.c +++ b/util/cpuid.c @@ -181,6 +181,7 @@ int main(int argc, const char* argv[]) { int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2); int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG); int has_avx10 = TestCpuFlag(kCpuHasAVX10); + int has_avx10_2 = TestCpuFlag(kCpuHasAVX10_2); int has_avxvnni = TestCpuFlag(kCpuHasAVXVNNI); int has_avxvnniint8 = TestCpuFlag(kCpuHasAVXVNNIINT8); int has_amxint8 = TestCpuFlag(kCpuHasAMXINT8); @@ -202,6 +203,7 @@ int main(int argc, const char* argv[]) { printf("Has AVX512VBMI2 0x%x\n", has_avx512vbmi2); printf("Has AVX512VBITALG 0x%x\n", has_avx512vbitalg); printf("Has AVX10 0x%x\n", has_avx10); + printf("Has AVX10_2 0x%x\n", has_avx10_2); printf("HAS AVXVNNI 0x%x\n", has_avxvnni); printf("Has AVXVNNIINT8 0x%x\n", has_avxvnniint8); printf("Has AMXINT8 0x%x\n", has_amxint8);