[PATCH 07/28] aarch64: Adjust alias priorities and make F_P1 default
Alice Carlotti
alice.carlotti@arm.com
Wed Nov 4 18:42:58 GMT 2026
Adjust alias priorities so that existing alias prioritisation does not
depend on opcode table ordering or on the value of the default priority.
The default alias priority is also changed to F_P1. This will allow an
opcode with a less specific ask to be deprioritised without needing to
explicitly raise the priority of all the more specific opcodes it
overlaps with, and will be useful for mrs/msr in a future commit.
For now, however, aarch64-gen.c currently requires non-aliases to have
priority 0, so set this explicitly in opcode_priority ().
diff --git a/include/opcode/aarch64.h b/include/opcode/aarch64.h
index bfe7489e813eaff06121cdf9e189589f663873ea..522c0a7f2f21929be56a0716bfcc202e7c2042c7 100644
--- a/include/opcode/aarch64.h
+++ b/include/opcode/aarch64.h
@@ -1436,11 +1436,12 @@ extern const aarch64_opcode aarch64_opcode_table[];
/* Opcode flags. */
#define F_ALIAS (1 << 0)
#define F_HAS_ALIAS (1 << 1)
-/* Disassembly preference priority 1-3 (the larger the higher). If nothing
- is specified, it is the priority 0 by default, i.e. the lowest priority. */
-#define F_P1 (1 << 2)
-#define F_P2 (2 << 2)
-#define F_P3 (3 << 2)
+/* Disassembly preference priority 0-3 (the larger the higher). If nothing
+ is specified, it is the priority 1 by default. */
+#define F_P0 (3 << 2)
+#define F_P1 (0 << 2)
+#define F_P2 (1 << 2)
+#define F_P3 (2 << 2)
/* Flag an instruction that is truly conditional executed, e.g. b.cond. */
#define F_COND (1 << 4)
/* Instruction has the field of 'sf'. */
@@ -1577,7 +1578,7 @@ opcode_has_alias (const aarch64_opcode *opcode)
static inline int
opcode_priority (const aarch64_opcode *opcode)
{
- return (opcode->flags >> 2) & 0x3;
+ return alias_opcode_p (opcode) ? (((opcode->flags >> 2) + 1) & 0x3) : 0;
}
static inline bool
diff --git a/opcodes/aarch64-asm-2.c b/opcodes/aarch64-asm-2.c
index 69aed08dde77da190d4d2539b5cd03085c62da4e..2fc7f98c3c2afe04b15143303aa03c62cc0563a3 100644
--- a/opcodes/aarch64-asm-2.c
+++ b/opcodes/aarch64-asm-2.c
@@ -127,9 +127,9 @@ aarch64_find_real_opcode (const aarch64_opcode *opcode)
case A64_OPID_33000000_bfm_Rd_Rn_IMMR_IMMS:
value = A64_OPID_33000000_bfm_Rd_Rn_IMMR_IMMS;
break;
+ case A64_OPID_53000000_lsr_Rd_Rn_IMM:
case A64_OPID_53003c00_uxth_Rd_Rn:
case A64_OPID_53001c00_uxtb_Rd_Rn:
- 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:
diff --git a/opcodes/aarch64-dis-2.c b/opcodes/aarch64-dis-2.c
index 2930749291ffca977b9dbfb7f7dcec9ad99f49db..8e811684a6520f560715eb2aec81b198b7c6480a 100644
--- a/opcodes/aarch64-dis-2.c
+++ b/opcodes/aarch64-dis-2.c
@@ -36769,7 +36769,7 @@ aarch64_find_alias_opcode (const aarch64_opcode *opcode)
value = A64_OPID_330003e0_bfc_Rd_IMM_WIDTH;
break;
case A64_OPID_53000000_ubfm_Rd_Rn_IMMR_IMMS:
- value = A64_OPID_53003c00_uxth_Rd_Rn;
+ value = A64_OPID_53000000_lsr_Rd_Rn_IMM;
break;
case A64_OPID_54000000_b_c_ADDR_PCREL19:
value = A64_OPID_5400000d_ble_ADDR_PCREL19;
@@ -37307,13 +37307,13 @@ aarch64_find_next_alias_opcode (const aarch64_opcode *opcode)
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:
+ value = A64_OPID_53003c00_uxth_Rd_Rn;
+ break;
case A64_OPID_53003c00_uxth_Rd_Rn:
value = A64_OPID_53001c00_uxtb_Rd_Rn;
break;
case A64_OPID_53001c00_uxtb_Rd_Rn:
- value = A64_OPID_53000000_lsr_Rd_Rn_IMM;
- break;
- case A64_OPID_53000000_lsr_Rd_Rn_IMM:
value = A64_OPID_53000000_lsl_Rd_Rn_IMM;
break;
case A64_OPID_53000000_lsl_Rd_Rn_IMM:
diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c
index 3d983c7535467a8a49c9b1fc68f9d2656d188f98..c4f37fd060700c063065e557eca8f500b717ce12 100644
--- a/opcodes/aarch64-dis.c
+++ b/opcodes/aarch64-dis.c
@@ -3322,11 +3322,17 @@ aarch64_opcode_decode (const aarch64_opcode *, const aarch64_insn,
F_ALIAS: opcode is an alias
F_HAS_ALIAS: opcode has alias(es)
+ F_P0
F_P1
F_P2
- F_P3: Disassembly preference priority 1-3 (the larger the
+ F_P3: Disassembly preference priority 0-3 (the larger the
higher). If nothing is specified, it is the priority
- 0 by default, i.e. the lowest priority.
+ 1 by default. This allows an opcode with a less
+ specific mask to be deprioritised without needing to
+ explicitly raise the priority of all the more specific
+ opcodes it overlaps with. This is useful for mrs/msr,
+ which overlaps with a lot of other system instructions
+ due to binutils accepting an expanded operand range.
Although the relation between the machine and the alias instructions are not
explicitly described, it can be easily determined from the base opcode
diff --git a/opcodes/aarch64-tbl.h b/opcodes/aarch64-tbl.h
index 93eb7c12f43bfac272fdd111cd9d4e18f900ae65..97fa74c057ff99e5c78d3807a4706c936fe2a73c 100644
--- a/opcodes/aarch64-tbl.h
+++ b/opcodes/aarch64-tbl.h
@@ -3774,7 +3774,7 @@ const struct aarch64_opcode aarch64_opcode_table[] =
CORE_INSN ("neg", 0x4b0003e0, 0x7f2003e0, addsub_shift, 0, OP2 (Rd, Rm_SFT), QL_I2SAME, F_ALIAS | F_SF),
CORE_INSN ("subs", 0x6b000000, 0x7f200000, addsub_shift, 0, OP3 (Rd, Rn, Rm_SFT), QL_I3SAMER, F_HAS_ALIAS | F_SF),
CORE_INSN ("cmp", 0x6b00001f, 0x7f20001f, addsub_shift, 0, OP2 (Rn, Rm_SFT), QL_I2SAME, F_ALIAS | F_SF | F_P1),
- CORE_INSN ("negs", 0x6b0003e0, 0x7f2003e0, addsub_shift, 0, OP2 (Rd, Rm_SFT), QL_I2SAME, F_ALIAS | F_SF),
+ CORE_INSN ("negs", 0x6b0003e0, 0x7f2003e0, addsub_shift, 0, OP2 (Rd, Rm_SFT), QL_I2SAME, F_ALIAS | F_SF | F_P0),
/* AdvSIMD across lanes. */
SIMD_INSN ("saddlv", 0x0e303800, 0xbf3ffc00, asimdall, 0, OP2 (Fd, Vn), QL_XLANES_L, F_SIZEQ),
SIMD_INSN ("smaxv", 0x0e30a800, 0xbf3ffc00, asimdall, 0, OP2 (Fd, Vn), QL_XLANES, F_SIZEQ),
@@ -4390,23 +4390,23 @@ const struct aarch64_opcode aarch64_opcode_table[] =
SF16_INSN ("fcvtzu", 0x7f10fc00, 0xff80fc00, asisdshf, OP3 (Sd, Sn, IMM_VLSR), QL_SSHIFT_H, 0),
/* Bitfield. */
CORE_INSN ("sbfm", 0x13000000, 0x7f800000, bitfield, 0, OP4 (Rd, Rn, IMMR, IMMS), QL_BF, F_HAS_ALIAS | F_SF | F_N),
- CORE_INSN ("sbfiz", 0x13000000, 0x7f800000, bitfield, OP_SBFIZ, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P1 | F_CONV),
+ CORE_INSN ("sbfiz", 0x13000000, 0x7f800000, bitfield, OP_SBFIZ, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P0 | F_CONV),
CORE_INSN ("sbfx", 0x13000000, 0x7f800000, bitfield, OP_SBFX, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P1 | F_CONV),
CORE_INSN ("sxtb", 0x13001c00, 0x7fbffc00, bitfield, 0, OP2 (Rd, Rn), QL_EXT, F_ALIAS | F_P3 | F_SF | F_N),
CORE_INSN ("sxth", 0x13003c00, 0x7fbffc00, bitfield, 0, OP2 (Rd, Rn), QL_EXT, F_ALIAS | F_P3 | F_SF | F_N),
CORE_INSN ("sxtw", 0x93407c00, 0xfffffc00, bitfield, 0, OP2 (Rd, Rn), QL_EXT_W, F_ALIAS | F_P3),
CORE_INSN ("asr", 0x13000000, 0x7f800000, bitfield, OP_ASR_IMM, OP3 (Rd, Rn, IMM), QL_SHIFT, F_ALIAS | F_P2 | F_CONV),
CORE_INSN ("bfm", 0x33000000, 0x7f800000, bitfield, 0, OP4 (Rd, Rn, IMMR, IMMS), QL_BF, F_HAS_ALIAS | F_SF | F_N),
- CORE_INSN ("bfi", 0x33000000, 0x7f800000, bitfield, OP_BFI, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P1 | F_CONV),
+ CORE_INSN ("bfi", 0x33000000, 0x7f800000, bitfield, OP_BFI, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P0 | F_CONV),
CORE_INSN ("bfc", 0x330003e0, 0x7f8003e0, bitfield, OP_BFC, OP3 (Rd, IMM, WIDTH), QL_BF1, F_ALIAS | F_P2 | F_CONV),
CORE_INSN ("bfxil", 0x33000000, 0x7f800000, bitfield, OP_BFXIL, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P1 | F_CONV),
CORE_INSN ("ubfm", 0x53000000, 0x7f800000, bitfield, 0, OP4 (Rd, Rn, IMMR, IMMS), QL_BF, F_HAS_ALIAS | F_SF | F_N),
- CORE_INSN ("ubfiz", 0x53000000, 0x7f800000, bitfield, OP_UBFIZ, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P1 | F_CONV),
+ CORE_INSN ("ubfiz", 0x53000000, 0x7f800000, bitfield, OP_UBFIZ, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P0 | F_CONV),
CORE_INSN ("ubfx", 0x53000000, 0x7f800000, bitfield, OP_UBFX, OP4 (Rd, Rn, IMM, WIDTH), QL_BF2, F_ALIAS | F_P1 | F_CONV),
CORE_INSN ("uxtb", 0x53001c00, 0xfffffc00, bitfield, OP_UXTB, OP2 (Rd, Rn), QL_I2SAMEW, F_ALIAS | F_P3),
CORE_INSN ("uxth", 0x53003c00, 0xfffffc00, bitfield, OP_UXTH, OP2 (Rd, Rn), QL_I2SAMEW, F_ALIAS | F_P3),
CORE_INSN ("lsl", 0x53000000, 0x7f800000, bitfield, OP_LSL_IMM, OP3 (Rd, Rn, IMM), QL_SHIFT, F_ALIAS | F_P2 | F_CONV),
- CORE_INSN ("lsr", 0x53000000, 0x7f800000, bitfield, OP_LSR_IMM, OP3 (Rd, Rn, IMM), QL_SHIFT, F_ALIAS | F_P2 | F_CONV),
+ CORE_INSN ("lsr", 0x53000000, 0x7f800000, bitfield, OP_LSR_IMM, OP3 (Rd, Rn, IMM), QL_SHIFT, F_ALIAS | F_P3 | F_CONV),
/* Unconditional branch (immediate). */
CORE_INSN ("b", 0x14000000, 0xfc000000, branch_imm, OP_B, OP1 (ADDR_PCREL26), QL_PCREL_26, F_SUBCLASS_OTHER),
CORE_INSN ("bl", 0x94000000, 0xfc000000, branch_imm, OP_BL, OP1 (ADDR_PCREL26), QL_PCREL_26, F_BRANCH_CALL),
@@ -4490,10 +4490,10 @@ const struct aarch64_opcode aarch64_opcode_table[] =
/* Conditional select. */
CORE_INSN ("csel", 0x1a800000, 0x7fe00c00, condsel, 0, OP4 (Rd, Rn, Rm, COND), QL_CSEL, F_SF),
CORE_INSN ("csinc", 0x1a800400, 0x7fe00c00, condsel, 0, OP4 (Rd, Rn, Rm, COND), QL_CSEL, F_HAS_ALIAS | F_SF),
- CORE_INSN ("cinc", 0x1a800400, 0x7fe00c00, condsel, OP_CINC, OP3 (Rd, Rn, COND1), QL_R2NIL, F_ALIAS | F_SF | F_CONV),
+ CORE_INSN ("cinc", 0x1a800400, 0x7fe00c00, condsel, OP_CINC, OP3 (Rd, Rn, COND1), QL_R2NIL, F_ALIAS | F_P0 | F_SF | F_CONV),
CORE_INSN ("cset", 0x1a9f07e0, 0x7fff0fe0, condsel, OP_CSET, OP2 (Rd, COND1), QL_DST_R, F_ALIAS | F_P1 | F_SF | F_CONV),
CORE_INSN ("csinv", 0x5a800000, 0x7fe00c00, condsel, 0, OP4 (Rd, Rn, Rm, COND), QL_CSEL, F_HAS_ALIAS | F_SF),
- CORE_INSN ("cinv", 0x5a800000, 0x7fe00c00, condsel, OP_CINV, OP3 (Rd, Rn, COND1), QL_R2NIL, F_ALIAS | F_SF | F_CONV),
+ CORE_INSN ("cinv", 0x5a800000, 0x7fe00c00, condsel, OP_CINV, OP3 (Rd, Rn, COND1), QL_R2NIL, F_ALIAS | F_P0 | F_SF | F_CONV),
CORE_INSN ("csetm", 0x5a9f03e0, 0x7fff0fe0, condsel, OP_CSETM, OP2 (Rd, COND1), QL_DST_R, F_ALIAS | F_P1 | F_SF | F_CONV),
CORE_INSN ("csneg", 0x5a800400, 0x7fe00c00, condsel, 0, OP4 (Rd, Rn, Rm, COND), QL_CSEL, F_HAS_ALIAS | F_SF),
CORE_INSN ("cneg", 0x5a800400, 0x7fe00c00, condsel, OP_CNEG, OP3 (Rd, Rn, COND1), QL_R2NIL, F_ALIAS | F_SF | F_CONV),
@@ -5287,7 +5287,7 @@ const struct aarch64_opcode aarch64_opcode_table[] =
_SVE_INSN ("mov", 0x05203800, 0xff3ffc00, sve_size_bhsd, 0, OP2 (SVE_Zd, Rn_SP), OP_SVE_VR_BHSD, F_ALIAS, 0),
_SVE_INSN ("mov", 0x25804000, 0xfff0c210, sve_misc, OP_MOV_P_P, OP2 (SVE_Pd, SVE_Pn), OP_SVE_BB, F_ALIAS | F_MISC, 0),
_SVE_INSN ("mov", 0x25804000, 0xfff0c210, sve_misc, OP_MOV_PN_PN, OP2 (SVE_PNd, SVE_PNn), OP_SVE_BB, F_ALIAS | F_PSEUDO | F_MISC, 0),
- _SVE_INSN ("mov", 0x05202000, 0xff20fc00, sve_index, 0, OP2 (SVE_Zd, SVE_Zn_INDEX), OP_SVE_VV_BHSDQ, F_ALIAS, 0),
+ _SVE_INSN ("mov", 0x05202000, 0xff20fc00, sve_index, 0, OP2 (SVE_Zd, SVE_Zn_INDEX), OP_SVE_VV_BHSDQ, F_ALIAS | F_P0, 0),
_SVE_INSN ("mov", 0x05c00000, 0xfffc0000, sve_limm, 0, OP2 (SVE_Zd, SVE_LIMM_MOV), OP_SVE_VU_BHSD, F_ALIAS, 0),
_SVE_INSN ("mov", 0x2538c000, 0xff3fc000, sve_size_bhsd, 0, OP2 (SVE_Zd, SVE_ASIMM), OP_SVE_VU_BHSD, F_ALIAS, 0),
_SVE_INSNC ("mov", 0x05208000, 0xff3fe000, sve_size_bhsd, 0, OP3 (SVE_Zd, SVE_Pg3, SVE_Vn), OP_SVE_VMV_BHSD, F_ALIAS, C_SCAN_MOVPRFX, 0),
More information about the Binutils
mailing list