@@ -481,23 +481,23 @@ gc_maybe_untrack(PyObject *op)
481481#define BUFFER_HI 16
482482#define BUFFER_LO 8
483483
484- #ifdef GC_ENABLE_PREFETCH_INSTRUCTIONS
485- #if (defined(__GNUC__ ) || defined(__clang__ ))
486- #define USE_BUILTIN_PREFETCH 1
487- #elif (defined(__cplusplus ) && (__cplusplus >= 201103 ))
488- #if defined(_MSC_VER )
489- #include <instrin.h>
484+ #if defined(__GNUC__ ) || defined(__clang__ )
485+ #define PREFETCH_L1 (ptr ) __builtin_prefetch(ptr, 1, 3)
486+ #define PREFETCH_L2 (ptr ) __builtin_prefetch(ptr, 1, 2)
487+ #elif defined(_MSC_VER ) && (defined(_M_X64 ) || defined(_M_I86 )) && !defined(_M_ARM64EC )
488+ #include <mmintrin.h>
489+ #define PREFETCH_L1 (ptr ) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
490+ #define PREFETCH_L2 (ptr ) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
491+ #elif defined(__aarch64__ )
492+ #define PREFETCH_L1 (ptr ) do { __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr))); } while (0)
493+ #define PREFETCH_L2 (ptr ) do { __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr))); } while (0)
490494#else
491- #include <xmmintrin.h>
492- #endif
493- #define USE_MM_PREFETCH 1
495+ #define PREFETCH_L1 (ptr ) do { (void)(ptr); } while (0) /* disabled */
496+ #define PREFETCH_L2 (ptr ) do { (void)(ptr); } while (0) /* disabled */
494497#endif
495- #endif // GC_ENABLE_PREFETCH_INSTRUCTIONS
496498
497- #if defined(USE_BUILTIN_PREFETCH )
498- #define prefetch (ptr ) __builtin_prefetch(ptr, 1, 3)
499- #elif defined(USE_MM_PREFETCH )
500- #define prefetch (ptr ) __mm_prefetch(ptr, _MM_HINT_T0)
499+ #ifdef GC_ENABLE_PREFETCH_INSTRUCTIONS
500+ #define prefetch (ptr ) PREFETCH_L2(ptr)
501501#else
502502#define prefetch (ptr )
503503#endif
0 commit comments