答复: [PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-09-27 Thread gengqi via Gcc-patches
Sorry, I sent the wrong one.

-邮件原件-
发件人: Geng Qi [mailto:gen...@linux.alibaba.com] 
发送时间: 2021年9月27日 19:25
收件人: gcc-patches@gcc.gnu.org; cooper...@linux.alibaba.com
抄送: gengqi 
主题: [PATCH] RISC-V: The 'multilib-generator' enhancement.

From: gengqi 

gcc/ChangeLog:
* config/riscv/arch-canonicalize
(longext_sort): New function for sorting 'multi-letter'.
* config/riscv/multilib-generator: Skip to next loop when current
'alt' is 'arch'. The 'arch' may not be the first of 'alts'.
(_expand_combination): Add underline for the ext without '*'.
This is because, a single-letter extension can always be treated
well
with a '_' prefix, but it cannot be separated out if it is appended
to a multi-letter.
---
 gcc/config/riscv/arch-canonicalize  | 14 +-
gcc/config/riscv/multilib-generator | 12 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/arch-canonicalize
b/gcc/config/riscv/arch-canonicalize
index 2b4289e..a1e4570 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -74,8 +74,20 @@ def arch_canonicalize(arch):
   # becasue we just append extensions list to the arch string.
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
+  def longext_sort (exts):
+if not exts.startswith("zxm") and exts.startswith("z"):
+  # If "Z" extensions are named, they should be ordered first by
CANONICAL.
+  if exts[1] not in CANONICAL_ORDER:
+raise Exception("Unsupported extension `%s`" % exts)
+  canonical_sort = CANONICAL_ORDER.index(exts[1])
+else:
+  canonical_sort = -1
+return (exts.startswith("x"), exts.startswith("zxm"),
+LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+
   # Multi-letter extension must be in lexicographic order.
-  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
+  key=longext_sort))
 
   # Put extensions in canonical order.
   for ext in CANONICAL_ORDER:
diff --git a/gcc/config/riscv/multilib-generator
b/gcc/config/riscv/multilib-generator
index 64ff15f..7b22537 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -68,15 +68,15 @@ def arch_canonicalize(arch):
 def _expand_combination(ext):
   exts = list(ext.split("*"))
 
-  # No need to expand if there is no `*`.
-  if len(exts) == 1:
-return [(exts[0],)]
-
   # Add underline to every extension.
   # e.g.
   #  _b * zvamo => _b * _zvamo
   exts = list(map(lambda x: '_' + x, exts))
 
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
   # Generate combination!
   ext_combs = []
   for comb_len in range(1, len(exts)+1):
@@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
   # Drop duplicated entry.
   alts = unique(alts)
 
-  for alt in alts[1:]:
+  for alt in alts:
+if alt == arch:
+  continue
 arches[alt] = 1
 reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt,
abi))
   required.append('march=%s/mabi=%s' % (arch, abi))
--
2.7.4



[PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-09-27 Thread Geng Qi via Gcc-patches
From: gengqi 

gcc/ChangeLog:
* config/riscv/arch-canonicalize
(longext_sort): New function for sorting 'multi-letter'.
* config/riscv/multilib-generator: Skip to next loop when current
'alt' is 'arch'. The 'arch' may not be the first of 'alts'.
(_expand_combination): Add underline for the ext without '*'.
This is because, a single-letter extension can always be treated well
with a '_' prefix, but it cannot be separated out if it is appended
to a multi-letter.
---
 gcc/config/riscv/arch-canonicalize  | 14 +-
 gcc/config/riscv/multilib-generator | 12 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/arch-canonicalize 
b/gcc/config/riscv/arch-canonicalize
index 2b4289e..a1e4570 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -74,8 +74,20 @@ def arch_canonicalize(arch):
   # becasue we just append extensions list to the arch string.
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
+  def longext_sort (exts):
+if not exts.startswith("zxm") and exts.startswith("z"):
+  # If "Z" extensions are named, they should be ordered first by CANONICAL.
+  if exts[1] not in CANONICAL_ORDER:
+raise Exception("Unsupported extension `%s`" % exts)
+  canonical_sort = CANONICAL_ORDER.index(exts[1])
+else:
+  canonical_sort = -1
+return (exts.startswith("x"), exts.startswith("zxm"),
+LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+
   # Multi-letter extension must be in lexicographic order.
-  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
+  key=longext_sort))
 
   # Put extensions in canonical order.
   for ext in CANONICAL_ORDER:
diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index 64ff15f..7b22537 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -68,15 +68,15 @@ def arch_canonicalize(arch):
 def _expand_combination(ext):
   exts = list(ext.split("*"))
 
