util: Refactoring check_cpu_caps_override out
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17813>
This commit is contained in:
@@ -590,6 +590,72 @@ get_cpu_topology(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
void check_cpu_caps_override(void)
|
||||
{
|
||||
const char *override_cpu_caps = debug_get_option("GALLIUM_OVERRIDE_CPU_CAPS", NULL);
|
||||
#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
|
||||
if (debug_get_bool_option("GALLIUM_NOSSE", false)) {
|
||||
util_cpu_caps.has_sse = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
/* For simulating less capable machines */
|
||||
if (debug_get_bool_option("LP_FORCE_SSE2", false)) {
|
||||
util_cpu_caps.has_sse3 = 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
|
||||
|
||||
if (override_cpu_caps != NULL) {
|
||||
#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
|
||||
if (!strcmp(override_cpu_caps, "nosse")) {
|
||||
util_cpu_caps.has_sse = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse")) {
|
||||
util_cpu_caps.has_sse2 = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse2")) {
|
||||
util_cpu_caps.has_sse3 = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse3")) {
|
||||
util_cpu_caps.has_sse4_1 = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse4.1")) {
|
||||
util_cpu_caps.has_avx = 0;
|
||||
}
|
||||
#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
|
||||
}
|
||||
|
||||
#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
|
||||
if (!util_cpu_caps.has_sse) {
|
||||
util_cpu_caps.has_sse2 = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_sse2) {
|
||||
util_cpu_caps.has_sse3 = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_sse3) {
|
||||
util_cpu_caps.has_ssse3 = 0;
|
||||
util_cpu_caps.has_sse4_1 = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_sse4_1) {
|
||||
util_cpu_caps.has_sse4_2 = 0;
|
||||
util_cpu_caps.has_avx = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_avx) {
|
||||
util_cpu_caps.has_avx2 = 0;
|
||||
util_cpu_caps.has_f16c = 0;
|
||||
util_cpu_caps.has_fma = 0;
|
||||
|
||||
/* avx512 are cleared */
|
||||
util_cpu_caps.has_avx512f = 0;
|
||||
util_cpu_caps.has_avx512dq = 0;
|
||||
util_cpu_caps.has_avx512ifma = 0;
|
||||
util_cpu_caps.has_avx512pf = 0;
|
||||
util_cpu_caps.has_avx512er = 0;
|
||||
util_cpu_caps.has_avx512cd = 0;
|
||||
util_cpu_caps.has_avx512bw = 0;
|
||||
util_cpu_caps.has_avx512vl = 0;
|
||||
util_cpu_caps.has_avx512vbmi = 0;
|
||||
}
|
||||
#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
|
||||
}
|
||||
|
||||
void _util_cpu_detect_once(void);
|
||||
|
||||
void
|
||||
@@ -597,7 +663,6 @@ _util_cpu_detect_once(void)
|
||||
{
|
||||
int available_cpus = 0;
|
||||
int total_cpus = 0;
|
||||
const char *override_cpu_caps = debug_get_option("GALLIUM_OVERRIDE_CPU_CAPS", NULL);
|
||||
|
||||
memset(&util_cpu_caps, 0, sizeof util_cpu_caps);
|
||||
|
||||
@@ -803,64 +868,6 @@ _util_cpu_detect_once(void)
|
||||
util_cpu_caps.cacheline = cacheline;
|
||||
}
|
||||
}
|
||||
if (debug_get_bool_option("GALLIUM_NOSSE", false)) {
|
||||
util_cpu_caps.has_sse = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
/* For simulating less capable machines */
|
||||
if (debug_get_bool_option("LP_FORCE_SSE2", false)) {
|
||||
util_cpu_caps.has_sse3 = 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
|
||||
|
||||
if (override_cpu_caps != NULL) {
|
||||
#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
|
||||
if (!strcmp(override_cpu_caps, "nosse")) {
|
||||
util_cpu_caps.has_sse = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse")) {
|
||||
util_cpu_caps.has_sse2 = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse2")) {
|
||||
util_cpu_caps.has_sse3 = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse3")) {
|
||||
util_cpu_caps.has_sse4_1 = 0;
|
||||
} else if (!strcmp(override_cpu_caps, "sse4.1")) {
|
||||
util_cpu_caps.has_avx = 0;
|
||||
}
|
||||
#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
|
||||
}
|
||||
|
||||
#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
|
||||
if (!util_cpu_caps.has_sse) {
|
||||
util_cpu_caps.has_sse2 = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_sse2) {
|
||||
util_cpu_caps.has_sse3 = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_sse3) {
|
||||
util_cpu_caps.has_ssse3 = 0;
|
||||
util_cpu_caps.has_sse4_1 = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_sse4_1) {
|
||||
util_cpu_caps.has_sse4_2 = 0;
|
||||
util_cpu_caps.has_avx = 0;
|
||||
}
|
||||
if (!util_cpu_caps.has_avx) {
|
||||
util_cpu_caps.has_avx2 = 0;
|
||||
util_cpu_caps.has_f16c = 0;
|
||||
util_cpu_caps.has_fma = 0;
|
||||
|
||||
/* avx512 are cleared */
|
||||
util_cpu_caps.has_avx512f = 0;
|
||||
util_cpu_caps.has_avx512dq = 0;
|
||||
util_cpu_caps.has_avx512ifma = 0;
|
||||
util_cpu_caps.has_avx512pf = 0;
|
||||
util_cpu_caps.has_avx512er = 0;
|
||||
util_cpu_caps.has_avx512cd = 0;
|
||||
util_cpu_caps.has_avx512bw = 0;
|
||||
util_cpu_caps.has_avx512vl = 0;
|
||||
util_cpu_caps.has_avx512vbmi = 0;
|
||||
}
|
||||
#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
|
||||
|
||||
#if defined(PIPE_ARCH_ARM) || defined(PIPE_ARCH_AARCH64)
|
||||
@@ -879,6 +886,8 @@ _util_cpu_detect_once(void)
|
||||
util_cpu_caps.family = CPU_S390X;
|
||||
#endif
|
||||
|
||||
check_cpu_caps_override();
|
||||
|
||||
get_cpu_topology();
|
||||
|
||||
if (debug_get_option_dump_cpu()) {
|
||||
|
Reference in New Issue
Block a user