From 17635a714b8c242127460aafc68a5a79bd141c3a Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Sat, 27 Apr 2019 18:57:17 -0700 Subject: [PATCH] Remove libgcc_s_seh-1.dll dependency when targeting Win32 with gcc. (mono/mono#14251) Don't use popcount intrinsic. Alternative but not exactly contradictory to https://github.com/mono/mono/pull/14248. Note that this is a single inlinable instruction on x86, if you assume at least SSE4 from circa 2007, which I am avoiding here. Commit migrated from https://github.com/mono/mono/commit/90a91429ae75240b4d0e791a563a9d553be09d56 --- src/mono/mono/sgen/sgen-marksweep.c | 4 +++- src/mono/mono/utils/monobitset.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/sgen/sgen-marksweep.c b/src/mono/mono/sgen/sgen-marksweep.c index c90c589..4ff3d2b 100644 --- a/src/mono/mono/sgen/sgen-marksweep.c +++ b/src/mono/mono/sgen/sgen-marksweep.c @@ -1544,7 +1544,9 @@ bitcount (mword d) { int count = 0; -#ifdef __GNUC__ +#if defined (__GNUC__) && !defined (HOST_WIN32) +// The builtins do work on Win32, but can cause a not worthwhile runtime dependency. +// See https://github.com/mono/mono/pull/14248. if (sizeof (mword) == 8) count += __builtin_popcountll (d); else diff --git a/src/mono/mono/utils/monobitset.c b/src/mono/mono/utils/monobitset.c index 944fae8..9d76038 100644 --- a/src/mono/mono/utils/monobitset.c +++ b/src/mono/mono/utils/monobitset.c @@ -201,14 +201,17 @@ mono_bitset_size (const MonoBitSet *set) { * \returns number of bits that are set. */ guint32 -mono_bitset_count (const MonoBitSet *set) { +mono_bitset_count (const MonoBitSet *set) +{ guint32 i, count; gsize d; count = 0; for (i = 0; i < set->size / BITS_PER_CHUNK; ++i) { d = set->data [i]; -#ifdef __GNUC__ +#if defined (__GNUC__) && !defined (HOST_WIN32) +// The builtins do work on Win32, but can cause a not worthwhile runtime dependency. +// See https://github.com/mono/mono/pull/14248. if (sizeof (gsize) == sizeof (unsigned int)) count += __builtin_popcount (d); else -- 2.7.4