From a080cb40b90e9893fd9dd0c47367808744c17e22 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 23 Sep 2015 11:01:46 +0100 Subject: [PATCH] Improve compiler detection for __builtin_popcount() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The popcount builtin was added in GCC after version 4.2 (which is what some *BSDs are using), which means we need to be more specific when using it than just asking for GCC. While we're at it, we can improve the compiler detection, and use a builtin popcount on Clang ≥ 3.1 and MSVC 2008. https://bugzilla.gnome.org/show_bug.cgi?id=755455 --- gtk/gtkcssselector.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c index 66ab936886..f252bbc7b6 100644 --- a/gtk/gtkcssselector.c +++ b/gtk/gtkcssselector.c @@ -25,6 +25,11 @@ #include "gtkcssprovider.h" #include "gtkstylecontextprivate.h" +#if defined(_MSC_VER) && _MSC_VER > 1500 +# include +# define __builtin_popcount(n) __popcount(n) +#endif + typedef struct _GtkCssSelectorClass GtkCssSelectorClass; typedef gboolean (* GtkCssSelectorForeachFunc) (const GtkCssSelector *selector, const GtkCssMatcher *matcher, @@ -749,7 +754,11 @@ gtk_css_selector_region_get_change (const GtkCssSelector *selector, GtkCssChange static inline guint count_bits (guint n) { -#if defined(__GNUC__) +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) + return (guint) __builtin_popcount (n); +#elif defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) + return (guint) __builtin_popcount (n); +#elif defined(_MSC_VER) && _MSC_VER > 1500 return (guint) __builtin_popcount (n); #else guint result = 0;