summaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2020-11-15 03:10:52 -0500
committerJoel Brobecker <brobecker@adacore.com>2020-11-15 03:10:52 -0500
commite55c6530dbf96bfbe2e4a232c0feb19c0a4a2294 (patch)
tree2924eba4d072b23919374e31ef15ac42b0e8024b /gdb/utils.c
parentb34c74ab9a6b8dc0ace3d0cc67bf62de8a74ea00 (diff)
downloadbinutils-gdb-e55c6530dbf96bfbe2e4a232c0feb19c0a4a2294.tar.gz
Move uinteger_pow gdb/valarith.c to gdb/utils.c and make it public
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.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index ab931c3a9c3..3226656e2c3 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -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)
{