@@ -558,6 +558,37 @@ def check_stdatomic(v):
558558 "Has builtin __atomic_load_n() and __atomic_store_n() functions" ,
559559 )
560560
561+ # Check for __builtin_shufflevector with 128-bit vector support on an
562+ # architecture where it compiles to worthwhile native SIMD instructions.
563+ # Used for SIMD-accelerated bytes.hex() in Python/pystrhex.c.
564+ pyconf .checking ("for __builtin_shufflevector" )
565+ ac_cv_efficient_builtin_shufflevector = pyconf .link_check (
566+ source = (
567+ "#if !defined(__x86_64__) && !defined(__aarch64__) && \\ \n "
568+ " !(defined(__arm__) && defined(__ARM_NEON))\n "
569+ '# error "128-bit vector SIMD not worthwhile on this architecture"\n '
570+ "#endif\n "
571+ "typedef unsigned char v16u8 __attribute__((vector_size(16)));\n "
572+ "int main(void) {\n "
573+ " v16u8 a = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};\n "
574+ " v16u8 b = {16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};\n "
575+ " v16u8 c = __builtin_shufflevector(a, b,\n "
576+ " 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23);\n "
577+ " (void)c;\n "
578+ " return 0;\n "
579+ "}\n "
580+ ),
581+ cache_var = "ac_cv_efficient_builtin_shufflevector" ,
582+ )
583+ pyconf .result (ac_cv_efficient_builtin_shufflevector )
584+ if ac_cv_efficient_builtin_shufflevector :
585+ pyconf .define (
586+ "HAVE_EFFICIENT_BUILTIN_SHUFFLEVECTOR" ,
587+ 1 ,
588+ "Define if compiler supports __builtin_shufflevector with 128-bit "
589+ "vectors AND the target architecture has native SIMD" ,
590+ )
591+
561592
562593def check_sizes (v ):
563594 """Check sizeof/alignof for fundamental types and pthread types."""
0 commit comments