This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository terminology.

View the commit online.

commit 1e6699a48855900361f1d247b8852c627e54d8e2
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 18:54:39 2026 -0600

    simd: always build the AVX2 kernels on x86_64
    
    The AVX2 kernels were only built with -Dsimd-avx2=true, which nobody
    sets, so every x86_64 build ran the SSE2 ones on CPUs that have AVX2.
    Drop the option: the kernels are always built, and simd_init() picks
    them when the CPU has AVX2, as it already did.
    
    Each kernel is compiled for AVX2 by a target attribute: the rest of
    the binary stays baseline x86-64, and no ymm instruction is outside
    the *_avx2 functions (checked with objdump on tytest). The CPU is
    asked through Eina, eina_cpu_features_get() & EINA_CPU_AVX2, when Eina
    has EINA_CPU_AVX2 (newer than EFL 1.28.1, probed by symbol as before),
    and otherwise through __builtin_cpu_supports("avx2"), so the kernels
    are built on an older Eina too. TERMINOLOGY_SIMD_DISABLE still turns
    every vector kernel off.
    
    simd_parity calls each kernel set directly, skipping a set the CPU
    lacks through the same check: on an AVX2 machine it covers the SSE2
    and the AVX2 kernels, and the SIMD-disabled pass the scalar ones.
    
    tybench -i 10 -w 1, release build with -falign-functions=64
    -falign-loops=64 -falign-jumps=32, 2000 lines of scrollback, median
    of 7 interleaved runs of perf stat on one pinned CPU, from a fixed
    working directory, GCC 11.4 on a Ryzen 7 6800U, parent (SSE2) vs this:
    
      corpus         Gcycles:u         Ginstructions:u
      scroll         2.172 -> 1.971    6.885 ->  5.740   -9.3% / -16.6%
      plain-ascii    0.737 -> 0.686    2.491 ->  2.147   -6.9% / -13.8%
      long-lines     0.671 -> 0.643    2.071 ->  1.857   -4.3% / -10.3%
      scroll-region  0.575 -> 0.556    2.099 ->  1.972   -3.3% /  -6.0%
      strings        0.332 -> 0.323    1.515 ->  1.458   -2.7% /  -3.7%
      sgr            1.668 -> 1.631    4.892 ->  4.601   -2.2% /  -5.9%
      hyperlink      3.338 -> 3.299   10.012 ->  9.901   -1.2% /  -1.1%
      fill           1.986 -> 1.966    5.889 ->  5.757   -1.0% /  -2.2%
      rep            3.077 -> 3.055   12.495 -> 12.245   -0.7% /  -2.0%
      unicode        1.977 -> 1.967    6.236 ->  6.086   -0.5% /  -2.4%
      insert         1.726 -> 1.719    5.573 ->  5.404   -0.4% /  -3.0%
      insert-mode    2.433 -> 2.433    7.921 ->  7.736    0.0% /  -2.3%
    
    No corpus is slower. The same corpora at 50 lines of scrollback move
    alike, within +0.8% on the cycles that do not improve. No document
    mentioned the option.
---
 meson.build         | 20 ++++++++------------
 meson_options.txt   |  4 ----
 src/bin/simd/simd.c | 26 +++++++++++++++++++-------
 src/bin/simd/simd.h | 13 +++++++++----
 4 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/meson.build b/meson.build
index 09887311..c574ac25 100644
--- a/meson.build
+++ b/meson.build
@@ -96,18 +96,14 @@ if cc.has_function('evas_object_textgrid_ligatures_set', dependencies: evas_dep)
   config_data.set('HAVE_TEXTGRID_LIGATURES', 1)
 endif
 
-if get_option('simd-avx2')
-  if host_machine.cpu_family() != 'x86_64'
-    error('simd-avx2 is only supported on x86_64')
-  endif
-  # Eina gained EINA_CPU_AVX2 after 1.28.1, and git builds of that period
-  # report the same version, so the symbol is probed rather than the version.
-  if not cc.has_header_symbol('Eina.h', 'EINA_CPU_AVX2',
-                              dependencies: eina_dep)
-    error('simd-avx2 needs an Eina that provides EINA_CPU_AVX2 ' +
-          '(EFL newer than 1.28.1)')
-  endif
-  add_project_arguments('-DTERMINOLOGY_ENABLE_AVX2', language: 'c')
+# The AVX2 kernels are always built on x86_64, each one compiled for AVX2 by a
+# target attribute so that the rest of the binary stays baseline x86-64, and
+# chosen at run time. Eina gained EINA_CPU_AVX2 after 1.28.1, and git builds
+# of that period report the same version, so the symbol is probed rather than
+# the version; without it the compiler's own CPU probe is used.
+if host_machine.cpu_family() == 'x86_64' and cc.has_header_symbol(
+     'Eina.h', 'EINA_CPU_AVX2', dependencies: eina_dep)
+  add_project_arguments('-DTERMINOLOGY_HAVE_EINA_CPU_AVX2', language: 'c')
 endif
 
 if cc.has_function('mkstemps')
