From c704831eca99c8544fe8e40e73fa69db26f58ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=B6ner?= Date: Sat, 10 Dec 2022 22:58:04 +0100 Subject: [PATCH 1/6] Enable prefetch on MSVC --- include/private/gcconfig.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index ab87692bc..3bb7db693 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -34,6 +34,10 @@ # include /* For size_t etc. */ # endif +# ifdef _MSC_VER +# include /* for prefetch intrinsics */ +# endif + /* Note: Only wrap our own declarations, and not the included headers. */ /* In this case, wrap our entire file, but temporarily unwrap/rewrap */ /* around #includes. Types and macros do not need such wrapping, only */ @@ -3196,7 +3200,11 @@ EXTERN_C_BEGIN # if GC_GNUC_PREREQ(3, 0) && !defined(NO_PREFETCH) # define PREFETCH(x) __builtin_prefetch((x), 0, 0) # else -# define PREFETCH(x) (void)0 +# ifdef _MSC_VER +# define PREFETCH(x) _mm_prefetch((x), _MM_HINT_T0) +# else +# define PREFETCH(x) (void)0 +# endif # endif #endif @@ -3204,7 +3212,11 @@ EXTERN_C_BEGIN # if GC_GNUC_PREREQ(3, 0) && !defined(GC_NO_PREFETCH_FOR_WRITE) # define GC_PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1) # else -# define GC_PREFETCH_FOR_WRITE(x) (void)0 +# ifdef _MSC_VER +# define GC_PREFETCH_FOR_WRITE(x) _mm_prefetch((x), _MM_HINT_T0) +# else +# define GC_PREFETCH_FOR_WRITE(x) (void)0 +# endif # endif #endif From f3c778acc6384b5bae74dc58e6ba035faccf483c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=B6ner?= Date: Thu, 15 Dec 2022 13:01:37 +0100 Subject: [PATCH 2/6] Respect NO_PREFETCH and add missing prefetch in gc_inline.h --- include/gc_inline.h | 6 ++++++ include/private/gcconfig.h | 16 ++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/gc_inline.h b/include/gc_inline.h index dca8fa3a1..a8060a629 100644 --- a/include/gc_inline.h +++ b/include/gc_inline.h @@ -31,6 +31,10 @@ #include "gc.h" #include "gc_tiny_fl.h" +# ifdef _MSC_VER +# include /* for prefetch intrinsics */ +# endif + #if GC_GNUC_PREREQ(3, 0) # define GC_EXPECT(expr, outcome) __builtin_expect(expr,outcome) /* Equivalent to (expr), but predict that usually (expr)==outcome. */ @@ -54,6 +58,8 @@ #ifndef GC_PREFETCH_FOR_WRITE # if GC_GNUC_PREREQ(3, 0) && !defined(GC_NO_PREFETCH_FOR_WRITE) # define GC_PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1) +# elif defined(_MSC_VER) && !defined(GC_NO_PREFETCH_FOR_WRITE) +# define GC_PREFETCH_FOR_WRITE(x) _mm_prefetch((x), _MM_HINT_T0) # else # define GC_PREFETCH_FOR_WRITE(x) (void)0 # endif diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 3bb7db693..bb376148c 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -3199,24 +3199,20 @@ EXTERN_C_BEGIN #ifndef PREFETCH # if GC_GNUC_PREREQ(3, 0) && !defined(NO_PREFETCH) # define PREFETCH(x) __builtin_prefetch((x), 0, 0) +# elif defined(_MSC_VER) && !defined(NO_PREFETCH) +# define PREFETCH(x) _mm_prefetch((x), _MM_HINT_T0) # else -# ifdef _MSC_VER -# define PREFETCH(x) _mm_prefetch((x), _MM_HINT_T0) -# else -# define PREFETCH(x) (void)0 -# endif +# define PREFETCH(x) (void)0 # endif #endif #ifndef GC_PREFETCH_FOR_WRITE # if GC_GNUC_PREREQ(3, 0) && !defined(GC_NO_PREFETCH_FOR_WRITE) # define GC_PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1) +# elif defined(_MSC_VER) && !defined(GC_NO_PREFETCH_FOR_WRITE) +# define GC_PREFETCH_FOR_WRITE(x) _mm_prefetch((x), _MM_HINT_T0) # else -# ifdef _MSC_VER -# define GC_PREFETCH_FOR_WRITE(x) _mm_prefetch((x), _MM_HINT_T0) -# else -# define GC_PREFETCH_FOR_WRITE(x) (void)0 -# endif +# define GC_PREFETCH_FOR_WRITE(x) (void)0 # endif #endif From 81823f1a31353c9d1f9ef05eeb6d85a545563216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=B6ner?= Date: Wed, 1 Feb 2023 13:44:39 +0100 Subject: [PATCH 3/6] Update gc_inline.h --- include/gc_inline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gc_inline.h b/include/gc_inline.h index a8060a629..3580e9649 100644 --- a/include/gc_inline.h +++ b/include/gc_inline.h @@ -32,7 +32,7 @@ #include "gc_tiny_fl.h" # ifdef _MSC_VER -# include /* for prefetch intrinsics */ +# include /* for prefetch intrinsics */ # endif #if GC_GNUC_PREREQ(3, 0) From a84e95ab7675c71c368ccd2f8346a5f6906fcbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=B6ner?= Date: Wed, 1 Feb 2023 13:44:57 +0100 Subject: [PATCH 4/6] Update gcconfig.h --- include/private/gcconfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index bb376148c..87f95a35f 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -35,7 +35,7 @@ # endif # ifdef _MSC_VER -# include /* for prefetch intrinsics */ +# include /* for prefetch intrinsics */ # endif /* Note: Only wrap our own declarations, and not the included headers. */ From 729106f7cde246464d61f55029e364defa0ab9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=B6ner?= Date: Wed, 1 Feb 2023 13:51:33 +0100 Subject: [PATCH 5/6] Update gc_inline.h --- include/gc_inline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/gc_inline.h b/include/gc_inline.h index 3580e9649..b67725107 100644 --- a/include/gc_inline.h +++ b/include/gc_inline.h @@ -58,7 +58,7 @@ #ifndef GC_PREFETCH_FOR_WRITE # if GC_GNUC_PREREQ(3, 0) && !defined(GC_NO_PREFETCH_FOR_WRITE) # define GC_PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1) -# elif defined(_MSC_VER) && !defined(GC_NO_PREFETCH_FOR_WRITE) +# elif defined(_MSC_VER) && !defined(GC_NO_PREFETCH_FOR_WRITE) && !defined(_M_ARM) && !defined(_M_ARM64) # define GC_PREFETCH_FOR_WRITE(x) _mm_prefetch((x), _MM_HINT_T0) # else # define GC_PREFETCH_FOR_WRITE(x) (void)0 From d7369afae7ef9bbb1c1c8659baf9a3ac111dafe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=B6ner?= Date: Wed, 1 Feb 2023 13:52:16 +0100 Subject: [PATCH 6/6] Update gcconfig.h --- include/private/gcconfig.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 87f95a35f..c33eda90f 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -3199,7 +3199,7 @@ EXTERN_C_BEGIN #ifndef PREFETCH # if GC_GNUC_PREREQ(3, 0) && !defined(NO_PREFETCH) # define PREFETCH(x) __builtin_prefetch((x), 0, 0) -# elif defined(_MSC_VER) && !defined(NO_PREFETCH) +# elif defined(_MSC_VER) && !defined(NO_PREFETCH) && !defined(_M_ARM) && !defined(_M_ARM64) # define PREFETCH(x) _mm_prefetch((x), _MM_HINT_T0) # else # define PREFETCH(x) (void)0 @@ -3209,7 +3209,7 @@ EXTERN_C_BEGIN #ifndef GC_PREFETCH_FOR_WRITE # if GC_GNUC_PREREQ(3, 0) && !defined(GC_NO_PREFETCH_FOR_WRITE) # define GC_PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1) -# elif defined(_MSC_VER) && !defined(GC_NO_PREFETCH_FOR_WRITE) +# elif defined(_MSC_VER) && !defined(GC_NO_PREFETCH_FOR_WRITE) && !defined(_M_ARM) && !defined(_M_ARM64) # define GC_PREFETCH_FOR_WRITE(x) _mm_prefetch((x), _MM_HINT_T0) # else # define GC_PREFETCH_FOR_WRITE(x) (void)0