From 061484434eb09a80f872cab0e173847668b46e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Tue, 6 Jan 2015 02:27:16 +0000 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ lib/count-leading-zeros.h | 5 +++++ lib/count-one-bits.h | 4 ++++ lib/count-trailing-zeros.h | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 938e031..3b08279 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-01-06 Pádraig Brady + + 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. + 2015-01-04 Benno Schulenberg maint: fix grammar nits in propername (trivial change) diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 722615f..9e72fff 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 d54397f..bd79fc5 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 83ce2fb..1e71977 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 -- 2.1.0