From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 5GbNKdIfq1+yGwAAWB0awg (envelope-from ) for ; Tue, 10 Nov 2020 18:18:42 -0500 Received: by simark.ca (Postfix, from userid 112) id 9F2CC1F08B; Tue, 10 Nov 2020 18:18:42 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 48F961E58D for ; Tue, 10 Nov 2020 18:18:42 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9F753851C3C; Tue, 10 Nov 2020 23:18:41 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id F20EE385702C for ; Tue, 10 Nov 2020 23:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F20EE385702C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8334E1E58D; Tue, 10 Nov 2020 18:18:38 -0500 (EST) Subject: Re: [PATCH 8/9] Add support for fixed-point type arithmetic To: Joel Brobecker , gdb-patches@sourceware.org References: <1604817017-25807-1-git-send-email-brobecker@adacore.com> <1604817017-25807-9-git-send-email-brobecker@adacore.com> From: Simon Marchi Message-ID: <7ada7fe8-a3e7-6acd-20d7-e36ebb7da4ac@simark.ca> Date: Tue, 10 Nov 2020 18:18:38 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <1604817017-25807-9-git-send-email-brobecker@adacore.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2020-11-08 1:30 a.m., Joel Brobecker wrote: > diff --git a/gdb/valarith.c b/gdb/valarith.c > index f6caf3d..65a6f13 100644 > --- a/gdb/valarith.c > +++ b/gdb/valarith.c > @@ -881,6 +881,84 @@ value_args_as_target_float (struct value *arg1, struct value *arg2, > type2->name ()); > } > > +/* Assuming at last one of ARG1 or ARG2 is a fixed point value, > + perform the binary operation OP on these two operands, and return > + the resulting value (also as a fixed point). */ > + > +static struct value * > +fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) > +{ > + struct type *type1 = check_typedef (value_type (arg1)); > + struct type *type2 = check_typedef (value_type (arg2)); > + > + struct value *val; > + > + gdb_assert (is_fixed_point_type (type1) || is_fixed_point_type (type2)); > + if (!is_fixed_point_type (type1)) > + { > + arg1 = value_cast (type2, arg1); > + type1 = type2; > + } > + if (!is_fixed_point_type (type2)) > + { > + arg2 = value_cast (type1, arg2); > + type2 = type1; > + } > + > + gdb_mpq v1, v2, res; > + v1.read_fixed_point (value_contents (arg1), TYPE_LENGTH (type1), > + type_byte_order (type1), type1->is_unsigned (), > + fixed_point_scaling_factor (type1)); > + v2.read_fixed_point (value_contents (arg2), TYPE_LENGTH (type2), > + type_byte_order (type2), type2->is_unsigned (), > + fixed_point_scaling_factor (type2)); > + > +#define INIT_VAL_WITH_FIXED_POINT_VAL(RESULT) \ > + do { \ > + val = allocate_value (type1); \ > + (RESULT).write_fixed_point \ > + (value_contents_raw (val), TYPE_LENGTH (type1), \ > + type_byte_order (type1), type1->is_unsigned (), \ > + fixed_point_scaling_factor (type1)); \ > + } while (0) Can you use a lambda function instead of a macro? It's easier to debug and edit. Something like auto fixed_point_to_value = [type1] (const gdb_mpq &fp) { value *val_ = allocate_value (type1); fp.write_fixed_point (value_contents_raw (val_), TYPE_LENGTH (type1), type_byte_order (type1), type1->is_unsigned (), fixed_point_scaling_factor (type1)); return val_; }; and val = fixed_point_to_value (res); Simon