From 6835fcf3cf3b366823f39a2c2cf37090e07a962e Mon Sep 17 00:00:00 2001 From: scherek Date: Sat, 12 Jun 2021 16:18:26 +0200 Subject: [PATCH 1/4] Fix illegal instruction crash on x64 CPUs without POPCNT instruction when compiled with MSVC --- gtk/gtkpopcountprivate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtk/gtkpopcountprivate.h b/gtk/gtkpopcountprivate.h index df2282c985..3862f5cb24 100644 --- a/gtk/gtkpopcountprivate.h +++ b/gtk/gtkpopcountprivate.h @@ -20,7 +20,7 @@ #pragma once -#if defined(_MSC_VER) && !defined (_M_ARM) && !defined (_M_ARM64) +#if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) && defined(__AVX__) && defined(__SSE4_2__) && defined(__POPCNT__) #include static inline guint @@ -29,7 +29,7 @@ gtk_popcount (guint32 value) return __popcnt (value); } #elif defined(__GNUC__) || defined(__clang__) -# define gtk_popcount(v) __builtin_popcount(v) +#define gtk_popcount(v) __builtin_popcount (v) #else static inline guint gtk_popcount (guint32 value) From e5b89569fdf634ac3920e56d9a10aa2809a34849 Mon Sep 17 00:00:00 2001 From: scherek Date: Sat, 12 Jun 2021 17:32:19 +0200 Subject: [PATCH 2/4] Replaced && with || for POPCNT checks to fix the logic. --- gtk/gtkpopcountprivate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkpopcountprivate.h b/gtk/gtkpopcountprivate.h index 3862f5cb24..38c4d6f95e 100644 --- a/gtk/gtkpopcountprivate.h +++ b/gtk/gtkpopcountprivate.h @@ -20,7 +20,7 @@ #pragma once -#if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) && defined(__AVX__) && defined(__SSE4_2__) && defined(__POPCNT__) +#if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) && defined(__AVX__) || defined(__SSE4_2__) || defined(__POPCNT__) #include static inline guint From bc7b6a0e538ee661fae6db7e668a8bad4a42b91b Mon Sep 17 00:00:00 2001 From: scherek Date: Sat, 12 Jun 2021 19:10:11 +0200 Subject: [PATCH 3/4] Dropped defined() for readability --- gtk/gtkpopcountprivate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkpopcountprivate.h b/gtk/gtkpopcountprivate.h index 38c4d6f95e..e0eeb3fdf8 100644 --- a/gtk/gtkpopcountprivate.h +++ b/gtk/gtkpopcountprivate.h @@ -20,7 +20,7 @@ #pragma once -#if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) && defined(__AVX__) || defined(__SSE4_2__) || defined(__POPCNT__) +#if (_MSC_VER && !_M_ARM && !_M_ARM64) && (__AVX__ || __SSE4_2__ || __POPCNT__) #include static inline guint From 106ac7c782e2b502e4b6553dc0e6a623c9f1075c Mon Sep 17 00:00:00 2001 From: Sebastian Cherek Date: Sat, 12 Jun 2021 17:35:13 +0000 Subject: [PATCH 4/4] Update gtkpopcountprivate.h: undefined macro outside msvc --- gtk/gtkpopcountprivate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkpopcountprivate.h b/gtk/gtkpopcountprivate.h index e0eeb3fdf8..d2dff51990 100644 --- a/gtk/gtkpopcountprivate.h +++ b/gtk/gtkpopcountprivate.h @@ -20,7 +20,7 @@ #pragma once -#if (_MSC_VER && !_M_ARM && !_M_ARM64) && (__AVX__ || __SSE4_2__ || __POPCNT__) +#if (defined(_MSC_VER) && !_M_ARM && !_M_ARM64) && (__AVX__ || __SSE4_2__ || __POPCNT__) #include static inline guint