From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 82CA23858D33 for ; Wed, 22 Nov 2023 01:35:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82CA23858D33 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 82CA23858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700616938; cv=none; b=C/YpiplbxxGao96gQ+gl3uwAgT/KC2sHgAL2Koc8e4L2PA3eRrmarytiok46l+Ovox3ZhB+MQHwuGawfYyn7v6vAoG1ePEo+fLg4S/SJ0BR682722bQxNK8EHww4I3lROkjxFH3mELOmJmHW6qWUSR4qZKIP7c7y79+brHnMZqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700616938; c=relaxed/simple; bh=y+ptzrn+aRSbkp7CW2k1/GUdt+baZOnc6osrUVRR0cM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=B/RskL7maxx1ZLfls6umdvz2PtKZKOlTOjctta7hvb8YFnHMDtBfS1JqEgQvPKLMGWmomw8RyYx4/qIP7z9CBtd7cEbvJ1eHgeWP7YzN2dNpjy3EBmeE2iQ7/CyrSRmjXQ9dStHmC6rASng4Z+uiKFf6AG88DglKt8SuDvJo52U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5bcfc508d14so4860547a12.3 for ; Tue, 21 Nov 2023 17:35:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700616934; x=1701221734; 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=xUb7VzE/lCif4vEn/0c3X99DO6Jcwcdxq2BigqL82/Q=; b=tj/FyY1YW6WVJTegu2GBqHxNTF9y/acyDWyUWVDIzUoZ4ctwUp79ywZ1bvV6RemHwl cY87ezhEZDGXWPo12NqO03R6zGx4zigI8GmezJVBAeorHQ7WaCUaYop0x07TDgi24HFT 8vWlDfdpnb4YbkAVokTctDe69chTptQups3GC1wYfTkbFH2nxkRNZk9T1B2zFjHsVmYi nEpYqa9xsrXN7toQ6xaZhT4lc7dNIQB4Lg5JzNXQ2vlgI8z/nhmXkwBKL3cembz1HPQC PG8q3Ra8pXIPhEQJQWtrUBoqW1WfKnyHW0p4W/ERkdiSkjFAhzbrDI3u7BZnKD527bQ2 WIvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700616934; x=1701221734; 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=xUb7VzE/lCif4vEn/0c3X99DO6Jcwcdxq2BigqL82/Q=; b=jm/L7GNEH7cjFOSnzPi1sefDLiP4exHUFRz4j8c7zSY352aZzUsWmSvMYsD9AyDJ7C WZJoybp3UnsijWsHJ8syipoGqSf5Qlc0G1xCjgXBcH8cXbWIM9y9R+OEE9NBVsly7rRV 22i4y5oOCHpQOfBbqeIte+jrUsDKCWaVbBkE3Ux3LN/U0msylZFE0pSfHv3b7w3n7oOF QdNzfT96ZXREX7f9b17lT0lCNLOpPGQ/VrNE/GKQcv/fPrt9XR5/LAi06VQSLtk5s+BP Z/H7MN/KGJRTuDo2z1e8qN6MacQtvgy5boobMWifvIAPeVhv4IsnXz91Vk8UnPCWqEqu K1CQ== X-Gm-Message-State: AOJu0Ywohybol6/SQEcmGxtlP4tbunlfpsaXksVdQdkW/h5mBUaqOzfs ed0fGUs+5SMNclosZFV333ToDh6VRpunH62FAQ2jyQ== X-Google-Smtp-Source: AGHT+IF+CjIx5E2gVKwj075gRibcZD1/evR4t9KF8gD+MwUdAdMnmozky1ftaCiB7pW3iwxZPtFLNA== X-Received: by 2002:a05:6a20:e11f:b0:188:290f:3da6 with SMTP id kr31-20020a056a20e11f00b00188290f3da6mr958564pzb.41.1700616933702; Tue, 21 Nov 2023 17:35:33 -0800 (PST) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id t13-20020a056a00138d00b006cb7c49c5e5sm5249694pfg.132.2023.11.21.17.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 17:35:33 -0800 (PST) From: Patrick O'Neill To: binutils@sourceware.org Cc: kito.cheng@sifive.com, nelson@rivosinc.com, Patrick O'Neill Subject: [PATCH] RISC-V: Avoid updating state until symbol is found Date: Tue, 21 Nov 2023 17:35:11 -0800 Message-ID: <20231122013511.46088-1-patrick@rivosinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. (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 --- Somewhat related to: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c2f60ac565f1d369fde98146a16f1d3ef79e1000 Sequences of compressed/uncompressed insns have different isa strings, so the cache in that patch is not triggered. Thankfully we can just reduce the number of calls to fix this issue rather than create a new cache. --- opcodes/riscv-dis.c | 47 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index ca328b4c997..4ada1487732 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -860,20 +860,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) @@ -900,10 +900,27 @@ 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_get_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 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 @@ -972,6 +989,11 @@ riscv_search_mapping_symbol (bfd_vma memaddr, } } + if (found) + riscv_update_map_state (symbol, &mstate, info); + else + riscv_update_map_state (info->symtab_size - 1, &mstate, info); + /* We can not find the suitable mapping symbol above. Therefore, we look forwards and try to find it again, but don't go past the start of the section. Otherwise a data section without mapping symbols @@ -996,6 +1018,10 @@ riscv_search_mapping_symbol (bfd_vma memaddr, break; } } + if (found) + riscv_update_map_state (symbol, &mstate, info); + else + riscv_update_map_state (0, &mstate, info); } if (found) @@ -1060,9 +1086,12 @@ riscv_data_length (bfd_vma memaddr, if (addr - memaddr < length) length = addr - memaddr; found = true; + riscv_update_map_state (n, &m, info); break; } } + if (!found) + riscv_update_map_state (0, &m, info); } if (!found) { -- 2.34.1