]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/hwint.c
[Ada] Two typo fixes
[thirdparty/gcc.git] / gcc / hwint.c
index b7bcfa5974032ed08d59f70e55ce657be23d1e92..31da90350f81fec5345b75010a27d828a5bd099a 100644 (file)
@@ -1,7 +1,5 @@
 /* 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.
 
@@ -21,7 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "config.h"
 #include "system.h"
-#include "diagnostic-core.h"
+#include "coretypes.h"
 
 #if GCC_VERSION < 3004
 
@@ -43,31 +41,31 @@ floor_log2 (unsigned HOST_WIDE_INT x)
     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,
@@ -76,7 +74,7 @@ ceil_log2 (unsigned HOST_WIDE_INT x)
 int
 exact_log2 (unsigned HOST_WIDE_INT x)
 {
-  if (x != (x & -x))
+  if (!pow2p_hwi (x))
     return -1;
   return floor_log2 (x);
 }
@@ -87,7 +85,7 @@ exact_log2 (unsigned HOST_WIDE_INT 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.  */
@@ -95,7 +93,7 @@ ctz_hwi (unsigned HOST_WIDE_INT x)
 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
@@ -104,7 +102,7 @@ clz_hwi (unsigned HOST_WIDE_INT x)
 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.  */
@@ -126,22 +124,6 @@ popcount_hwi (unsigned HOST_WIDE_INT 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.  */