[gtk+] Improve compiler detection for __builtin_popcount()
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Improve compiler detection for __builtin_popcount()
- Date: Wed, 23 Sep 2015 13:00:53 +0000 (UTC)
commit a080cb40b90e9893fd9dd0c47367808744c17e22
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Sep 23 11:01:46 2015 +0100
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
gtk/gtkcssselector.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 66ab936..f252bbc 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]