From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by sourceware.org (Postfix) with ESMTPS id 0C5D83858D28 for ; Tue, 18 Apr 2023 03:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C5D83858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-18777914805so1308897fac.1 for ; Mon, 17 Apr 2023 20:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681789385; x=1684381385; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=K2dtErg5qjozc5ar5OOlwgUxbnPgVoMpNHq4zVIgIIY=; b=at00OlboxUHeRZ934xUbdB4pzFoR8wRGRb8jW2FlDrozV8AG8ZiP3bsYZsRsvpfhoh xMS7mjO0grWVbjKnzf6izs4xcSbFmc7AvBgNri0cTEohuxkYpnkXPWSXhfPdFwcb0zAc 6lnGuS36Pi6L93Mx8I1gt3ZoKX+PuQDQ0yOPfKrAJMD3cJ1oe65xNIcSSdeL8SlncX/R s3Wz2SFUOqS2sVFb1/2MrI85hnmkbysf0hDMSoCE7feAFaOpLS2UaMJwkQNmwi9r5hU3 SJGvgn2bCnKeD9uZm3CIMFlvOqFD5+XXN68L/irzVDnqusnf2Iyuz7zTGfY1VrqbNBRh rYXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681789385; x=1684381385; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=K2dtErg5qjozc5ar5OOlwgUxbnPgVoMpNHq4zVIgIIY=; b=TSePIiJvskVNb0VT9QnEmJ1q173mUtwaifajVTc+Xenb+KrxUryxLNbREPj6koJ98V aPCf9FinI0FZ0A7ejwM6VWQhRmheXkCN+M91IRjtxg0Feqsukguo+1qBxedQF0cfM6Fw 64VOAEitKjgpCStSsOCTNjAcvaR6Si1UCiswOt5PS3oei1szm4/+DoCMuTTQOonPwjP6 jwsaTZoHsVGrN7QBykFRpC9T7Oy9o7/1F8HRppaK1vgSeidyTzUuBtNDkdFRXyvqvThk ruGLz6DXVvfiqrN8JgAMVILAxKcTHPOUmxOPevoqd22Iaz5fp1slD9wj8saOuZ3YBqQ2 HZKA== X-Gm-Message-State: AAQBX9c4kR+BM4wNOryHqpACH9N2peoTpCRyqGe0M+7cuDY7z1PGTIlz YovKJh05/tYH2T7KOLrwpgjrMgBOrC3FfADJ5gaUAA== X-Google-Smtp-Source: AKy350YdSq9iOIKIka+OMH8SsTJd05SELPitaOqhqTYNPwLVfPSyOStWlq0AtrzkwfxJNQllayxpcSBmR6aAJ/pE034= X-Received: by 2002:a05:6871:724:b0:188:a53:394a with SMTP id f36-20020a056871072400b001880a53394amr292460oap.5.1681789385304; Mon, 17 Apr 2023 20:43:05 -0700 (PDT) MIME-Version: 1.0 References: <20230417121633.68761-1-kito.cheng@sifive.com> In-Reply-To: <20230417121633.68761-1-kito.cheng@sifive.com> From: Nelson Chu Date: Tue, 18 Apr 2023 11:42:54 +0800 Message-ID: Subject: Re: [PATCH] RISC-V: Cache the latest mapping symbol and its boundary. To: Kito Cheng Cc: binutils@sourceware.org, kito.cheng@gmail.com, palmer@rivosinc.com Content-Type: multipart/alternative; boundary="000000000000e6063c05f9941ac6" X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,HTML_MESSAGE,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: --000000000000e6063c05f9941ac6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks, committed after passing gcc/binutils regression of riscv-gnu-toolchain. Nelson On Mon, Apr 17, 2023 at 8:16=E2=80=AFPM Kito Cheng = wrote: > This issue was reported from > https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1188 > > Current flow: > 1) Scan any mapping symbol less than this instruciton. > 2) If not found, did a backward search. > > The flow seems not big issue, let run an example here: > > $x: > 0x0 a <--- Found at step 1 > 0x4 b <--- Not found in step 1, but found at step 2 > 0x8 c <--- Not found in step 1, but found at step 2 > $d > 0x12 .word 1234 <-- Found at step 1 > > The instruciton didn't have the same address with mapping symbol will > still did backward search again and again. > > So the new flow is: > 1) Use the last mapping symbol status if the address is still within the > range > of the current mapping symbol. > 2) Scan any mapping symbol less than this instruciton. > 3) If not found, did a backward search. > 4) If a proper mapping symbol is found in either step 2 or 3, find its > boundary, > and cache that. > > Use the same example to run the new flow again: > > $x: > 0x0 a <--- Found at step 2, the boundary is 0x12 > 0x4 b <--- Cache hit at step 1, within the boundary. > 0x8 c <--- Cache hit at step 1, within the boundary. > $d > 0x12 .word 1234 <-- Found at step 2, the boundary is the end of section. > > The disassemble time of the test cases has been reduced from ~20 minutes > to ~4 > seconds. > > opcode/ChangeLog > PR 30282 > * riscv-dis.c (last_map_symbol_boundary): New. > (last_map_state): New. > (last_map_section): New. > (riscv_search_mapping_symbol): Cache the result of latest > mapping symbol. > --- > opcodes/riscv-dis.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c > index 3aaa45f419c..f25993d1e45 100644 > --- a/opcodes/riscv-dis.c > +++ b/opcodes/riscv-dis.c > @@ -64,6 +64,9 @@ struct riscv_private_data > /* Used for mapping symbols. */ > static int last_map_symbol =3D -1; > static bfd_vma last_stop_offset =3D 0; > +static bfd_vma last_map_symbol_boundary =3D 0; > +static enum riscv_seg_mstate last_map_state =3D MAP_NONE; > +static asection *last_map_section =3D NULL; > > /* Register names as used by the disassembler. */ > static const char * const *riscv_gpr_names; > @@ -868,6 +871,14 @@ riscv_search_mapping_symbol (bfd_vma memaddr, > int symbol =3D -1; > int n; > > + /* Return the last map state if the address is still within the range > of the > + last mapping symbol. */ > + if (last_map_section =3D=3D info->section > + && (memaddr < last_map_symbol_boundary)) > + return last_map_state; > + > + last_map_section =3D info->section; > + > /* Decide whether to print the data or instruction by default, in case > we can not find the corresponding mapping symbols. */ > mstate =3D MAP_DATA; > @@ -939,6 +950,36 @@ riscv_search_mapping_symbol (bfd_vma memaddr, > } > } > > + if (found) > + { > + /* Find the next mapping symbol to determine the boundary of this > mapping > + symbol. */ > + > + bool found_next =3D false; > + /* Try to found next mapping symbol. */ > + for (n =3D symbol + 1; n < info->symtab_size; n++) > + { > + if (info->symtab[symbol]->section !=3D info->symtab[n]->section) > + continue; > + > + bfd_vma addr =3D bfd_asymbol_value (info->symtab[n]); > + const char *sym_name =3D bfd_asymbol_name(info->symtab[n]); > + if (sym_name[0] =3D=3D '$' && (sym_name[1] =3D=3D 'x' || sym_na= me[1] =3D=3D > 'd')) > + { > + /* The next mapping symbol has been found, and it represents > the > + boundary of this mapping symbol. */ > + found_next =3D true; > + last_map_symbol_boundary =3D addr; > + break; > + } > + } > + > + /* No further mapping symbol has been found, indicating that the > boundary > + of the current mapping symbol is the end of this section. */ > + if (!found_next) > + last_map_symbol_boundary =3D info->section->vma + > info->section->size; > + } > + > /* Save the information for next use. */ > last_map_symbol =3D symbol; > last_stop_offset =3D info->stop_offset; > @@ -1059,6 +1100,8 @@ print_insn_riscv (bfd_vma memaddr, struct > disassemble_info *info) > set_default_riscv_dis_options (); > > mstate =3D riscv_search_mapping_symbol (memaddr, info); > + /* Save the last mapping state. */ > + last_map_state =3D mstate; > > /* Set the size to dump. */ > if (mstate =3D=3D MAP_DATA > -- > 2.39.2 > > --000000000000e6063c05f9941ac6--