public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Maintain a string to hold the canonical order
@ 2022-02-21 14:47 Kito Cheng
  2022-02-21 14:50 ` Tsukasa OI
  2022-02-21 15:02 ` Tsukasa OI
  0 siblings, 2 replies; 4+ messages in thread
From: Kito Cheng @ 2022-02-21 14:47 UTC (permalink / raw)
  To: binutils, kito.cheng, jim.wilson.gcc, research_trasio, jbeulich,
	philipp.tomsich, palmer, nelson.chu, cmuellner, jiawei
  Cc: Kito Cheng

Using dummy entry in riscv_supported_std_ext cause confusing and wrongly
support `b` and `k` extensions.

bfd/
	* elfxx-riscv.c (riscv_supported_std_ext): Drop unsupported
	extensions.
	(riscv_ext_canonical_order): New.
	(riscv_init_ext_order): Use riscv_ext_canonical_order rather
	than riscv_supported_std_ext to compute canonical order.
---
 bfd/elfxx-riscv.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 9f52bb545ac..17633e6fae2 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -1163,17 +1163,10 @@ static struct riscv_supported_ext riscv_supported_std_ext[] =
   {"q",		ISA_SPEC_CLASS_20191213,	2, 2, 0 },
   {"q",		ISA_SPEC_CLASS_20190608,	2, 2, 0 },
   {"q",		ISA_SPEC_CLASS_2P2,		2, 0, 0 },
