diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2020-12-09 15:48:09 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2020-12-09 16:06:52 +0000 |
commit | b8a651df4782d790130c73e8c5fe70154ff7e11b (patch) | |
tree | 7ff91dbf5b5bba5a901d158a72038a979a2db799 /gtk/gtkcssenumvalue.c | |
parent | c5dd34344f0c660ceffffb3bf9da43c263db16e1 (diff) | |
download | gtk+-b8a651df4782d790130c73e8c5fe70154ff7e11b.tar.gz |
Share the popcount() fallback for MSVC
We use __builtin_popcount() in a couple of places, so it makes sense to
have it in one header.
Diffstat (limited to 'gtk/gtkcssenumvalue.c')
-rw-r--r-- | gtk/gtkcssenumvalue.c | 53 |
1 files changed, 9 insertions, 44 deletions
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c index 82d5580773..9bd29e3742 100644 --- a/gtk/gtkcssenumvalue.c +++ b/gtk/gtkcssenumvalue.c @@ -24,9 +24,7 @@ #include "gtkstyleproviderprivate.h" #include "gtksettingsprivate.h" -#ifdef _MSC_VER -# include <intrin.h> -#endif +#include "gtkpopcountprivate.h" /* repeated API */ @@ -1453,39 +1451,6 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_EAST_ASIAN = { gtk_css_font_variant_east_asian_value_print }; -#ifdef _MSC_VER -/* __builtin_popcount is a GCC-only function - so we need to define it for ourselves somehow */ - -static inline guint -__msvc_compat_popcnt (guint32 value) -{ - static gssize popcnt_checked = 0; - static gboolean have_popcnt = FALSE; - -# if defined (_M_AMD64) || defined (_M_X64) || (_M_IX86) - if (g_once_init_enter (&popcnt_checked)) - { - int cpuinfo[4] = {-1}; - - __cpuid (cpuinfo, 1); - have_popcnt = (cpuinfo[2] & 0x00800000) != 0; - g_once_init_leave (&popcnt_checked, 1); - } -# endif - - if (have_popcnt) - return __popcnt (value); - else - /* http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel */ - return (((value & 0xfff) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f) + - ((((value & 0xfff000) >> 12) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f) + - (((value >> 24) * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f); -} - -# define __builtin_popcount(v) __msvc_compat_popcnt(v) -#endif - static gboolean east_asian_value_is_valid (GtkCssFontVariantEastAsian east_asian) { @@ -1493,16 +1458,16 @@ east_asian_value_is_valid (GtkCssFontVariantEastAsian east_asian) (east_asian != GTK_CSS_FONT_VARIANT_EAST_ASIAN_NORMAL)) return FALSE; - if (__builtin_popcount (east_asian & (GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS78 | - GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS83 | - GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS90 | - GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS04 | - GTK_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED | - GTK_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL)) > 1) + if (gtk_popcount (east_asian & (GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS78 | + GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS83 | + GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS90 | + GTK_CSS_FONT_VARIANT_EAST_ASIAN_JIS04 | + GTK_CSS_FONT_VARIANT_EAST_ASIAN_SIMPLIFIED | + GTK_CSS_FONT_VARIANT_EAST_ASIAN_TRADITIONAL)) > 1) return FALSE; - if (__builtin_popcount (east_asian & (GTK_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH | - GTK_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL)) > 1) + if (gtk_popcount (east_asian & (GTK_CSS_FONT_VARIANT_EAST_ASIAN_FULL_WIDTH | + GTK_CSS_FONT_VARIANT_EAST_ASIAN_PROPORTIONAL)) > 1) return FALSE; return TRUE; |