On 15/2/24 09:14, Richard Henderson wrote:
Because the three alternatives are monotonic, we don't
need to keep a couple of bitmasks, just identify the
strongest alternative at startup.

Signed-off-by: Richard Henderson <richard.hender...@linaro.org>
---
  util/bufferiszero.c | 56 ++++++++++++++++++---------------------------
  1 file changed, 22 insertions(+), 34 deletions(-)

enum {
  ACCEL_DEFAULT,
  ACCEL_SSE2,
  ACCEL_AVX2,
};

+static biz_accel_fn const accel_table[] = {

  [ACCEL_DEFAULT] =

+    buffer_is_zero_int_ge256,

  [ACCEL_SSE2] =

+    buffer_zero_sse2,
  #ifdef CONFIG_AVX2_OPT

  [ACCEL_AVX2] =

+    buffer_zero_avx2,
  #endif


+static unsigned accel_index;
static void __attribute__((constructor)) init_accel(void)
  {
-    used_accel = select_accel_cpuinfo(cpuinfo_init());
+    unsigned info = cpuinfo_init();
+    unsigned index = (info & CPUINFO_SSE2 ? 1 : 0);

  ... ? ACCEL_SSE2 : ACCEL_DEFAULT;

+
+#ifdef CONFIG_AVX2_OPT
+    if (info & CPUINFO_AVX2) {
+        index = 2;

  ... = ACCEL_AVX2

+    }
+#endif
+
+    accel_index = index;
+    buffer_is_zero_accel = accel_table[index];
  }
Preferably introducing accel enum:
Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>

Reply via email to