From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6259 invoked by alias); 21 Jun 2018 14:00:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 6107 invoked by uid 89); 21 Jun 2018 14:00:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.2 spammy=nits X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Jun 2018 14:00:00 +0000 Received: from ESESBMB504.ericsson.se (Unknown_Domain [153.88.183.117]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id AA.1C.02679.D5FAB2B5; Thu, 21 Jun 2018 15:59:57 +0200 (CEST) Received: from ESESBMB503.ericsson.se (153.88.183.170) by ESESBMB504.ericsson.se (153.88.183.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 21 Jun 2018 15:59:57 +0200 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB503.ericsson.se (153.88.183.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Thu, 21 Jun 2018 15:59:57 +0200 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from [142.133.60.192] (192.75.88.130) by SN6PR15MB2400.namprd15.prod.outlook.com (2603:10b6:805:24::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.19; Thu, 21 Jun 2018 13:59:54 +0000 Subject: Re: [PATCH v2 2/3] Avoid memcpys in regcache read_part/write_part for full registers. To: Alan Hayward , CC: References: <20180621093802.79342-1-alan.hayward@arm.com> <20180621093802.79342-3-alan.hayward@arm.com> From: Simon Marchi Message-ID: <59b4e783-0cc5-5f75-61bf-56c9fe640ffa@ericsson.com> Date: Thu, 21 Jun 2018 14:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180621093802.79342-3-alan.hayward@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SN4PR0801CA0018.namprd08.prod.outlook.com (2603:10b6:803:29::28) To SN6PR15MB2400.namprd15.prod.outlook.com (2603:10b6:805:24::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34048f6c-7665-49c7-a440-08d5d77f4474 X-MS-TrafficTypeDiagnostic: SN6PR15MB2400: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Forefront-PRVS: 07106EF9B9 Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2018 13:59:54.8353 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34048f6c-7665-49c7-a440-08d5d77f4474 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR15MB2400 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes X-SW-Source: 2018-06/txt/msg00517.txt.bz2 On 2018-06-21 05:38 AM, Alan Hayward wrote: > Additionally, tidy up the functions: Remove asserts, use gdb_byte, > update comments. Thanks, that's a nice cleanup. Just two nits, the patch LGTM with those fixed. > diff --git a/gdb/regcache.c b/gdb/regcache.c > index 6276b149a2..fe4742c2ee 100644 > --- a/gdb/regcache.c > +++ b/gdb/regcache.c > @@ -775,77 +775,75 @@ regcache::cooked_write (int regnum, const gdb_byte *buf) > regnum, buf); > } > > -/* Perform a partial register transfer using a read, modify, write > - operation. */ > +/* See regcache.h. */ > > enum register_status > -readable_regcache::read_part (int regnum, int offset, int len, void *in, > - bool is_raw) > +readable_regcache::read_part (int regnum, int offset, int len, > + gdb_byte *out, bool is_raw) > { > - struct gdbarch *gdbarch = arch (); > - gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum)); > + int reg_size = register_size (arch (), regnum); > > - gdb_assert (in != NULL); > - gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]); > - gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]); > - /* Something to do? */ > - if (offset + len == 0) > + gdb_assert (out != NULL); > + gdb_assert (offset >= 0 && len >= 0 && offset + len <= reg_size); > + > + if (offset == 0 && len == 0) > return REG_VALID; > - /* Read (when needed) ... */ > + > + if (offset == 0 && len == reg_size) > + return (is_raw) ? raw_read (regnum, out) : cooked_read (regnum, out); Could you add some comments to help the reader quickly know what's going on? Something like: if (offset == 0 && len == 0) { /* We don't read anything at all. */ return REG_VALID; } if (offset == 0 && len == reg_size) { /* We read the whole register. */ return (is_raw) ? raw_read (regnum, out) : cooked_read (regnum, out); } /* We read only part of the register. */ Same for write_part. > @@ -355,9 +358,10 @@ private: > int regnum, const void *in_buf, > void *out_buf, size_t size) const; > > + /* Perform a partial register transfer using a read, modify, write > + operation. */ > enum register_status write_part (int regnum, int offset, int len, > - const void *out, bool is_raw); > - > + const gdb_byte *out, bool is_raw); Rename out to in? Thanks, Simon