From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Tue, 10 Nov 2020 23:18:40 -0000 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