summaryrefslogtreecommitdiff
path: root/src/random_deviate.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-02-19 16:02:44 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-02-19 16:02:44 +0000
commit67bdf2071cdac915de2ea352ffdeb6796d04bd7a (patch)
treedd08eb06c19b8241510e06aad699f072dee0bddb /src/random_deviate.c
parent18fa464c7f2d8f71cafba62da7cd67468aeeb3ec (diff)
downloadmpfr-67bdf2071cdac915de2ea352ffdeb6796d04bd7a.tar.gz
[src/random_deviate.c] don't compile alternate code if not needed
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12315 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/random_deviate.c')
-rw-r--r--src/random_deviate.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/random_deviate.c b/src/random_deviate.c
index a45a7ead6..1b2c9ceee 100644
--- a/src/random_deviate.c
+++ b/src/random_deviate.c
@@ -172,12 +172,13 @@ random_deviate_generate (mpfr_random_deviate_t x, mpfr_random_size_t k,
}
}
+#if MPFR_LIMB_MAX >= ULONG_MAX
/*
* return index [-1..127] of highest bit set. Return -1 if x = 0, 2 if x = 4,
* etc. (From Algorithms for programmers by Joerg Arndt.)
*/
static int
-highest_bit_idx_alt (unsigned long x)
+highest_bit_idx (unsigned long x)
{
int r = 0;
@@ -198,7 +199,7 @@ highest_bit_idx_alt (unsigned long x)
if (x & 0x00000002UL) { r += 1; }
return r;
}
-
+#else
/*
* return index [-1..63] of highest bit set.
* Return -1 if x = 0, 63 is if x = ~0 (for 64-bit unsigned long).
@@ -207,20 +208,15 @@ highest_bit_idx_alt (unsigned long x)
static int
highest_bit_idx (unsigned long x)
{
- /* this test should be evaluated at compile time */
- if (sizeof (mp_limb_t) >= sizeof (unsigned long))
- {
- int cnt;
+ int cnt;
- if (x == 0)
- return -1;
- count_leading_zeros (cnt, (mp_limb_t) x);
- MPFR_ASSERTD (cnt <= GMP_NUMB_BITS - 1);
- return GMP_NUMB_BITS - 1 - cnt;
- }
- else
- return highest_bit_idx_alt (x);
+ if (x == 0)
+ return -1;
+ count_leading_zeros (cnt, (mp_limb_t) x);
+ MPFR_ASSERTD (cnt <= GMP_NUMB_BITS - 1);
+ return GMP_NUMB_BITS - 1 - cnt;
}
+#endif
/* return position of leading bit, counting from 1 */
static mpfr_random_size_t