]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Add -march=help for gas
authorHau Hsu <hau.hsu@sifive.com>
Fri, 23 Feb 2024 06:17:28 +0000 (14:17 +0800)
committerNelson Chu <nelson@rivosinc.com>
Wed, 13 Mar 2024 05:47:34 +0000 (13:47 +0800)
Use -march=help for gas to print all supported extensions and versions.

Here is part of the output of `as -march=help`:
All available -march extensions for RISC-V:
        e                                       1.9
        i                                       2.1, 2.0
        m                                       2.0
        a                                       2.1, 2.0
        f                                       2.2, 2.0
        d                                       2.2, 2.0
        q                                       2.2, 2.0
        c                                       2.0
        v                                       1.0
        h                                       1.0
        zicbom                                  1.0
        zicbop                                  1.0
        ...

This patch assumes that the supported extensions with the same versions
are listed together. For example:
static struct riscv_supported_ext riscv_supported_std_ext[] =
{
  ...
  {"i",         ISA_SPEC_CLASS_20191213,        2, 1, 0 },
  {"i",         ISA_SPEC_CLASS_20190608,        2, 1, 0 },
  {"i",         ISA_SPEC_CLASS_2P2,             2, 0, 0 },
  ...
};

For the "i" extension, 2.1.0 with different spec class are listed together.
This patch records the previous printed extension and version.  If the
current extension and version are the same as the previous one, skip
printing.

bfd/
* elfxx-riscv.c (riscv_print_extensions): New function.  Print
available extensions and versions.
* elfxx-riscv.h (riscv_print_extensions): New declaration.
gas/
* gas/config/tc-riscv.c (md_parse_option): Parse 'help' keyword in
-march option to print available extensions and versions.
* testsuite/gas/riscv/march-help.l: New testcase for -march=help.
* testsuite/gas/riscv/riscv.exp: Updated.

bfd/elfxx-riscv.c
bfd/elfxx-riscv.h
gas/config/tc-riscv.c
gas/testsuite/gas/riscv/march-help.l [new file with mode: 0644]
gas/testsuite/gas/riscv/riscv.exp

index 731366625ec26f6d3fd27b6a2c1626a4e708e09a..28be6651945354f1bc95ecb58ef7c5da4ee057ab 100644 (file)
@@ -2941,3 +2941,49 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
       return NULL;
     }
 }
+
+/* Print supported extensions with versions if -march=help.  */
+
+void
+riscv_print_extensions (void)
+{
+  /* Record the previous printed extension.
+     Print the current one if they are not the same.  */
+  const struct riscv_supported_ext *cur = NULL, *prev = NULL;
+  int i, j;
+
+  printf ("All available -march extensions for RISC-V:");
+
+  for (i = 0; riscv_all_supported_ext[i] != NULL; i++)
+    {
+      const struct riscv_supported_ext *exts = riscv_all_supported_ext[i];
+      prev = NULL;
+      for (j = 0; exts[j].name != NULL; j++)
+       {
+         cur = &exts[j];
+         /* Unclear version information, skip.  */
+         if (cur->isa_spec_class == ISA_SPEC_CLASS_NONE
+             || cur->major_version == RISCV_UNKNOWN_VERSION
+             || cur->minor_version == RISCV_UNKNOWN_VERSION)
+           continue;
+
+         /* Same extension.  */
+         if (prev && strcmp (prev->name, cur->name) == 0)
+           {
+             /* Same version, skip.  */
+             if (prev->major_version == cur->major_version
+                 && prev->minor_version == cur->minor_version)
+               continue;
+             /* Different version, print version with comma.  */
+             else
+               printf (", %d.%d", cur->major_version, cur->minor_version);
+           }
+         /* Different extension, print extension and version with newline.  */
+         else
+           printf ("\n\t%-40s%d.%d", cur->name, cur->major_version,
+                   cur->minor_version);
+         prev = &exts[j];
+       }
+    }
+  printf ("\n");
+}
index ae4cbee7bc35d900b87cffee108644a13dd7a92c..49be71746b91a2dc203737ebfc38b266c62c9b20 100644 (file)
@@ -121,6 +121,9 @@ riscv_multi_subset_supports (riscv_parse_subset_t *, enum riscv_insn_class);
 extern const char *
 riscv_multi_subset_supports_ext (riscv_parse_subset_t *, enum riscv_insn_class);
 
+extern void
+riscv_print_extensions (void);
+
 extern void
 bfd_elf32_riscv_set_data_segment_info (struct bfd_link_info *, int *);
 extern void
