[PATCH v6 2/7] ppc: introduce non-zero operand flag
Dmitry Selyutin
ghostmansd@gmail.com
Mon Jul 25 13:10:15 GMT 2022
svstep and svshape instructions subtract 1 before encoding some of the
operands. Obviously zero is not supported for these operands. Whilst
PPC_OPERAND_PLUS1 fits perfectly to mark that maximal value should be
incremented, there is no flag which marks the fact that zero values are
not allowed. This patch adds a new flag, PPC_OPERAND_NONZERO, for this
purpose.
---
gas/config/tc-ppc.c | 22 +++++++++++++++++++---
include/opcode/ppc.h | 7 +++++++
opcodes/ppc-dis.c | 3 +++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index ffc99857e3..7bd2fe785d 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -1656,10 +1656,16 @@ ppc_setup_opcodes (void)
all the 1's in the mask are contiguous. */
for (i = 0; i < num_powerpc_operands; ++i)
{
+
uint64_t mask = powerpc_operands[i].bitm;
+ unsigned long flags = powerpc_operands[i].flags;
uint64_t right_bit;
unsigned int j;
+ if ((flags & (PPC_OPERAND_PLUS1 | PPC_OPERAND_NONZERO)) ==
+ (PPC_OPERAND_PLUS1 | PPC_OPERAND_NONZERO))
+ as_bad ("mutually exclusive operand flags");
+
right_bit = mask & -mask;
mask += right_bit;
right_bit = mask & -mask;
@@ -1992,6 +1998,11 @@ ppc_insert_operand (uint64_t insn,
max = (max >> 1) & -right;
min = ~max & -right;
}
+ else if ((operand->flags & PPC_OPERAND_NONZERO) != 0)
+ {
+ ++min;
+ ++max;
+ }
if ((operand->flags & PPC_OPERAND_PLUS1) != 0)
max++;
@@ -2042,10 +2053,15 @@ ppc_insert_operand (uint64_t insn,
if (errmsg != (const char *) NULL)
as_bad_where (file, line, "%s", errmsg);
}
- else if (operand->shift >= 0)
- insn |= (val & operand->bitm) << operand->shift;
else
- insn |= (val & operand->bitm) >> -operand->shift;
+ {
+ if ((operand->flags & PPC_OPERAND_NONZERO) != 0)
+ --val;
+ if (operand->shift >= 0)
+ insn |= (val & operand->bitm) << operand->shift;
+ else
+ insn |= (val & operand->bitm) >> -operand->shift;
+ }
return insn;
}
diff --git a/include/opcode/ppc.h b/include/opcode/ppc.h
index d5752a42e6..df06671db4 100644
--- a/include/opcode/ppc.h
+++ b/include/opcode/ppc.h
@@ -463,6 +463,13 @@ extern const unsigned int num_powerpc_operands;
#define PPC_OPERAND_FCR (0x1000000)
#define PPC_OPERAND_UDI (0x2000000)
+/*
+ * Valid range of operand is 1..n rather than 0..n-1.
+ * Before encoding, the operand value is decremented.
+ * After decoding. the operand value is incremented.
+ */
+#define PPC_OPERAND_NONZERO 0x4000000
+
extern ppc_cpu_t ppc_parse_cpu (ppc_cpu_t, ppc_cpu_t *, const char *);
static inline int64_t
diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c
index f61e6518f1..d5b23c8a75 100644
--- a/opcodes/ppc-dis.c
+++ b/opcodes/ppc-dis.c
@@ -545,6 +545,9 @@ operand_value_powerpc (const struct powerpc_operand *operand,
}
}
+ if ((operand->flags & PPC_OPERAND_NONZERO) != 0)
+ ++value;
+
return value;
}
--
2.37.0
More information about the Binutils
mailing list