ppc/svp64: support w/dw/sw modes
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 28 May 2023 22:04:56 +0000 (01:04 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 14 Nov 2023 19:53:34 +0000 (22:53 +0300)
gas/config/tc-ppc-svp64.c

index e9bcb4121eb718c0eb45f527480fa69af339e2c9..f771151f0886f997568c368d5fd1f30e1bb46275 100644 (file)
@@ -33,6 +33,8 @@ struct svp64_ctx {
   unsigned int has_smask : 1;
   unsigned int mask_m_specified : 1;
   unsigned int subvl : 2;
+  unsigned int destwid : 2;
+  unsigned int srcwid : 2;
 };
 
 static jmp_buf svp64_exception;
@@ -243,6 +245,97 @@ svp64_decode_vec (char *str, struct svp64_ctx *svp64)
   return str;
 }
 
+struct svp64_width_map {
+  const char *str;
+  unsigned int len;
+  unsigned int width;
+};
+#define SVP64_WIDTH_MAP(STR, WIDTH) \
+  { STR, (sizeof (STR) - 1), WIDTH }
+
+static char *
+svp64_decode_width (char *str, unsigned int *width)
+{
+  size_t i;
+  static const struct svp64_width_map table[] = {
+    SVP64_WIDTH_MAP ("8", 3),
+    SVP64_WIDTH_MAP ("16", 2),
+    SVP64_WIDTH_MAP ("32", 1),
+  };
+
+  for (i = 0; i < (sizeof (table) / sizeof (table[0])); ++i)
+    {
+      const struct svp64_width_map *entry = &table[i];
+
+      if (strncmp (str, entry->str, entry->len) != 0)
+        continue;
+
+      str += entry->len;
+      if (! ISSPACE (*str) && *str != SVP64_SEP && *str != '\0')
+        {
+          str -= entry->len;
+          continue;
+        }
+
+      *width = entry->width;
+
+      *str++ = '\0';
+
+      return str;
+    }
+
+  return NULL;
+}
+
+static char *
+svp64_decode_w (char *str, struct svp64_ctx *svp64)
+{
+  char *iter;
+  unsigned int width;
+
+  str += (sizeof ("w=") - 1);
+  iter = svp64_decode_width (str, &width);
+  if (!iter)
+    svp64_raise (_("unrecognized mode: `%s'"), str);
+
+  svp64->srcwid = width;
+  svp64->destwid = width;
+
+  return iter;
+}
+
+static char *
+svp64_decode_dw (char *str, struct svp64_ctx *svp64)
+{
+  char *iter;
+  unsigned int width;
+
+  str += (sizeof ("dw=") - 1);
+  iter = svp64_decode_width (str, &width);
+  if (!iter)
+    svp64_raise (_("unrecognized mode: `%s'"), str);
+
+  svp64->destwid = width;
+
+  return iter;
+}
+
+static char *
+svp64_decode_sw (char *str, struct svp64_ctx *svp64)
+{
+  char *iter;
+  unsigned int width;
+
+  str += (sizeof ("sw=") - 1);
+  iter = svp64_decode_width (str, &width);
+  if (!iter)
+    svp64_raise (_("unrecognized mode: `%s'"), str);
+
+  svp64->srcwid = width;
+
+  return iter;
+}
+
 static char *
 svp64_decode_mode (char *str, struct svp64_ctx *svp64)
 {
@@ -254,6 +347,9 @@ svp64_decode_mode (char *str, struct svp64_ctx *svp64)
     SVP64_DECODER ("vec2", svp64_decode_vec),
     SVP64_DECODER ("vec3", svp64_decode_vec),
     SVP64_DECODER ("vec4", svp64_decode_vec),
+    SVP64_DECODER ("w=" ,  svp64_decode_w),
+    SVP64_DECODER ("dw=" , svp64_decode_dw),
+    SVP64_DECODER ("sw=" , svp64_decode_sw),
   };
 
   for (i = 0; i < sizeof (table) / sizeof (table[0]); ++i)