[1/3] RISC-V: Easy optimization on riscv_search_mapping_symbol

Message ID 88793c204c9270376959c6276fb1b63275bef3c8.1668906599.git.research_trasio@irq.a4lg.com
State Unresolved
Headers
Series RISC-V: Disassembler Core Optimization 1-2 (Mapping symbols) |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Tsukasa OI Nov. 20, 2022, 1:10 a.m. UTC
  From: Tsukasa OI <research_trasio@irq.a4lg.com>

Before further optimization, we can optimize the function
riscv_search_mapping_symbol a bit for clarity.

opcodes/ChangeLog:

	* riscv-dis.c (riscv_search_mapping_symbol): Make MAP_INSN default
	considering major usecases.  Remove setting found here as no one
	uses the value after setting this.  memaddr cannot be negative
	so simplify and change comment.

Idea-by: Nelson Chu <nelson@rivosinc.com>
---
 opcodes/riscv-dis.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
  

Patch

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 32e7b1174436..9ea4da9b219b 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -1132,18 +1132,16 @@  riscv_search_mapping_symbol (bfd_vma memaddr,
 
   /* Decide whether to print the data or instruction by default, in case
      we can not find the corresponding mapping symbols.  */
-  mstate = MAP_DATA;
-  if ((info->section
-       && info->section->flags & SEC_CODE)
-      || !info->section)
-    mstate = MAP_INSN;
+  mstate = MAP_INSN;
+  if (info->section && (info->section->flags & SEC_CODE) == 0)
+    mstate = MAP_DATA;
 
   if (info->symtab_size == 0
       || bfd_asymbol_flavour (*info->symtab) != bfd_target_elf_flavour)
     return mstate;
 
-  /* Reset the last_map_symbol if we start to dump a new section.  */
-  if (memaddr <= 0)
+  /* Reset the last_map_symbol if the address is zero.  */
+  if (memaddr == 0)
     last_map_symbol = -1;
 
   /* If the last stop offset is different from the current one, then
@@ -1195,7 +1193,6 @@  riscv_search_mapping_symbol (bfd_vma memaddr,
 	  if (riscv_get_map_state (n, &mstate, info, true))
 	    {
 	      symbol = n;
-	      found = true;
 	      break;
 	    }
 	}