/* Operations on HOST_WIDE_INT.
- Copyright (C) 1987-2015 Free Software Foundation, Inc.
+ Copyright (C) 1987-2020 Free Software Foundation, Inc.
This file is part of GCC.
#include "config.h"
#include "system.h"
-#include "diagnostic-core.h"
+#include "coretypes.h"
#if GCC_VERSION < 3004
return -1;
if (HOST_BITS_PER_WIDE_INT > 64)
- if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
+ if (x >= HOST_WIDE_INT_1U << (t + 64))
t += 64;
if (HOST_BITS_PER_WIDE_INT > 32)
- if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
+ if (x >= HOST_WIDE_INT_1U << (t + 32))
t += 32;
- if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
+ if (x >= HOST_WIDE_INT_1U << (t + 16))
t += 16;
- if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
+ if (x >= HOST_WIDE_INT_1U << (t + 8))
t += 8;
- if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
+ if (x >= HOST_WIDE_INT_1U << (t + 4))
t += 4;
- if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
+ if (x >= HOST_WIDE_INT_1U << (t + 2))
t += 2;
- if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
+ if (x >= HOST_WIDE_INT_1U << (t + 1))
t += 1;
return t;
}
-/* Given X, an unsigned number, return the largest Y such that 2**Y >= X. */
+/* Given X, an unsigned number, return the least Y such that 2**Y >= X. */
int
ceil_log2 (unsigned HOST_WIDE_INT x)
{
- return floor_log2 (x - 1) + 1;
+ return x == 0 ? 0 : floor_log2 (x - 1) + 1;
}
/* Return the logarithm of X, base 2, considering X unsigned,
int
exact_log2 (unsigned HOST_WIDE_INT x)
{
- if (x != (x & -x))
+ if (!pow2p_hwi (x))
return -1;
return floor_log2 (x);
}
int
ctz_hwi (unsigned HOST_WIDE_INT x)
{
- return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
+ return x ? floor_log2 (least_bit_hwi (x)) : HOST_BITS_PER_WIDE_INT;
}
/* Similarly for most significant bits. */
int
ffs_hwi (unsigned HOST_WIDE_INT x)
{
- return 1 + floor_log2 (x & -x);
+ return 1 + floor_log2 (least_bit_hwi (x));
}
/* Return the number of set bits in X. */