From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UL02DH3osF/tOgAAWB0awg (envelope-from ) for ; Sun, 15 Nov 2020 03:36:13 -0500 Received: by simark.ca (Postfix, from userid 112) id 2D59F1F09B; Sun, 15 Nov 2020 03:36:13 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 636A61F08D for ; Sun, 15 Nov 2020 03:36:10 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C901388A409; Sun, 15 Nov 2020 08:36:10 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id D52A9388A404 for ; Sun, 15 Nov 2020 08:36:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D52A9388A404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=brobecke@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 64AED5604D; Sun, 15 Nov 2020 03:36:07 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4gYLzX6vIwzG; Sun, 15 Nov 2020 03:36:07 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 5593056011; Sun, 15 Nov 2020 03:36:07 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id 5402D111; Sun, 15 Nov 2020 03:36:07 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/v2 4/9] Move uinteger_pow gdb/valarith.c to gdb/utils.c and make it public Date: Sun, 15 Nov 2020 03:35:40 -0500 Message-Id: <1605429345-78384-5-git-send-email-brobecker@adacore.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1605429345-78384-1-git-send-email-brobecker@adacore.com> References: <1604817017-25807-1-git-send-email-brobecker@adacore.com> <1605429345-78384-1-git-send-email-brobecker@adacore.com> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Marchi , Joel Brobecker Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 | 6 ++++++ gdb/utils.c | 30 ++++++++++++++++++++++++++++++ gdb/utils.h | 7 +++++++ gdb/valarith.c | 31 ------------------------------- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a029109..5aacbf0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2020-11-15 Joel Brobecker + * 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 + * gmp-utils.h, gmp-utils.h: New file. * unittests/gmp-utils-selftests.c: New file. * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add diff --git a/gdb/utils.c b/gdb/utils.c index ab931c3..3226656 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) { diff --git a/gdb/utils.h b/gdb/utils.h index 6948908..a8c65ed 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -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 diff --git a/gdb/valarith.c b/gdb/valarith.c index 21b597a..f6caf3d 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -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 -- 2.1.4