public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] ppc/svp64: introduce non-zero operand flag
Date: Thu, 11 Aug 2022 09:09:29 +0000 (GMT)	[thread overview]
Message-ID: <20220811090929.A4CD43857824@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=59f08271dda07502f53575538efcd19d247c70e1

commit 59f08271dda07502f53575538efcd19d247c70e1
Author: Dmitry Selyutin <ghostmansd@gmail.com>
Date:   Mon Jul 25 16:10:15 2022 +0300

    ppc/svp64: introduce non-zero operand flag
    
    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.

Diff:
---
 gas/config/tc-ppc.c  | 21 ++++++++++++++++++---
 include/opcode/ppc.h |  5 +++++
 opcodes/ppc-dis.c    |  3 +++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index ffc99857e39..b5aad4b6e3e 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -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;
@@ -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++;
@@ -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;
 }
diff --git a/include/opcode/ppc.h b/include/opcode/ppc.h
index cf72db6069d..3578f0d218d 100644
--- a/include/opcode/ppc.h
+++ b/include/opcode/ppc.h
@@ -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
diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c
index db03dce4613..97f2e201e9a 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;
 }


                 reply	other threads:[~2022-08-11  9:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220811090929.A4CD43857824@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).