[PATCH 25/28] aarch64: Support priority flags on non-alias opcodes
Alice Carlotti
alice.carlotti@arm.com
Wed Nov 4 18:48:22 GMT 2026
This can be used to remove opcode table order dependencies, or to reduce
the length of decode chains (by moving more of the work into the decode
tree).
Reduce the priority of msr and mrs to P0. With this change, all opcode
prioritisation is explicitly specified, with no dependencies on opcode
table order (so reversing the entire opcode table would not change any
disassembly).
diff --git a/include/opcode/aarch64.h b/include/opcode/aarch64.h
index 522c0a7f2f21929be56a0716bfcc202e7c2042c7..e862dce9eec3c7060f271fa474b48bfdbb49b27a 100644
--- a/include/opcode/aarch64.h
+++ b/include/opcode/aarch64.h
@@ -1578,7 +1578,7 @@ opcode_has_alias (const aarch64_opcode *opcode)
static inline int
opcode_priority (const aarch64_opcode *opcode)
{
- return alias_opcode_p (opcode) ? (((opcode->flags >> 2) + 1) & 0x3) : 0;
+ return ((opcode->flags >> 2) + 1) & 0x3;
}
static inline bool
diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c
index 373613f1e7757472d5ebc53ea497901bbb099bd2..4f7176407553b4f94fc4db9234b62620aca3fe5c 100644
--- a/opcodes/aarch64-gen.c
+++ b/opcodes/aarch64-gen.c
@@ -274,10 +274,9 @@ validate_table (opcode_node *has_alias_list)
static void
read_table (opcode_node **tree_opcodes, opcode_node **alias_opcodes)
{
- /* Linked lists for non-alias, P0 alias, P1 alias, P2 alias, P3 alias. */
- opcode_node *heads[5] = {};
- opcode_node **tails[5];
- for (int i = 0; i < 5; i++)
+ opcode_node *heads[8] = {};
+ opcode_node **tails[8];
+ for (int i = 0; i < 8; i++)
tails[i] = &heads[i];
for (unsigned int index = 0; ; index++)
@@ -290,9 +289,8 @@ read_table (opcode_node **tree_opcodes, opcode_node **alias_opcodes)
if (pseudo_opcode_p (ent))
continue;
- unsigned int part = 0;
- if (alias_opcode_p (ent))
- part = 1 + opcode_priority (ent);
+ unsigned int part = (alias_opcode_p (ent) ? 4 : 0)
+ + opcode_priority (ent);
opcode_node *node = new_opcode_node ();
node->opcode = ent->opcode;
@@ -302,12 +300,14 @@ read_table (opcode_node **tree_opcodes, opcode_node **alias_opcodes)
tails[part] = &node->next;
}
- *tails[2] = heads[1]; /* Append P0 to P1. */
- *tails[3] = heads[2]; /* Append P1P0 to P2. */
- *tails[4] = heads[3]; /* Append P2P1P0 to P3. */
+ /* Splice the lists together. */
+ for (int i = 1; i < 8; i++)
+ if (i != 4)
+ /* Append list i-1 to list i. */
+ *tails[i] = heads[i - 1];
- *tree_opcodes = heads[0];
- *alias_opcodes = heads[4];
+ *tree_opcodes = heads[3];
+ *alias_opcodes = heads[7];
}
static inline void
diff --git a/opcodes/aarch64-tbl.h b/opcodes/aarch64-tbl.h
index 97fa74c057ff99e5c78d3807a4706c936fe2a73c..129966fa9aec329ae7d618f7bb22d89fcedf258c 100644
--- a/opcodes/aarch64-tbl.h
+++ b/opcodes/aarch64-tbl.h
@@ -5239,16 +5239,16 @@ const struct aarch64_opcode aarch64_opcode_table[] =
PREDRES2_INSN ("cosp", 0xd50b73c0, 0xffffffe0, ic_system, OP2 (SYSREG_SR, Rt), QL_SRC_X, F_ALIAS),
BRBE_INSN ("brb", 0xd5097280, 0xffffffc0, OP2 (BRBOP, Rt_IN_SYS_ALIASES), QL_IMM_NIL_NIL, F_ALIAS | F_OPD1_OPT | F_DEFAULT (0x1F)),
FLAGM_INSN ("cfinv", 0xd500401f, 0xffffffff, ic_system, OP0 (), QL_0, 0),
- /* This msr entry has a lot of aliases, and some of these (such as "hint")
- have their own (recursive) aliases. We currently use a flat alias
- structure, so to avoid creating an excessively long list of aliases for
- the entire msr space we instead handle the top level of disambiguation
- outside the alias infrastructure. This requires that all of the top-level
- aliases of msr must appear earlier in the opcode table, since normal
- (non-alias) disassembly is done on a "first match" basis. */
- CORE_INSN ("msr", 0xd5000000, 0xffe00000, ic_system, 0, OP2 (SYSREG, Rt), QL_SRC_X, F_SYS_WRITE),
+ /* This msr entry accepts all 2-bit op0 values, even though the architecture
+ restricts op0 to 2 or 3. This results in msr overlapping a large number
+ of other opcodes, as if they were aliases of msr. However, marking them
+ as aliases would prevent us marking some of those opcodes as having their
+ own aliases, because we use a flat (non-recursive) structure, and it
+ wouldn't reflect the architectural alias structure either. Instead, we
+ simply deprioritise this entry by marking it as F_P0. */
+ CORE_INSN ("msr", 0xd5000000, 0xffe00000, ic_system, 0, OP2 (SYSREG, Rt), QL_SRC_X, F_P0 | F_SYS_WRITE),
CORE_INSN ("sysl",0xd5280000, 0xfff80000, ic_system, 0, OP5 (Rt, UIMM3_OP1, CRn, CRm, UIMM3_OP2), QL_SYSL, F_HAS_ALIAS),
- CORE_INSN ("mrs", 0xd5200000, 0xffe00000, ic_system, 0, OP2 (Rt, SYSREG), QL_DST_X, F_SYS_READ),
+ CORE_INSN ("mrs", 0xd5200000, 0xffe00000, ic_system, 0, OP2 (Rt, SYSREG), QL_DST_X, F_P0 | F_SYS_READ),
D128_INSN ("mrrs", 0xd5700000, 0xfff00000, OP3 (Rt, PAIRREG, SYSREG128), QL_DST_X2, F_SYS_READ),
D128_INSN ("msrr", 0xd5500000, 0xfff00000, OP3 (SYSREG128, Rt, PAIRREG), QL_SRC_X2, F_SYS_WRITE),
CORE_INSN ("paciaz", 0xd503231f, 0xffffffff, ic_system, 0, OP0 (), QL_0, F_ALIAS),
More information about the Binutils
mailing list