1feee8
commit 94b9c1b6409e34f3f0b2339f77d7ee78087422eb
1feee8
Author: Aurelien Jarno <aurelien@aurel32.net>
1feee8
Date:   Mon Oct 3 23:16:46 2022 +0200
1feee8
1feee8
    x86-64: Require BMI2 for AVX2 (raw|w)memchr implementations
1feee8
    
1feee8
    The AVX2 memchr, rawmemchr and wmemchr implementations use the 'bzhi'
1feee8
    and 'sarx' instructions, which belongs to the BMI2 CPU feature.
1feee8
    
1feee8
    Fixes: acfd088a1963 ("x86: Optimize memchr-avx2.S")
1feee8
    Partially resolves: BZ #29611
1feee8
    
1feee8
    Reviewed-by: Noah Goldstein  <goldstein.w.n@gmail.com>
1feee8
    (cherry picked from commit e3e7fab7fe5186d18ca2046d99ba321c27db30ad)
1feee8
1feee8
diff --git a/sysdeps/x86_64/multiarch/ifunc-impl-list.c b/sysdeps/x86_64/multiarch/ifunc-impl-list.c
1feee8
index e76a991dc671c1a9..81640cf00664e3ed 100644
1feee8
--- a/sysdeps/x86_64/multiarch/ifunc-impl-list.c
1feee8
+++ b/sysdeps/x86_64/multiarch/ifunc-impl-list.c
1feee8
@@ -41,10 +41,12 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
1feee8
   /* Support sysdeps/x86_64/multiarch/memchr.c.  */
1feee8
   IFUNC_IMPL (i, name, memchr,
1feee8
 	      IFUNC_IMPL_ADD (array, i, memchr,
1feee8
-			      CPU_FEATURE_USABLE (AVX2),
1feee8
+			      (CPU_FEATURE_USABLE (AVX2)
1feee8
+			       && CPU_FEATURE_USABLE (BMI2)),
1feee8
 			      __memchr_avx2)
1feee8
 	      IFUNC_IMPL_ADD (array, i, memchr,
1feee8
 			      (CPU_FEATURE_USABLE (AVX2)
1feee8
+			       && CPU_FEATURE_USABLE (BMI2)
1feee8
 			       && CPU_FEATURE_USABLE (RTM)),
1feee8
 			      __memchr_avx2_rtm)
1feee8
 	      IFUNC_IMPL_ADD (array, i, memchr,
1feee8
@@ -283,10 +285,12 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
1feee8
   /* Support sysdeps/x86_64/multiarch/rawmemchr.c.  */
1feee8
   IFUNC_IMPL (i, name, rawmemchr,
1feee8
 	      IFUNC_IMPL_ADD (array, i, rawmemchr,
1feee8
-			      CPU_FEATURE_USABLE (AVX2),
1feee8
+			      (CPU_FEATURE_USABLE (AVX2)
1feee8
+			       && CPU_FEATURE_USABLE (BMI2)),
1feee8
 			      __rawmemchr_avx2)
1feee8
 	      IFUNC_IMPL_ADD (array, i, rawmemchr,
1feee8
 			      (CPU_FEATURE_USABLE (AVX2)
1feee8
+			       && CPU_FEATURE_USABLE (BMI2)
1feee8
 			       && CPU_FEATURE_USABLE (RTM)),
1feee8
 			      __rawmemchr_avx2_rtm)
1feee8
 	      IFUNC_IMPL_ADD (array, i, rawmemchr,
1feee8
@@ -787,10 +791,12 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
1feee8
   /* Support sysdeps/x86_64/multiarch/wmemchr.c.  */
1feee8
   IFUNC_IMPL (i, name, wmemchr,
1feee8
 	      IFUNC_IMPL_ADD (array, i, wmemchr,
1feee8
-			      CPU_FEATURE_USABLE (AVX2),
1feee8
+			      (CPU_FEATURE_USABLE (AVX2)
1feee8
+			       && CPU_FEATURE_USABLE (BMI2)),
1feee8
 			      __wmemchr_avx2)
1feee8
 	      IFUNC_IMPL_ADD (array, i, wmemchr,
1feee8
 			      (CPU_FEATURE_USABLE (AVX2)
1feee8
+			       && CPU_FEATURE_USABLE (BMI2)
1feee8
 			       && CPU_FEATURE_USABLE (RTM)),
1feee8
 			      __wmemchr_avx2_rtm)
1feee8
 	      IFUNC_IMPL_ADD (array, i, wmemchr,