]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/hwint.c
[Ada] Two typo fixes
[thirdparty/gcc.git] / gcc / hwint.c
index 2d1b248c2edc7a48280ef43ce5899e4444d4b0da..31da90350f81fec5345b75010a27d828a5bd099a 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
 
@@ -19,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
 
@@ -41,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,
@@ -74,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);
 }
@@ -85,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.  */
@@ -102,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.  */