From patchwork Thu Nov 30 03:55:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick O'Neill X-Patchwork-Id: 171728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp138726vqy; Wed, 29 Nov 2023 19:55:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFC1LFT+rOBRP282w6oRjRS+73adMPSlhMDKZRp8VxK4e4vBvXri//pLddDRmn8XkQWoXZI X-Received: by 2002:ac8:7d12:0:b0:423:792f:d5ca with SMTP id g18-20020ac87d12000000b00423792fd5camr27345459qtb.63.1701316543428; Wed, 29 Nov 2023 19:55:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701316543; cv=pass; d=google.com; s=arc-20160816; b=HELxg0HKSYe61SKIvQCswmVD1lnpijHnqmd0QRWz3YgyxMywnuiZHl+sntBgrqskgr f0vOvQTGnM6IQss1QFAYCQNFzXxDi5EDVciMMtM8KYPjao4RpEQJl1cYQpTFr54qD25T 2mV/dyzWVV5DktOBcvHqYbUqexuYa6Fkd8TA5BZpa2W7SRQQBTOVGbt0RbOREyuhNrRw 847n9t+Wws3/wayq15MphevUAs7T4oZUWIb1YhL0RqTAjf6Kftaf5JocvvXlGhIImKpC BXjwfnOM8ocXH6glRNIadX5ZpVrF7tYQU2uuJZbzOdvKWLOkc1p8JCsUPI7Atudslgkh JPJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=mht+vliACOR+1htTOYs6SSxN8McQU6X+ve/Vwdt65yk=; fh=OVIcoUdPNesMpLPgiX+pkFGeiMlGTPMvWoYEXxDxCCM=; b=mFsE527sXYR2iC1C/L8zPchtomz4sDvqoCWShribDRf9k66F1S63w1AniHsM/QxHWT w2MfTkdecwvShxhF+mMF1t9cMxFP/iqfjln+9bEma2fK2IbPFwu6xbANkbPju7qLCRcn 0Y12lcG6NocpuZnHQzl4u7JzBT5nloG/sLSS5KRuZU3n2aonps5zfFoPWYz8VpieYmUt /NQzXPnYJjwDWDyP0loNP4nibF/HHfz/aHGQ2y66Wn8EvsIkwdysSqy6aBf0VVJl2UrG jBxjva0PX7jAM9CS8ux9ZUfTnmYhc/gS/XtiTwMOhAFsrv6LN4I2mKV1ZdNHKGTtPBzR MBiQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=r6G1Vtvj; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ge10-20020a05622a5c8a00b0042398ddfec3si287636qtb.58.2023.11.29.19.55.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 19:55:43 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=r6G1Vtvj; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35F343858C2B for ; Thu, 30 Nov 2023 03:55:43 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by sourceware.org (Postfix) with ESMTPS id A3FDE3858D1E for ; Thu, 30 Nov 2023 03:55:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3FDE3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A3FDE3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701316539; cv=none; b=IepVj/CytqMPkkumYAcdnaC2WWUxIGw96ayKGgJkjgxXIjBlh6MPzdWBCNGmkU1OE3lwu6dOlzJNQTb5WQF1wkoy7W77boPEO9NSy4r3dsU4YoBgidhxL3CL9O494IzH6QtWZHoBd9vJHyBPkhim9H668IxZPLId7IbnUE5yYKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701316539; c=relaxed/simple; bh=d+cMMAY7do8yPINYrEPF0SF7Jxm6TXsKp79tt2K/8Io=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hv+V1rvEj6KRPqqY5GjD+AJ2CTEZ+hS61aMlQVqPRraRM8x6C7ObxleSDFs1z1BHzQoGc8FWCjP6bw9s3r0hRzhGvrnfdVIQu4OhTO/ojv6rDSDHNvM9qGZcYSXfNqBkS8Wx9W1B0cAqEa05J7VcJLhxsw40wAnQOmf66cpHDj0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-58d533268e6so320504eaf.1 for ; Wed, 29 Nov 2023 19:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1701316537; x=1701921337; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mht+vliACOR+1htTOYs6SSxN8McQU6X+ve/Vwdt65yk=; b=r6G1VtvjGhK91Hb7NvrWpne8j9b6colT7KhdhVR3fiIFdeuxKIe/T28JHmGqooX13u +z9yubKhsjWgQ4I0cqIhUGJf2gS/32MKt77fqMjk6am0GP1uAkWNjs124Fe+Db9oszhK E4prduFKrkUQ5+UTNGrzRxM6Q3ZVF1yId99Ye2OAc1DhYqfHMAjEvElZYjZy9m9TKaFt XygtR3S68MpWJ3k/O4epf+4PgbyXVA5tXV+ZGg9E9OUaE4FbGPnJUgwfrm+0xQQRwtVZ ToeWD2DCu9BEBWwL5pgd7wE11iwYqOX6QDs7DLqeYtt9OWuh6vTt+XENCN/ZyPaCzgPA MkLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701316537; x=1701921337; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mht+vliACOR+1htTOYs6SSxN8McQU6X+ve/Vwdt65yk=; b=ftM2qEaZEewvI+mPULmX0oQlITbTxAi/yE2ZJKLRzct/tcSPuaq2I50sPSDzdHAAnK FDkE9pJTxaoND/JTWJ2VLqT1NOVkz96zVmm4Jcdb0X88DIDnczhhpZMiEgwYw5F2pRqL SMOloaOAJPIerjz9qQ28B1RFFVV8YBNuuQWY7b6JJXZweUcbm9ks91nMFgWXUGOtPtJA JZzIYRJ4elCrx/Ir0HVHJNc7CSsiuwDUGXylfTrDlFIQkMQGmeyxII7IZzJiTOYufVWX QAbK6LB+kd6fyoHnH1/mEcYueFhYjAf4viai3XATAOugs2HwteUrNhvPZuXid/7ZPRms 9Xdg== X-Gm-Message-State: AOJu0YyX6k71I6NK+a9r9fACbN6FpDZzVGrNMLbDlH6/Gj2e9RoF3HoY mOnC20NWH3zsI03TAdj0b0mHMw== X-Received: by 2002:a05:6358:e48b:b0:16b:f704:15a0 with SMTP id by11-20020a056358e48b00b0016bf70415a0mr20361424rwb.8.1701316536869; Wed, 29 Nov 2023 19:55:36 -0800 (PST) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hsd1.ca.comcast.net ([2601:647:5700:6860:9340:ff6c:5ea9:271a]) by smtp.gmail.com with ESMTPSA id t10-20020a65608a000000b005acd5d7e11bsm178166pgu.35.2023.11.29.19.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 19:55:36 -0800 (PST) From: Patrick O'Neill To: nelson@rivosinc.com, binutils@sourceware.org Cc: kito.cheng@sifive.com, Patrick O'Neill Subject: [PATCH v3] RISC-V: Avoid updating state until symbol is found Date: Wed, 29 Nov 2023 19:55:20 -0800 Message-ID: <20231130035520.1369012-1-patrick@rivosinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783939984788255635 X-GMAIL-MSGID: 1783959695600225907 Currently objdump gets and updates the map state once per symbol. Updating the state (partiularly riscv_parse_subset) is expensive and grows quadratically since we iterate over all symbols. By deferring this until once we've found the symbol of interest, we can reduce the time to dump a 4k insn file of .norvc and .rvc insns from ~47 seconds to ~0.13 seconds. opcodes/ChangeLog: * riscv-dis.c (riscv_get_map_state): Remove state updating logic and rename to riscv_is_valid_mapping_symbol. (riscv_update_map_state): Add state updating logic to seperate function. (riscv_search_mapping_symbol): Use new riscv_update_map_state. (riscv_data_length): Ditto. Signed-off-by: Patrick O'Neill --- Re-tested using rv64gcv make report-linux and make report-binutils-linux. Binutils hash used/applied to: c618a1c548193d2a6a8c3d909a3d1c620a156b5d GCC hash used: eecdd96c8d1de244e21212a830e51062b3e444c5 v3 changelog: - Move and unify riscv_update_map_state calls into if (found) block v2 changelog: - Remove unneeded riscv_update_state calls on !found - Rename riscv_get_map_state -> riscv_is_valid_mapping_symbol --- opcodes/riscv-dis.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 6fa9855e3cd..f7f4c0750ed 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -873,20 +873,20 @@ riscv_disassemble_insn (bfd_vma memaddr, return insnlen; } -/* Return true if we find the suitable mapping symbol, - and also update the STATE. Otherwise, return false. */ +/* If we find the suitable mapping symbol update the STATE. + Otherwise, do nothing. */ -static bool -riscv_get_map_state (int n, - enum riscv_seg_mstate *state, - struct disassemble_info *info) +static void +riscv_update_map_state (int n, + enum riscv_seg_mstate *state, + struct disassemble_info *info) { const char *name; /* If the symbol is in a different section, ignore it. */ if (info->section != NULL && info->section != info->symtab[n]->section) - return false; + return; name = bfd_asymbol_name(info->symtab[n]); if (strcmp (name, "$x") == 0) @@ -913,10 +913,26 @@ riscv_get_map_state (int n, else riscv_parse_subset (&riscv_rps_dis, name + 2); } - else +} + +/* Return true if we find the suitable mapping symbol. + Otherwise, return false. */ + +static bool +riscv_is_valid_mapping_symbol (int n, + struct disassemble_info *info) +{ + const char *name; + + /* If the symbol is in a different section, ignore it. */ + if (info->section != NULL + && info->section != info->symtab[n]->section) return false; - return true; + name = bfd_asymbol_name(info->symtab[n]); + return (strcmp (name, "$x") == 0 + || strcmp (name, "$d") == 0 + || strncmp (name, "$xrv", 4) == 0); } /* Check the sorted symbol table (sorted by the symbol value), find the @@ -975,7 +991,7 @@ riscv_search_mapping_symbol (bfd_vma memaddr, /* We have searched all possible symbols in the range. */ if (addr > memaddr) break; - if (riscv_get_map_state (n, &mstate, info)) + if (riscv_is_valid_mapping_symbol (n, info)) { symbol = n; found = true; @@ -1002,7 +1018,7 @@ riscv_search_mapping_symbol (bfd_vma memaddr, if (addr < (info->section ? info->section->vma : 0)) break; /* Stop searching once we find the closed mapping symbol. */ - if (riscv_get_map_state (n, &mstate, info)) + if (riscv_is_valid_mapping_symbol (n, info)) { symbol = n; found = true; @@ -1013,6 +1029,8 @@ riscv_search_mapping_symbol (bfd_vma memaddr, if (found) { + riscv_update_map_state (symbol, &mstate, info); + /* Find the next mapping symbol to determine the boundary of this mapping symbol. */ @@ -1068,11 +1086,12 @@ riscv_data_length (bfd_vma memaddr, { bfd_vma addr = bfd_asymbol_value (info->symtab[n]); if (addr > memaddr - && riscv_get_map_state (n, &m, info)) + && riscv_is_valid_mapping_symbol (n, info)) { if (addr - memaddr < length) length = addr - memaddr; found = true; + riscv_update_map_state (n, &m, info); break; } }