index 0966b7bf2359cbe0dc7273785bfa30e1a8b049a1..2a2948fde17cd2d2788d0d44637ed97c2b5d8eed 100644 (file)
@@ -4038,6 +4038,12 @@ md_parse_option (int c, const char *arg)
   switch (c)
     {
     case OPTION_MARCH:
+      /* List all avaiable extensions.  */
+      if (strcmp (arg, "help") == 0)
+       {
+         riscv_print_extensions ();
+         exit (EXIT_SUCCESS);
+       }
       default_arch_with_ext = arg;
       break;
 
diff --git a/gas/testsuite/gas/riscv/march-help.l b/gas/testsuite/gas/riscv/march-help.l
new file mode 100644 (file)
index 0000000..7f92194
--- /dev/null
@@ -0,0 +1,119 @@
+All available -march extensions for RISC-V:
+       e                                       1.9
+       i                                       2.1, 2.0
+       m                                       2.0
+       a                                       2.1, 2.0
+       f                                       2.2, 2.0
+       d                                       2.2, 2.0
+       q                                       2.2, 2.0
+       c                                       2.0
+       v                                       1.0
+       h                                       1.0
+       zicbom                                  1.0
+       zicbop                                  1.0
+       zicboz                                  1.0
+       zicond                                  1.0
+       zicntr                                  2.0
+       zicsr                                   2.0
+       zifencei                                2.0
+       zihintntl                               1.0
+       zihintpause                             2.0
+       zihpm                                   2.0
+       zmmul                                   1.0
+       zabha                                   1.0
+       zawrs                                   1.0
+       zfa                                     1.0
+       zfh                                     1.0
+       zfhmin                                  1.0
+       zfinx                                   1.0
+       zdinx                                   1.0
+       zqinx                                   1.0
+       zhinx                                   1.0
+       zhinxmin                                1.0
+       zbb                                     1.0
+       zba                                     1.0
+       zbc                                     1.0
+       zbs                                     1.0
+       zbkb                                    1.0
+       zbkc                                    1.0
+       zbkx                                    1.0
+       zk                                      1.0
+       zkn                                     1.0
+       zknd                                    1.0
+       zkne                                    1.0
+       zknh                                    1.0
+       zkr                                     1.0
+       zks                                     1.0
+       zksed                                   1.0
+       zksh                                    1.0
+       zkt                                     1.0
+       zve32x                                  1.0
+       zve32f                                  1.0
+       zve64x                                  1.0
+       zve64f                                  1.0
+       zve64d                                  1.0
+       zvbb                                    1.0
+       zvbc                                    1.0
+       zvfh                                    1.0
+       zvfhmin                                 1.0
+       zvkb                                    1.0
+       zvkg                                    1.0
+       zvkn                                    1.0
+       zvkng                                   1.0
+       zvknc                                   1.0
+       zvkned                                  1.0
+       zvknha                                  1.0
+       zvknhb                                  1.0
+       zvksed                                  1.0
+       zvksh                                   1.0
+       zvks                                    1.0
+       zvksg                                   1.0
+       zvksc                                   1.0
+       zvkt                                    1.0
+       zvl32b                                  1.0
+       zvl64b                                  1.0
+       zvl128b                                 1.0
+       zvl256b                                 1.0
+       zvl512b                                 1.0
+       zvl1024b                                1.0
+       zvl2048b                                1.0
+       zvl4096b                                1.0
+       zvl8192b                                1.0
+       zvl16384b                               1.0
+       zvl32768b                               1.0
+       zvl65536b                               1.0
+       ztso                                    1.0
+       zca                                     1.0
+       zcb                                     1.0
+       zcf                                     1.0
+       zcd                                     1.0
+       smaia                                   1.0
+       smcntrpmf                               1.0
+       smepmp                                  1.0
+       smstateen                               1.0
+       ssaia                                   1.0
+       sscofpmf                                1.0
+       ssstateen                               1.0
+       sstc                                    1.0
+       svadu                                   1.0
+       svinval                                 1.0
+       svnapot                                 1.0
+       svpbmt                                  1.0
+       xcvmac                                  1.0
+       xcvalu                                  1.0
+       xtheadba                                1.0
+       xtheadbb                                1.0
+       xtheadbs                                1.0
+       xtheadcmo                               1.0
+       xtheadcondmov                           1.0
+       xtheadfmemidx                           1.0
+       xtheadfmv                               1.0
+       xtheadint                               1.0
+       xtheadmac                               1.0
+       xtheadmemidx                            1.0
+       xtheadmempair                           1.0
+       xtheadsync                              1.0
+       xtheadvector                            1.0
+       xtheadzvamo                             1.0
+       xventanacondops                         1.0
+       xsfvcp                                  1.0
index 2c7e950c0ffcae95300dbe7e475295b60ac678a5..069e9a6945a9a95809fc3d3489ac411b0b9b2dd6 100644 (file)
@@ -21,4 +21,5 @@
 if [istarget riscv*-*-*] {
     run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
     run_list_test "align-1"
+    run_list_test "march-help" "-march=help"
 }