/* Operations on HOST_WIDE_INT.
- Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
- 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
clz_hwi (unsigned HOST_WIDE_INT x)
{
- return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
+ return HOST_BITS_PER_WIDE_INT - 1 - floor_log2 (x);
}
/* Similar to ctz_hwi, except that the least significant bit is numbered
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. */
#endif /* GCC_VERSION < 3004 */
-/* Compute the absolute value of X. */
-
-HOST_WIDE_INT
-abs_hwi (HOST_WIDE_INT x)
-{
- gcc_checking_assert (x != HOST_WIDE_INT_MIN);
- return x >= 0 ? x : -x;
-}
-
-/* Compute the absolute value of X as an unsigned type. */
-
-unsigned HOST_WIDE_INT
-absu_hwi (HOST_WIDE_INT x)
-{
- return x >= 0 ? (unsigned HOST_WIDE_INT)x : -(unsigned HOST_WIDE_INT)x;
-}
/* Compute the greatest common divisor of two numbers A and B using
Euclid's algorithm. */