Skip to content

Commit

Permalink
ppc/svp64: introduce non-zero operand flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ghostmansd authored and amodra committed Aug 11, 2022
1 parent 33ae8a3 commit 59f0827
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
21 changes: 18 additions & 3 deletions gas/config/tc-ppc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,9 +1657,14 @@ ppc_setup_opcodes (void)
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) != 0
&& (flags & PPC_OPERAND_NONZERO) != 0)
as_bad ("mutually exclusive operand flags");

right_bit = mask & -mask;
mask += right_bit;
right_bit = mask & -mask;
Expand Down Expand Up @@ -1992,6 +1997,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++;
Expand Down Expand Up @@ -2042,10 +2052,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;
}
Expand Down
5 changes: 5 additions & 0 deletions include/opcode/ppc.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ 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
Expand Down
3 changes: 3 additions & 0 deletions opcodes/ppc-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ operand_value_powerpc (const struct powerpc_operand *operand,
}
}

if ((operand->flags & PPC_OPERAND_NONZERO) != 0)
++value;

return value;
}

Expand Down

0 comments on commit 59f0827

Please sign in to comment.