[PATCH 19/28] aarch64: Use has_alias_list in print_find_real_opcode

Alice Carlotti alice.carlotti@arm.com
Wed Nov 4 18:46:39 GMT 2026


This replaces the use of alias_info.  The alias lists in alias_info are
built up in reverse table order, while the new print_find_real_opcode
processes the list in a forward order, so some case statements are
reordered in the generated file.

This patch also removes the sharing of case bodies.  This makes the
generation code simpler, and only adds 18 lines to the generated file.


diff --git a/opcodes/aarch64-asm-2.c b/opcodes/aarch64-asm-2.c
index febd268038295f3d40a8be7b33a550daf6abc526..bd82c68aa498caa55e297c8445ad4516c88f2c13 100644
--- a/opcodes/aarch64-asm-2.c
+++ b/opcodes/aarch64-asm-2.c
@@ -46,30 +46,48 @@ aarch64_find_real_opcode (const aarch64_opcode *opcode)
     case A64_OPID_6f00a400_uxtl2_Vd_Vn:
       value = A64_OPID_6f00a400_ushll2_Vd_Vn_IMM_VLSL;
       break;
-    case A64_OPID_13000000_asr_Rd_Rn_IMM:
-    case A64_OPID_13000000_sbfx_Rd_Rn_IMM_WIDTH:
     case A64_OPID_13000000_sbfiz_Rd_Rn_IMM_WIDTH:
       value = A64_OPID_13000000_sbfm_Rd_Rn_IMMR_IMMS;
       break;
+    case A64_OPID_13000000_sbfx_Rd_Rn_IMM_WIDTH:
+      value = A64_OPID_13000000_sbfm_Rd_Rn_IMMR_IMMS;
+      break;
+    case A64_OPID_13000000_asr_Rd_Rn_IMM:
+      value = A64_OPID_13000000_sbfm_Rd_Rn_IMMR_IMMS;
+      break;
+    case A64_OPID_33000000_bfi_Rd_Rn_IMM_WIDTH:
+      value = A64_OPID_33000000_bfm_Rd_Rn_IMMR_IMMS;
+      break;
     case A64_OPID_330003e0_bfc_Rd_IMM_WIDTH:
+      value = A64_OPID_33000000_bfm_Rd_Rn_IMMR_IMMS;
+      break;
     case A64_OPID_33000000_bfxil_Rd_Rn_IMM_WIDTH:
-    case A64_OPID_33000000_bfi_Rd_Rn_IMM_WIDTH:
       value = A64_OPID_33000000_bfm_Rd_Rn_IMMR_IMMS;
       break;
-    case A64_OPID_53000000_lsr_Rd_Rn_IMM:
-    case A64_OPID_53000000_lsl_Rd_Rn_IMM:
-    case A64_OPID_53000000_ubfx_Rd_Rn_IMM_WIDTH:
     case A64_OPID_53000000_ubfiz_Rd_Rn_IMM_WIDTH:
       value = A64_OPID_53000000_ubfm_Rd_Rn_IMMR_IMMS;
       break;
-    case A64_OPID_1a9f07e0_cset_Rd_COND1:
+    case A64_OPID_53000000_ubfx_Rd_Rn_IMM_WIDTH:
+      value = A64_OPID_53000000_ubfm_Rd_Rn_IMMR_IMMS;
+      break;
+    case A64_OPID_53000000_lsl_Rd_Rn_IMM:
+      value = A64_OPID_53000000_ubfm_Rd_Rn_IMMR_IMMS;
+      break;
+    case A64_OPID_53000000_lsr_Rd_Rn_IMM:
+      value = A64_OPID_53000000_ubfm_Rd_Rn_IMMR_IMMS;
+      break;
     case A64_OPID_1a800400_cinc_Rd_Rn_COND1:
       value = A64_OPID_1a800400_csinc_Rd_Rn_Rm_COND;
       break;
-    case A64_OPID_5a9f03e0_csetm_Rd_COND1:
+    case A64_OPID_1a9f07e0_cset_Rd_COND1:
+      value = A64_OPID_1a800400_csinc_Rd_Rn_Rm_COND;
+      break;
     case A64_OPID_5a800000_cinv_Rd_Rn_COND1:
       value = A64_OPID_5a800000_csinv_Rd_Rn_Rm_COND;
       break;
+    case A64_OPID_5a9f03e0_csetm_Rd_COND1:
+      value = A64_OPID_5a800000_csinv_Rd_Rn_Rm_COND;
+      break;
     case A64_OPID_5a800400_cneg_Rd_Rn_COND1:
       value = A64_OPID_5a800400_csneg_Rd_Rn_Rm_COND;
       break;
diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index 89cb1683d6940557858189f92fbebe4ae7c71ff0..50f241478d5aecd0c2e54b36ac2f2dd6bc5349eb 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -682,7 +682,7 @@ release_resource_decoder_tree (struct bittree* bittree)
    entries in the table.  */
 
 static void
-print_find_real_opcode (const opcode_node *table, int num)
+print_find_real_opcode (opcode_node *has_alias_list)
 {
   int i;
 
@@ -699,29 +699,24 @@ print_find_real_opcode (const opcode_node *table, int num)
   printf ("  switch (key)\n");
   printf ("    {\n");
 
-  for (i = 0; i < num; ++i)
+  for (unsigned int index = 0; ; index++)
     {
-      const opcode_node *real = table + i;
-      const opcode_node *alias = real->next;
-      bool used = false;
-      for (; alias; alias = alias->next)
-	if (get_aarch64_opcode (alias)->flags & F_CONV)
-	  {
-	    printf ("    case %s:\n",
-		    opcode_node_labels[alias->index]);
-	    used = true;
-	  }
-      if (used)
+      const struct aarch64_opcode *ent = &aarch64_opcode_table[index];
+      if (!ent->name)
+	break;
+
+      if ((ent->flags & F_ALIAS) && (ent->flags & F_CONV))
 	{
-	  printf ("      value = %s;\n",
-		  opcode_node_labels[real->index]);
+	  opcode_node *aliased = get_aliased_opcode (ent->opcode, ent->mask,
+						     has_alias_list);
+	  printf ("    case %s:\n", opcode_node_labels[index]);
+	  printf ("      value = %s;\n", opcode_node_labels[aliased->index]);
 	  printf ("      break;\n");
 	}
     }
 
   printf ("    default: return NULL;\n");
   printf ("    }\n\n");
-
   printf ("  return aarch64_opcode_table + value;\n");
   printf ("}\n");
 }
@@ -1489,22 +1484,19 @@ main (int argc, char **argv)
     }
 
   /* Generate alias opcode handling for the assembler or the disassembler.  */
-  if (gen_assembler_p || gen_disassembler_p)
+  if (gen_disassembler_p)
     {
       int num;
       opcode_node *alias_info = create_alias_info (&num);
 
-      if (gen_assembler_p)
-	print_find_real_opcode (alias_info, num);
-
-      if (gen_disassembler_p)
-	{
-	  print_find_next_alias_opcode (alias_info, num);
-	}
+      print_find_next_alias_opcode (alias_info, num);
 
       release_resource_alias_info (alias_info, num);
     }
 
+  if (gen_assembler_p)
+    print_find_real_opcode (has_alias_list);
+
   free_opcode_list (has_alias_list);
 
   /* Generate operand table.  */


More information about the Binutils mailing list