From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7803) id 8CECB3857BBC; Thu, 30 Nov 2023 07:55:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CECB3857BBC Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nelson Chu To: bfd-cvs@sourceware.org Subject: [binutils-gdb] RISC-V: Avoid updating state until symbol is found X-Act-Checkin: binutils-gdb X-Git-Author: Patrick O'Neill X-Git-Refname: refs/heads/master X-Git-Oldrev: dd2947e76aa285a12aa26de63a59f5fb8092ef82 X-Git-Newrev: 460e0e6e3e6c23ed5f4b70e1b86435f58cb890aa Message-Id: <20231130075509.8CECB3857BBC@sourceware.org> Date: Thu, 30 Nov 2023 07:55:09 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Nov 2023 07:55:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D460e0e6e3e6c= 23ed5f4b70e1b86435f58cb890aa commit 460e0e6e3e6c23ed5f4b70e1b86435f58cb890aa Author: Patrick O'Neill Date: Wed Nov 29 19:55:20 2023 -0800 RISC-V: Avoid updating state until symbol is found =20 Currently objdump gets and updates the map state once per symbol. Updat= ing the state (partiularly riscv_parse_subset) is expensive and grows quadratic= ally since we iterate over all symbols. By deferring this until once we've f= ound the symbol of interest, we can reduce the time to dump a 4k insn file of .n= orvc and .rvc insns from ~47 seconds to ~0.13 seconds. =20 opcodes/ChangeLog: =20 * 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. =20 Signed-off-by: Patrick O'Neill Diff: --- 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; } =20 -/* 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. */ =20 -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; =20 /* If the symbol is in a different section, ignore it. */ if (info->section !=3D NULL && info->section !=3D info->symtab[n]->section) - return false; + return; =20 name =3D bfd_asymbol_name(info->symtab[n]); if (strcmp (name, "$x") =3D=3D 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 !=3D NULL + && info->section !=3D info->symtab[n]->section) return false; =20 - return true; + name =3D bfd_asymbol_name(info->symtab[n]); + return (strcmp (name, "$x") =3D=3D 0 + || strcmp (name, "$d") =3D=3D 0 + || strncmp (name, "$xrv", 4) =3D=3D 0); } =20 /* 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 =3D n; found =3D 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 =3D n; found =3D true; @@ -1013,6 +1029,8 @@ riscv_search_mapping_symbol (bfd_vma memaddr, =20 if (found) { + riscv_update_map_state (symbol, &mstate, info); + /* Find the next mapping symbol to determine the boundary of this ma= pping symbol. */ =20 @@ -1068,11 +1086,12 @@ riscv_data_length (bfd_vma memaddr, { bfd_vma addr =3D 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 =3D addr - memaddr; found =3D true; + riscv_update_map_state (n, &m, info); break; } }