Move uinteger_pow gdb/valarith.c to gdb/utils.c and make it public
authorJoel Brobecker <brobecker@adacore.com>
Sun, 15 Nov 2020 08:10:52 +0000 (03:10 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Sun, 15 Nov 2020 08:10:52 +0000 (03:10 -0500)
This is a generic function which I would like to use in a followup
patch adding support for fixed-point types. So this commit moves it
out of valarith.c into util.c, and makes it non-static.

gdb/ChangeLog:

        * utils.h (uinteger_pow): Add declaration.
        * utils.c (uinteger_pow): Moved here (without changes)...
        * valarith.c (uinteger_pow): ... from here.

gdb/ChangeLog
gdb/utils.c
gdb/utils.h
gdb/valarith.c

index a0291092e29e538bc06c409cd0c259678cba2ae1..5aacbf057f24a23642291619b127408cc1f0258d 100644 (file)
@@ -1,3 +1,9 @@
+2020-11-15  Joel Brobecker  <brobecker@adacore.com>
+
+       * utils.h (uinteger_pow): Add declaration.
+       * utils.c (uinteger_pow): Moved here (without changes)...
+       * valarith.c (uinteger_pow): ... from here.
+
 2020-11-15  Joel Brobecker  <brobecker@adacore.com>
 
        * gmp-utils.h,  gmp-utils.h: New file.
index ab931c3a9c372d6731b58cd5625f78c951a7bc40..3226656e2c32548f83e581195cb543fbae769e25 100644 (file)
@@ -709,6 +709,36 @@ myread (int desc, char *addr, int len)
   return orglen;
 }
 
+/* See utils.h.  */
+
+ULONGEST
+uinteger_pow (ULONGEST v1, LONGEST v2)
+{
+  if (v2 < 0)
+    {
+      if (v1 == 0)
+       error (_("Attempt to raise 0 to negative power."));
+      else
+       return 0;
+    }
+  else
+    {
+      /* The Russian Peasant's Algorithm.  */
+      ULONGEST v;
+
+      v = 1;
+      for (;;)
+       {
+         if (v2 & 1L)
+           v *= v1;
+         v2 >>= 1;
+         if (v2 == 0)
+           return v;
+         v1 *= v1;
+       }
+    }
+}
+
 void
 print_spaces (int n, struct ui_file *file)
 {
index 6948908a317259647c2053bc5d18a9ebe2bec586..a8c65ed81706b5d1266ff4b9d32ec9f0c857f003 100644 (file)
@@ -593,6 +593,13 @@ extern pid_t wait_to_die_with_timeout (pid_t pid, int *status, int timeout);
 
 extern int myread (int, char *, int);
 
+/* Integer exponentiation: Return V1**V2, where both arguments
+   are integers.
+
+   Requires V1 != 0 if V2 < 0.
+   Returns 1 for 0 ** 0.  */
+extern ULONGEST uinteger_pow (ULONGEST v1, LONGEST v2);
+
 /* Resource limits used by getrlimit and setrlimit.  */
 
 enum resource_limit_kind
index 21b597a1b7a3ef0f699c640e7427a8c7a647b71e..f6caf3d18044d44e03acb69054c21edecc42b2b8 100644 (file)
@@ -819,37 +819,6 @@ integer_pow (LONGEST v1, LONGEST v2)
     }
 }
 
-/* Integer exponentiation: V1**V2, where both arguments are
-   integers.  Requires V1 != 0 if V2 < 0.  Returns 1 for 0 ** 0.  */
-
-static ULONGEST
-uinteger_pow (ULONGEST v1, LONGEST v2)
-{
-  if (v2 < 0)
-    {
-      if (v1 == 0)
-       error (_("Attempt to raise 0 to negative power."));
-      else
-       return 0;
-    }
-  else 
-    {
-      /* The Russian Peasant's Algorithm.  */
-      ULONGEST v;
-      
-      v = 1;
-      for (;;)
-       {
-         if (v2 & 1L) 
-           v *= v1;
-         v2 >>= 1;
-         if (v2 == 0)
-           return v;
-         v1 *= v1;
-       }
-    }
-}
-
 /* Obtain argument values for binary operation, converting from
    other types if one of them is not floating point.  */
 static void
This page took 0.03855 seconds and 4 git commands to generate.