-  {"l",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
   {"c",		ISA_SPEC_CLASS_20191213,	2, 0, 0 },
   {"c",		ISA_SPEC_CLASS_20190608,	2, 0, 0 },
   {"c",		ISA_SPEC_CLASS_2P2,		2, 0, 0 },
-  {"b",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
-  {"k",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
-  {"j",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
-  {"t",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
-  {"p",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
   {"v",		ISA_SPEC_CLASS_DRAFT,		1, 0, 0 },
-  {"n",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
   {NULL, 0, 0, 0, 0}
 };
 
@@ -1341,6 +1334,9 @@ riscv_recognized_prefixed_ext (const char *ext)
   return false;
 }
 
+/* Canonical order for single letter extensions.  */
+static const char riscv_ext_canonical_order[] = "eigmafdqlcbjktpvn";
+
 /* Array is used to compare the orders of standard extensions quickly.  */
 static int riscv_ext_order[26] = {0};
 
@@ -1356,16 +1352,10 @@ riscv_init_ext_order (void)
   /* The orders of all standard extensions are positive.  */
   int order = 1;
 
-  int i = 0;
-  while (riscv_supported_std_ext[i].name != NULL)
-    {
-      const char *ext = riscv_supported_std_ext[i].name;
-      riscv_ext_order[(*ext - 'a')] = order++;
-      i++;
-      while (riscv_supported_std_ext[i].name
-	     && strcmp (ext, riscv_supported_std_ext[i].name) == 0)
-	i++;
-    }
+  for (const char *ext = &riscv_ext_canonical_order[0];
+       *ext != NULL;
+       ++ext)
+    riscv_ext_order[(*ext - 'a')] = order++;
 
   /* Some of the prefixed keyword are not single letter, so we set
      their prefixed orders in the riscv_compare_subsets directly,
-- 
2.34.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Maintain a string to hold the canonical order
  2022-02-21 14:47 [PATCH] RISC-V: Maintain a string to hold the canonical order Kito Cheng
@ 2022-02-21 14:50 ` Tsukasa OI
  2022-02-21 15:02 ` Tsukasa OI
  1 sibling, 0 replies; 4+ messages in thread
From: Tsukasa OI @ 2022-02-21 14:50 UTC (permalink / raw)
  To: Binutils

+1.

On 2022/02/21 23:47, Kito Cheng wrote:
> Using dummy entry in riscv_supported_std_ext cause confusing and wrongly
> support `b` and `k` extensions.
> 
> bfd/
> 	* elfxx-riscv.c (riscv_supported_std_ext): Drop unsupported
> 	extensions.
> 	(riscv_ext_canonical_order): New.
> 	(riscv_init_ext_order): Use riscv_ext_canonical_order rather
> 	than riscv_supported_std_ext to compute canonical order.
> ---
>  bfd/elfxx-riscv.c | 24 +++++++-----------------
>  1 file changed, 7 insertions(+), 17 deletions(-)
> 
> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
> index 9f52bb545ac..17633e6fae2 100644
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -1163,17 +1163,10 @@ static struct riscv_supported_ext riscv_supported_std_ext[] =
>    {"q",		ISA_SPEC_CLASS_20191213,	2, 2, 0 },
>    {"q",		ISA_SPEC_CLASS_20190608,	2, 2, 0 },
>    {"q",		ISA_SPEC_CLASS_2P2,		2, 0, 0 },
> -  {"l",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"c",		ISA_SPEC_CLASS_20191213,	2, 0, 0 },
>    {"c",		ISA_SPEC_CLASS_20190608,	2, 0, 0 },
>    {"c",		ISA_SPEC_CLASS_2P2,		2, 0, 0 },
> -  {"b",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"k",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"j",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"t",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"p",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"v",		ISA_SPEC_CLASS_DRAFT,		1, 0, 0 },
> -  {"n",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {NULL, 0, 0, 0, 0}
>  };
>  
> @@ -1341,6 +1334,9 @@ riscv_recognized_prefixed_ext (const char *ext)
>    return false;
>  }
>  
> +/* Canonical order for single letter extensions.  */
> +static const char riscv_ext_canonical_order[] = "eigmafdqlcbjktpvn";
> +
>  /* Array is used to compare the orders of standard extensions quickly.  */
>  static int riscv_ext_order[26] = {0};
>  
> @@ -1356,16 +1352,10 @@ riscv_init_ext_order (void)
>    /* The orders of all standard extensions are positive.  */
>    int order = 1;
>  
> -  int i = 0;
> -  while (riscv_supported_std_ext[i].name != NULL)
> -    {
> -      const char *ext = riscv_supported_std_ext[i].name;
> -      riscv_ext_order[(*ext - 'a')] = order++;
> -      i++;
> -      while (riscv_supported_std_ext[i].name
> -	     && strcmp (ext, riscv_supported_std_ext[i].name) == 0)
> -	i++;
> -    }
> +  for (const char *ext = &riscv_ext_canonical_order[0];
> +       *ext != NULL;
> +       ++ext)
> +    riscv_ext_order[(*ext - 'a')] = order++;
>  
>    /* Some of the prefixed keyword are not single letter, so we set
>       their prefixed orders in the riscv_compare_subsets directly,

Reviewed-by: Tsukasa OI <research_trasio@irq.a4lg.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Maintain a string to hold the canonical order
  2022-02-21 14:47 [PATCH] RISC-V: Maintain a string to hold the canonical order Kito Cheng
  2022-02-21 14:50 ` Tsukasa OI
@ 2022-02-21 15:02 ` Tsukasa OI
  2022-02-21 15:12   ` Kito Cheng
  1 sibling, 1 reply; 4+ messages in thread
From: Tsukasa OI @ 2022-02-21 15:02 UTC (permalink / raw)
  To: Kito Cheng; +Cc: Binutils

I missed one.

On 2022/02/21 23:47, Kito Cheng wrote:
> Using dummy entry in riscv_supported_std_ext cause confusing and wrongly
> support `b` and `k` extensions.
> 
> bfd/
> 	* elfxx-riscv.c (riscv_supported_std_ext): Drop unsupported
> 	extensions.
> 	(riscv_ext_canonical_order): New.
> 	(riscv_init_ext_order): Use riscv_ext_canonical_order rather
> 	than riscv_supported_std_ext to compute canonical order.
> ---
>  bfd/elfxx-riscv.c | 24 +++++++-----------------
>  1 file changed, 7 insertions(+), 17 deletions(-)
> 
> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
> index 9f52bb545ac..17633e6fae2 100644
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -1163,17 +1163,10 @@ static struct riscv_supported_ext riscv_supported_std_ext[] =
>    {"q",		ISA_SPEC_CLASS_20191213,	2, 2, 0 },
>    {"q",		ISA_SPEC_CLASS_20190608,	2, 2, 0 },
>    {"q",		ISA_SPEC_CLASS_2P2,		2, 0, 0 },
> -  {"l",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"c",		ISA_SPEC_CLASS_20191213,	2, 0, 0 },
>    {"c",		ISA_SPEC_CLASS_20190608,	2, 0, 0 },
>    {"c",		ISA_SPEC_CLASS_2P2,		2, 0, 0 },
> -  {"b",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"k",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"j",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"t",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> -  {"p",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"v",		ISA_SPEC_CLASS_DRAFT,		1, 0, 0 },
> -  {"n",		ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {NULL, 0, 0, 0, 0}
>  };
>  
> @@ -1341,6 +1334,9 @@ riscv_recognized_prefixed_ext (const char *ext)
>    return false;
>  }
>  
> +/* Canonical order for single letter extensions.  */
> +static const char riscv_ext_canonical_order[] = "eigmafdqlcbjktpvn";
> +
>  /* Array is used to compare the orders of standard extensions quickly.  */
>  static int riscv_ext_order[26] = {0};
>  
> @@ -1356,16 +1352,10 @@ riscv_init_ext_order (void)
>    /* The orders of all standard extensions are positive.  */
>    int order = 1;
>  
> -  int i = 0;
> -  while (riscv_supported_std_ext[i].name != NULL)
> -    {
> -      const char *ext = riscv_supported_std_ext[i].name;
> -      riscv_ext_order[(*ext - 'a')] = order++;
> -      i++;
> -      while (riscv_supported_std_ext[i].name
> -	     && strcmp (ext, riscv_supported_std_ext[i].name) == 0)
> -	i++;
> -    }
> +  for (const char *ext = &riscv_ext_canonical_order[0];
> +       *ext != NULL;

Just "*ext" or "*ext != '\0'"? comparing a const char (not pointer) with
NULL looks a bit odd.

> +       ++ext)
> +    riscv_ext_order[(*ext - 'a')] = order++;
>  
>    /* Some of the prefixed keyword are not single letter, so we set
>       their prefixed orders in the riscv_compare_subsets directly,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Maintain a string to hold the canonical order
  2022-02-21 15:02 ` Tsukasa OI
@ 2022-02-21 15:12   ` Kito Cheng
  0 siblings, 0 replies; 4+ messages in thread
From: Kito Cheng @ 2022-02-21 15:12 UTC (permalink / raw)
  To: Tsukasa OI; +Cc: Kito Cheng, Binutils

> Just "*ext" or "*ext != '\0'"? comparing a const char (not pointer) with
> NULL looks a bit odd.

Thanks for catching that, that's functional equivalent, but definitely
wrong semantic.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-21 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 14:47 [PATCH] RISC-V: Maintain a string to hold the canonical order Kito Cheng
2022-02-21 14:50 ` Tsukasa OI
2022-02-21 15:02 ` Tsukasa OI
2022-02-21 15:12   ` Kito Cheng

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).