This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch v-1.29
in repository efl.
View the commit online.
commit c371e8a0b069d224dd652f4c9a470a65713c79d3
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 18 16:40:25 2026 -0600
eina: let EINA_CPU_DISABLE hide cpu features
Ruling a SIMD path in or out of a bug meant knowing which library
dispatches it: EVAS_CPU_NO_SSE3 only reached evas, while ector and the
other users of eina_cpu_features_get() kept their SSE3 code. Hiding the
feature where it is detected reaches every one of them.
Detection now starts from zero at each init, so that initializing again
without the variable restores the real features.
NEON is reported on every aarch64 build rather than only where auxv is
available, as it is mandatory in ARMv8-A; evas assumed so on its own
until now, and is about to rely on eina for it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/eina/eina_cpu.c | 63 ++++++++++++++++++++++++++++++++++++++++--
src/lib/eina/eina_cpu.h | 5 ++++
src/tests/eina/eina_test_cpu.c | 42 ++++++++++++++++++++++++++++
3 files changed, 107 insertions(+), 3 deletions(-)
diff --git a/src/lib/eina/eina_cpu.c b/src/lib/eina/eina_cpu.c
index b32c17d9ea..22f9565909 100644
--- a/src/lib/eina/eina_cpu.c
+++ b/src/lib/eina/eina_cpu.c
@@ -182,9 +182,6 @@ static void
_arm_cpu_features(Eina_Cpu_Features *features)
{
unsigned long aux = getauxval(AT_HWCAP);
-# if defined(__aarch64__)
- *features |= EINA_CPU_NEON;
-# endif
# ifdef HWCAP_NEON
if (aux & HWCAP_NEON) *features |= EINA_CPU_NEON;
# endif
@@ -218,14 +215,74 @@ _ppc_cpu_features(Eina_Cpu_Features *features)
*/
EINA_API Eina_Cpu_Features eina_cpu_features = 0;
+static void
+_eina_cpu_features_disable(const char *list)
+{
+ static const struct
+ {
+ const char *name;
+ Eina_Cpu_Features feature;
+ } names[] = {
+ { "mmx", EINA_CPU_MMX },
+ { "sse", EINA_CPU_SSE },
+ { "sse2", EINA_CPU_SSE2 },
+ { "sse3", EINA_CPU_SSE3 },
+ { "ssse3", EINA_CPU_SSSE3 },
+ { "sse41", EINA_CPU_SSE41 },
+ { "sse42", EINA_CPU_SSE42 },
+ { "avx2", EINA_CPU_AVX2 },
+ { "altivec", EINA_CPU_ALTIVEC },
+ { "vis", EINA_CPU_VIS },
+ { "neon", EINA_CPU_NEON },
+ { "sve", EINA_CPU_SVE },
+ };
+ const char *token = list;
+ unsigned int i;
+ size_t len;
+
+ if (!strcmp(list, "all"))
+ {
+ eina_cpu_features = 0;
+ return;
+ }
+
+ while (*token)
+ {
+ len = strcspn(token, ",");
+ for (i = 0; i < EINA_C_ARRAY_LENGTH(names); i++)
+ {
+ if ((strlen(names[i].name) == len) &&
+ !strncmp(token, names[i].name, len))
+ break;
+ }
+ if (i < EINA_C_ARRAY_LENGTH(names))
+ eina_cpu_features &= ~names[i].feature;
+ else if (len)
+ EINA_LOG_WARN("EINA_CPU_DISABLE: unknown cpu feature '%.*s'",
+ (int)len, token);
+ token += len;
+ if (*token == ',') token++;
+ }
+}
+
Eina_Bool
eina_cpu_init(void)
{
+ const char *disable;
+
+ eina_cpu_features = 0;
#if defined(__i386__) || defined(__x86_64__)
_x86_simd(&eina_cpu_features);
#elif defined(HAVE_SYS_AUXV_H) && defined(HAVE_ASM_HWCAP_H) && (defined(__arm__) || defined(__aarch64__)) && defined(__linux__)
_arm_cpu_features(&eina_cpu_features);
#endif
+#if defined(__aarch64__)
+ /* NEON is mandatory in ARMv8-A, also where there is no auxv to ask. */
+ eina_cpu_features |= EINA_CPU_NEON;
+#endif
+
+ disable = getenv("EINA_CPU_DISABLE");
+ if (disable) _eina_cpu_features_disable(disable);
// Figure out the page size for this system
_eina_page_size();
diff --git a/src/lib/eina/eina_cpu.h b/src/lib/eina/eina_cpu.h
index 2fc54669aa..1e19c1d053 100644
--- a/src/lib/eina/eina_cpu.h
+++ b/src/lib/eina/eina_cpu.h
@@ -70,6 +70,11 @@ EINA_API extern Eina_Cpu_Features eina_cpu_features;
/**
* @brief Cpu features accessor.
*
+ * Setting the environment variable EINA_CPU_DISABLE before eina_init()
+ * hides features from every EFL library, to rule out or compare a SIMD
+ * path: a comma separated list of mmx, sse, sse2, sse3, ssse3, sse41,
+ * sse42, avx2, altivec, vis, neon and sve, or "all".
+ *
* @return the current cpu features
*/
EINA_API Eina_Cpu_Features eina_cpu_features_get(void);
diff --git a/src/tests/eina/eina_test_cpu.c b/src/tests/eina/eina_test_cpu.c
index de318bef0d..a7d7ad7207 100644
--- a/src/tests/eina/eina_test_cpu.c
+++ b/src/tests/eina/eina_test_cpu.c
@@ -27,7 +27,49 @@ EFL_START_TEST(eina_cpu_avx2_implies_sse3)
}
EFL_END_TEST
+static Eina_Cpu_Features
+_cpu_features_with_disable(const char *disable)
+{
+ Eina_Cpu_Features f;
+
+ /* The suite fixture holds the only eina_init(), so this cycle runs the
+ * feature detection again. */
+ ck_assert_int_eq(eina_shutdown(), 0);
+ setenv("EINA_CPU_DISABLE", disable, 1);
+ eina_init();
+ f = eina_cpu_features_get();
+ unsetenv("EINA_CPU_DISABLE");
+ eina_shutdown();
+ eina_init();
+ return f;
+}
+
+EFL_START_TEST(eina_cpu_disable_masks_listed_features)
+{
+ Eina_Cpu_Features detected = eina_cpu_features_get();
+ Eina_Cpu_Features f;
+
+ f = _cpu_features_with_disable("sse3");
+ ck_assert_int_eq(f, detected & ~EINA_CPU_SSE3);
+
+ f = _cpu_features_with_disable("avx2,neon,sse41");
+ ck_assert_int_eq(f, detected & ~(EINA_CPU_AVX2 | EINA_CPU_NEON | EINA_CPU_SSE41));
+
+ f = _cpu_features_with_disable("all");
+ ck_assert_int_eq(f, 0);
+
+ /* A name that is a prefix of another must not match it, and an unknown
+ * name is ignored rather than taking everything else with it. */
+ f = _cpu_features_with_disable("sse,bogus");
+ ck_assert_int_eq(f, detected & ~EINA_CPU_SSE);
+
+ /* Re-initializing without the variable restores the detection. */
+ ck_assert_int_eq(eina_cpu_features_get(), detected);
+}
+EFL_END_TEST
+
void eina_test_cpu(TCase *tc)
{
tcase_add_test(tc, eina_cpu_avx2_implies_sse3);
+ tcase_add_test(tc, eina_cpu_disable_masks_listed_features);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.