summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-01-06 02:27:16 +0000
committerPádraig Brady <P@draigBrady.com>2015-01-06 10:19:32 +0000
commitdf7ede08f08348a791ebaadafaa963ed804a725d (patch)
tree03f9b2daf1d00f875caa1730d74d310c58ae7731 /lib
parent257752a173c30b75018c9a6df1a8739010e6f4b3 (diff)
downloadgnulib-df7ede08f08348a791ebaadafaa963ed804a725d.tar.gz
count-leading-zeros: avoid 64-bit intrinsics on 32-bit Windows
* lib/count-leading-zeros.h (count_leading_zeros_ll): Use 32 bit intrinsics in this case. * lib/count-trailing-zeros.h: Likewise. * lib/count-one-bits.h: Likewise.
Diffstat (limited to 'lib')
-rw-r--r--lib/count-leading-zeros.h5
-rw-r--r--lib/count-one-bits.h4
-rw-r--r--lib/count-trailing-zeros.h5
3 files changed, 14 insertions, 0 deletions
diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h
index 722615f9b5..9e72fffe1f 100644
--- a/lib/count-leading-zeros.h
+++ b/lib/count-leading-zeros.h
@@ -104,8 +104,13 @@ count_leading_zeros_l (unsigned long int x)
COUNT_LEADING_ZEROS_INLINE int
count_leading_zeros_ll (unsigned long long int x)
{
+# if _MSC_VER && ! defined _M_X64
+ int count = count_leading_zeros (x >> 31 >> 1);
+ return count < 32 ? count : 32 + count_leading_zeros (x);
+# else
COUNT_LEADING_ZEROS (__builtin_clzll, _BitScanReverse64,
unsigned long long int);
+# endif
}
#endif
diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h
index d54397f5fa..bd79fc5609 100644
--- a/lib/count-one-bits.h
+++ b/lib/count-one-bits.h
@@ -127,7 +127,11 @@ count_one_bits_l (unsigned long int x)
COUNT_ONE_BITS_INLINE int
count_one_bits_ll (unsigned long long int x)
{
+# if _MSC_VER && ! defined _M_X64
+ return count_one_bits (x >> 31 >> 1) + count_one_bits (x);
+# else
COUNT_ONE_BITS (__builtin_popcountll, __popcnt64, unsigned long long int);
+# endif
}
#endif
diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h
index 83ce2fbe26..1e71977fab 100644
--- a/lib/count-trailing-zeros.h
+++ b/lib/count-trailing-zeros.h
@@ -96,8 +96,13 @@ count_trailing_zeros_l (unsigned long int x)
COUNT_TRAILING_ZEROS_INLINE int
count_trailing_zeros_ll (unsigned long long int x)
{
+# if _MSC_VER && ! defined _M_X64
+ int count = count_trailing_zeros (x);
+ return count < 32 ? count : 32 + count_trailing_zeros (x >> 31 >> 1);
+# else
COUNT_TRAILING_ZEROS (__builtin_ctzll, _BitScanForward64,
unsigned long long int);
+# endif
}
#endif