summaryrefslogtreecommitdiff
path: root/gtk/gtkcssselector.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2015-09-23 11:01:46 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2015-09-23 13:58:50 +0100
commita080cb40b90e9893fd9dd0c47367808744c17e22 (patch)
tree4e5fd0582e607cd54fae30e0704ec8969f948641 /gtk/gtkcssselector.c
parent3c54fbd3acb572d8b7e6022bc3de496689a9bb62 (diff)
downloadgtk+-a080cb40b90e9893fd9dd0c47367808744c17e22.tar.gz
Improve compiler detection for __builtin_popcount()
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
Diffstat (limited to 'gtk/gtkcssselector.c')
-rw-r--r--gtk/gtkcssselector.c11
1 files changed, 10 insertions, 1 deletions
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 <intrin.h>
+# 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;