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
This commit is contained in:
Emmanuele Bassi 2015-09-23 11:01:46 +01:00
parent 3c54fbd3ac
commit a080cb40b9

View File

@ -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;