diff --git a/meson_options.txt b/meson_options.txt
index a7559f2e..57917b70 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -16,10 +16,6 @@ option('benchmarks',
        type: 'boolean',
        value: false,
        description: 'Enable generating tybench, used to benchmark the pty intake path. (default=false)')
-option('simd-avx2',
-       type: 'boolean',
-       value: false,
-       description: 'Build the AVX2 intake kernels, used when the CPU supports them. Requires an Eina providing EINA_CPU_AVX2 (newer than EFL 1.28.1). (default=false)')
 option('nls',
        type: 'boolean',
        value: true,
diff --git a/src/bin/simd/simd.c b/src/bin/simd/simd.c
index c79916c8..41e6a983 100644
--- a/src/bin/simd/simd.c
+++ b/src/bin/simd/simd.c
@@ -13,6 +13,19 @@ static Eina_Bool _use_simd = EINA_FALSE;
 static Eina_Bool _use_avx2 = EINA_FALSE;
 #endif
 
+#if defined(TERMINOLOGY_HAVE_AVX2)
+Eina_Bool
+simd_avx2_supported(void)
+{
+#if defined(TERMINOLOGY_HAVE_EINA_CPU_AVX2)
+   return (eina_cpu_features_get() & EINA_CPU_AVX2) ? EINA_TRUE : EINA_FALSE;
+#else
+   __builtin_cpu_init();
+   return __builtin_cpu_supports("avx2") ? EINA_TRUE : EINA_FALSE;
+#endif
+}
+#endif
+
 void
 simd_init(void)
 {
@@ -24,8 +37,7 @@ simd_init(void)
      _use_simd = EINA_FALSE;
 #endif
 #if defined(TERMINOLOGY_HAVE_AVX2)
-   _use_avx2 = (_use_simd && (eina_cpu_features_get() & EINA_CPU_AVX2))
-      ? EINA_TRUE : EINA_FALSE;
+   _use_avx2 = (_use_simd && simd_avx2_supported()) ? EINA_TRUE : EINA_FALSE;
 #endif
 }
 
@@ -495,7 +507,7 @@ _test_ref_widen(void)
 
 typedef struct tag_SimdVector
 {
-   Eina_Cpu_Features required;
+   Eina_Bool (*supported)(void); /* NULL: always */
    size_t (*scan)(const unsigned char *buf, size_t len);
    size_t (*scan_u32)(const Eina_Unicode *buf, size_t len);
    size_t (*rscan)(const unsigned char *buf, size_t len);
@@ -506,7 +518,7 @@ typedef struct tag_SimdVector
 
 static const SimdVector _vectors[] = {
 #if defined(TERMINOLOGY_HAVE_NEON)
-   { 0,
+   { NULL,
      simd_scan_plain_ascii_neon,
      simd_scan_plain_ascii_u32_neon,
      simd_rscan_nonzero_neon,
@@ -514,7 +526,7 @@ static const SimdVector _vectors[] = {
      simd_widen_ascii_neon },
 #endif
 #if defined(TERMINOLOGY_HAVE_SSE2)
-   { 0,
+   { NULL,
      simd_scan_plain_ascii_sse2,
      simd_scan_plain_ascii_u32_sse2,
      simd_rscan_nonzero_sse2,
@@ -522,7 +534,7 @@ static const SimdVector _vectors[] = {
      simd_widen_ascii_sse2 },
 #endif
 #if defined(TERMINOLOGY_HAVE_AVX2)
-   { EINA_CPU_AVX2,
+   { simd_avx2_supported,
      simd_scan_plain_ascii_avx2,
      simd_scan_plain_ascii_u32_avx2,
      simd_rscan_nonzero_avx2,
@@ -777,7 +789,7 @@ tytest_simd_parity(void)
 
            /* Calls the kernels directly, so a kernel set the CPU lacks must
             * be skipped here whatever TERMINOLOGY_SIMD_DISABLE says. */
-           if ((eina_cpu_features_get() & set->required) != set->required)
+           if (set->supported && !set->supported())
              continue;
            _test_scan(set);
            _test_scan_u32(set);
diff --git a/src/bin/simd/simd.h b/src/bin/simd/simd.h
index 19190bf3..73667c4a 100644
--- a/src/bin/simd/simd.h
+++ b/src/bin/simd/simd.h
@@ -15,10 +15,15 @@
 #endif
 #if defined(__x86_64__)
 # define TERMINOLOGY_HAVE_SSE2 1
-/* AVX2 is optional (-Dsimd-avx2=true) and probed at runtime by simd_init(). */
-# if defined(TERMINOLOGY_ENABLE_AVX2)
-#  define TERMINOLOGY_HAVE_AVX2 1
-# endif
+/* AVX2 is not baseline: its kernels are built with a target attribute, and
+ * used when simd_avx2_supported() says the CPU has it. */
+# define TERMINOLOGY_HAVE_AVX2 1
+#endif
+
+#if defined(TERMINOLOGY_HAVE_AVX2)
+/* Whether the CPU runs the AVX2 kernels, whatever TERMINOLOGY_SIMD_DISABLE
+ * says. */
+Eina_Bool simd_avx2_supported(void);
 #endif
 
 /* Index of the first byte that is not plain printable ASCII (0x20..0x7e),

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to