Skip to content

Commit 1b4e8c3

Browse files
committed
Add prefetch() macro that might work on MSVC.
1 parent 1dd4bb6 commit 1b4e8c3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Python/gc_free_threading.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,23 @@ gc_maybe_untrack(PyObject *op)
481481
#define BUFFER_HI 16
482482
#define BUFFER_LO 8
483483

484-
#if !(defined(__GNUC__) || defined(__clang__))
485-
#undef GC_ENABLE_PREFETCH_INSTRUCTIONS
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>
490+
#else
491+
#include <xmmintrin.h>
492+
#endif
493+
#define USE_MM_PREFETCH 1
486494
#endif
495+
#endif // GC_ENABLE_PREFETCH_INSTRUCTIONS
487496

488-
#ifdef GC_ENABLE_PREFETCH_INSTRUCTIONS
497+
#if defined(USE_BUILTIN_PREFETCH)
489498
#define prefetch(ptr) __builtin_prefetch(ptr, 1, 3)
499+
#elif defined(USE_MM_PREFETCH)
500+
#define prefetch(ptr) __mm_prefetch(ptr, _MM_HINT_T0)
490501
#else
491502
#define prefetch(ptr)
492503
#endif
@@ -514,7 +525,7 @@ gc_mark_stack_push(_PyObjectStack *ms, PyObject *op)
514525
static inline void
515526
gc_mark_buffer_push(PyObject *op, struct gc_mark_args *args)
516527
{
517-
#if Py_DEBUG
528+
#ifdef Py_DEBUG
518529
Py_ssize_t buf_used = args->enqueued - args->dequeued;
519530
assert(buf_used < BUFFER_SIZE);
520531
#endif

0 commit comments

Comments
 (0)