-  # No need to expand if there is no `*`.
-  if len(exts) == 1:
-return [(exts[0],)]
-
   # Add underline to every extension.
   # e.g.
   #  _b * zvamo => _b * _zvamo
   exts = list(map(lambda x: '_' + x, exts))
 
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
   # Generate combination!
   ext_combs = []
   for comb_len in range(1, len(exts)+1):
@@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
   # Drop duplicated entry.
   alts = unique(alts)
 
-  for alt in alts[1:]:
+  for alt in alts:
+if alt == arch:
+  continue
 arches[alt] = 1
 reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
   required.append('march=%s/mabi=%s' % (arch, abi))
-- 
2.7.4



Re: [PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-01-18 Thread Kito Cheng via Gcc-patches
Hi Geng Qi:

Thanks for your patch, committed!


On Mon, Jan 18, 2021 at 3:01 PM Geng Qi via Gcc-patches
 wrote:
>
> From: gengqi 
>
> Think about this case:
>   ./multilib-generator rv32imc-ilp32-rv32imac,rv32imacxthead-f
> Here are 2 problems:
>   1. A unexpected 'xtheadf' extension was made.
>   2. The arch 'rv32imac' was not be created.
> This modification fix these two, and also sorts 'multi-letter'.
>
> gcc/ChangeLog:
> * config/riscv/arch-canonicalize
> (longext_sort): New function for sorting 'multi-letter'.
> * config/riscv/multilib-generator: Adjusting the loop of 'alt' in
> 'alts'. The 'arch' may not be the first of 'alts'.
> (_expand_combination): Add underline for the 'ext' without '*'.
> This is because, a single-letter extension can always be treated well
> with a '_' prefix, but it cannot be separated out if it is appended
> to a multi-letter.
> ---
>  gcc/config/riscv/arch-canonicalize  | 14 +-
>  gcc/config/riscv/multilib-generator | 12 +++-
>  2 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/config/riscv/arch-canonicalize 
> b/gcc/config/riscv/arch-canonicalize
> index 2b4289e..a1e4570 100755
> --- a/gcc/config/riscv/arch-canonicalize
> +++ b/gcc/config/riscv/arch-canonicalize
> @@ -74,8 +74,20 @@ def arch_canonicalize(arch):
># becasue we just append extensions list to the arch string.
>std_exts += list(filter(lambda x:len(x) == 1, long_exts))
>
> +  def longext_sort (exts):
> +if not exts.startswith("zxm") and exts.startswith("z"):
> +  # If "Z" extensions are named, they should be ordered first by 
> CANONICAL.
> +  if exts[1] not in CANONICAL_ORDER:
> +raise Exception("Unsupported extension `%s`" % exts)
> +  canonical_sort = CANONICAL_ORDER.index(exts[1])
> +else:
> +  canonical_sort = -1
> +return (exts.startswith("x"), exts.startswith("zxm"),
> +LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
> +
># Multi-letter extension must be in lexicographic order.
> -  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
> +  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
> +  key=longext_sort))
>
># Put extensions in canonical order.
>for ext in CANONICAL_ORDER:
> diff --git a/gcc/config/riscv/multilib-generator 
> b/gcc/config/riscv/multilib-generator
> index 64ff15f..7b22537 100755
> --- a/gcc/config/riscv/multilib-generator
> +++ b/gcc/config/riscv/multilib-generator
> @@ -68,15 +68,15 @@ def arch_canonicalize(arch):
>  def _expand_combination(ext):
>exts = list(ext.split("*"))
>
> -  # No need to expand if there is no `*`.
> -  if len(exts) == 1:
> -return [(exts[0],)]
> -
># Add underline to every extension.
># e.g.
>#  _b * zvamo => _b * _zvamo
>exts = list(map(lambda x: '_' + x, exts))
>
> +  # No need to expand if there is no `*`.
> +  if len(exts) == 1:
> +return [(exts[0],)]
> +
># Generate combination!
>ext_combs = []
>for comb_len in range(1, len(exts)+1):
> @@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
># Drop duplicated entry.
>alts = unique(alts)
>
> -  for alt in alts[1:]:
> +  for alt in alts:
> +if alt == arch:
> +  continue
>  arches[alt] = 1
>  reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
>required.append('march=%s/mabi=%s' % (arch, abi))
> --
> 2.7.4
>


[PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-01-17 Thread Geng Qi via Gcc-patches
From: gengqi 

Think about this case:
  ./multilib-generator rv32imc-ilp32-rv32imac,rv32imacxthead-f
Here are 2 problems:
  1. A unexpected 'xtheadf' extension was made.
  2. The arch 'rv32imac' was not be created.
This modification fix these two, and also sorts 'multi-letter'.

gcc/ChangeLog:
* config/riscv/arch-canonicalize
(longext_sort): New function for sorting 'multi-letter'.
* config/riscv/multilib-generator: Adjusting the loop of 'alt' in
'alts'. The 'arch' may not be the first of 'alts'.
(_expand_combination): Add underline for the 'ext' without '*'.
This is because, a single-letter extension can always be treated well
with a '_' prefix, but it cannot be separated out if it is appended
to a multi-letter.
---
 gcc/config/riscv/arch-canonicalize  | 14 +-
 gcc/config/riscv/multilib-generator | 12 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/arch-canonicalize 
b/gcc/config/riscv/arch-canonicalize
index 2b4289e..a1e4570 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -74,8 +74,20 @@ def arch_canonicalize(arch):
   # becasue we just append extensions list to the arch string.
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
+  def longext_sort (exts):
+if not exts.startswith("zxm") and exts.startswith("z"):
+  # If "Z" extensions are named, they should be ordered first by CANONICAL.
+  if exts[1] not in CANONICAL_ORDER:
+raise Exception("Unsupported extension `%s`" % exts)
+  canonical_sort = CANONICAL_ORDER.index(exts[1])
+else:
+  canonical_sort = -1
+return (exts.startswith("x"), exts.startswith("zxm"),
+LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+
   # Multi-letter extension must be in lexicographic order.
-  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
+  key=longext_sort))
 
   # Put extensions in canonical order.
   for ext in CANONICAL_ORDER:
diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index 64ff15f..7b22537 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -68,15 +68,15 @@ def arch_canonicalize(arch):
 def _expand_combination(ext):
   exts = list(ext.split("*"))
 
-  # No need to expand if there is no `*`.
-  if len(exts) == 1:
-return [(exts[0],)]
-
   # Add underline to every extension.
   # e.g.
   #  _b * zvamo => _b * _zvamo
   exts = list(map(lambda x: '_' + x, exts))
 
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
   # Generate combination!
   ext_combs = []
   for comb_len in range(1, len(exts)+1):
@@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
   # Drop duplicated entry.
   alts = unique(alts)
 
-  for alt in alts[1:]:
+  for alt in alts:
+if alt == arch:
+  continue
 arches[alt] = 1
 reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
   required.append('march=%s/mabi=%s' % (arch, abi))
-- 
2.7.4



[PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-01-17 Thread Geng Qi via Gcc-patches
From: gengqi 

gcc/ChangeLog:
* config/riscv/arch-canonicalize
(longext_sort): New function for sorting 'multi-letter'.
* config/riscv/multilib-generator: Adjusting the loop of 'alt' in
'alts'. The 'arch' may not be the first of 'alts'.
(_expand_combination): Add underline for the 'ext' without '*'.
This is because, a single-letter extension can always be treated well
with a '_' prefix, but it cannot be separated out if it is appended
to a multi-letter.
---
 gcc/config/riscv/arch-canonicalize  | 14 +-
 gcc/config/riscv/multilib-generator | 12 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/arch-canonicalize 
b/gcc/config/riscv/arch-canonicalize
index 2b4289e..a1e4570 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -74,8 +74,20 @@ def arch_canonicalize(arch):
   # becasue we just append extensions list to the arch string.
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
+  def longext_sort (exts):
+if not exts.startswith("zxm") and exts.startswith("z"):
+  # If "Z" extensions are named, they should be ordered first by CANONICAL.
+  if exts[1] not in CANONICAL_ORDER:
+raise Exception("Unsupported extension `%s`" % exts)
+  canonical_sort = CANONICAL_ORDER.index(exts[1])
+else:
+  canonical_sort = -1
+return (exts.startswith("x"), exts.startswith("zxm"),
+LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+
   # Multi-letter extension must be in lexicographic order.
-  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
+  key=longext_sort))
 
   # Put extensions in canonical order.
   for ext in CANONICAL_ORDER:
diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index 64ff15f..7b22537 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -68,15 +68,15 @@ def arch_canonicalize(arch):
 def _expand_combination(ext):
   exts = list(ext.split("*"))
 
-  # No need to expand if there is no `*`.
-  if len(exts) == 1:
-return [(exts[0],)]
-
   # Add underline to every extension.
   # e.g.
   #  _b * zvamo => _b * _zvamo
   exts = list(map(lambda x: '_' + x, exts))
 
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
   # Generate combination!
   ext_combs = []
   for comb_len in range(1, len(exts)+1):
@@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
   # Drop duplicated entry.
   alts = unique(alts)
 
-  for alt in alts[1:]:
+  for alt in alts:
+if alt == arch:
+  continue
 arches[alt] = 1
 reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
   required.append('march=%s/mabi=%s' % (arch, abi))
-- 
2.7.4