Re: [Patch ,gcc/MIPS] add an build-time/runtime option to disable madd.fmt

2016-12-24 Thread Yunqiang Su

> 在 2016年12月22日,23:31,Richard Sandiford  写道:
> 
> Matthew Fortune  writes:
>> Sandra Loosemore  writes:
>>> On 12/21/2016 11:54 AM, Yunqiang Su wrote:
 By this patch, I add a build-time option ` --with-unfused-madd4=yes/no',
 and runtime option -m(no-)unfused-madd4,
 to disable generate madd.fmt instructions.
>>> 
>>> Your patch also needs a documentation change so that the new
>>> command-line option is listed in the GCC manual with other MIPS target
>>> options.
>> 
>> Any opinions on option names to control this? Is it best to target the 
>> specific
>> feature that is non-compliant on loongson or apply a general -mfix-loongson
>> type option?
>> 
>> I'm not sure I have a strong opinion either way but there do seem to be
>> multiple possible variants.
> 
> Wasn't sure from this thread whether Loongson simply had a fused
> implementation (without intermediate rounding) or whether the

I test some cases on Loongson 3A 1000 with glibc’s test: math/test-double.
-march=mips64r2

1.  set ISA_HAS_FUSED_MADD4 1
 set ISA_HAS_UNFUSED_MADD4 0
   
 56 errors occurred, which is the same with amd64 with avx2 enabled.

2.  set ISA_HAS_FUSED_MADD4 0
 set ISA_HAS_UNFUSED_MADD4 0

no error happens

3. set ISA_HAS_FUSED_MADD4 0
set ISA_HAS_UNFUSED_MADD4 1
   
816 errors occurred.
  
So it seems Loongson’s madd.fmt is are fused.


> instructions gave numerically incorrect results for some inputs.
> It sounds from a later thread like it's generating incorrect results,
> is that right?  If so, then FWIW I agree an -mfix option would be more
> consistent.  E.g. one of the -mfix-vr4120 errata was an incorrect
> integer division result and one of the -mfix-sb1 errata was an incorrect
> single-precision float division result.  The latter case could have been
> handled by an option to disable DIV.S and DIV.PS, but the -mfix option
> gave more control.
> 
> If instead the problem is that the instructions are fused then that's
> also what the original MIPS 4 parts did, so maybe an option to control
> fusedness would make sense.

Since for binary Linux distributions, like Debian, we need to generate
generic output, we will need an option to disable madd.fmt at all.

Besides this, should we have another options, like
-mmadd-is-fused
-mno-madd-is-fused
?

Ohh, maybe we should have options like these?
build-time
 —with-madd=fused/unfused/no
runtime
 -mmadd=fused/unfused/no


> 
> Thanks,
> Richard



[patch mips/gcc] add build-time and runtime options to disable or set madd.fmt type

2016-12-24 Thread Yunqiang Su
By this patch, I add 
build-time options:
 —with-madd4=unfused/fused/no
runtime options:
 -mmadd4=unfused/fused/no

to disable or set madd.fmt type.

For MIPS r6 (TARGET_MIPS8000) and Loongson (TARGET_LOONGSON_3A), 
it always generate fused madd.fmt or maddf.fmt.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 7afbc54bc78..7176d4484f7 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3940,7 +3940,7 @@ case "${target}" in
;;
 
mips*-*-*)
-   supported_defaults="abi arch arch_32 arch_64 float fpu nan 
fp_32 odd_spreg_32 tune tune_32 tune_64 divide llsc mips-plt synci"
+   supported_defaults="abi arch arch_32 arch_64 float fpu nan 
fp_32 odd_spreg_32 madd4 tune tune_32 tune_64 divide llsc mips-plt synci"
 
case ${with_float} in
"" | soft | hard)
@@ -3997,6 +3997,16 @@ case "${target}" in
exit 1
;;
esac
+   
+   case ${with_madd4} in
+   "" | fused | unfused | no)
+   # OK
+   ;;
+   *)
+   echo "Unknown madd4 type used in 
--with-madd4=$with_madd4" 1>&2
+   exit 1
+   ;;
+   esac
 
case ${with_abi} in
"" | 32 | o64 | n32 | 64 | eabi)
@@ -4496,7 +4506,7 @@ case ${target} in
 esac
 
 t=
-all_defaults="abi cpu cpu_32 cpu_64 arch arch_32 arch_64 tune tune_32 tune_64 
schedule float mode fpu nan fp_32 odd_spreg_32 divide llsc mips-plt synci tls"
+all_defaults="abi cpu cpu_32 cpu_64 arch arch_32 arch_64 tune tune_32 tune_64 
schedule float mode fpu nan fp_32 odd_spreg_32 madd4 divide llsc mips-plt synci 
tls"
 for option in $all_defaults
 do
eval "val=\$with_"`echo $option | sed s/-/_/g`
diff --git a/gcc/config/mips/mips-opts.h b/gcc/config/mips/mips-opts.h
index 40aa006bc4e..ea1e0ea5310 100644
--- a/gcc/config/mips/mips-opts.h
+++ b/gcc/config/mips/mips-opts.h
@@ -34,6 +34,13 @@ enum mips_ieee_754_setting {
   MIPS_IEEE_754_2008
 };
 
+/* Enumerates the setting of the -mmadd4 option.  */
+enum mips_madd4_setting {
+  MIPS_MADD4_DEFAULT,
+  MIPS_MADD4_UNFUSED,
+  MIPS_MADD4_FUSED,
+  MIPS_MADD4_NO
+};
 /* Enumerates the setting of the -mr10k-cache-barrier option.  */
 enum mips_r10k_cache_barrier_setting {
   R10K_CACHE_BARRIER_NONE,
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index bb66c428dd1..e8ca94ac709 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -863,6 +863,7 @@ struct mips_cpu_info {

":%{!msoft-float:%{!msingle-float:%{!mfp*:%{!mmsa:-mfp%(VALUE)}" }, \
   {"odd_spreg_32", "%{" OPT_ARCH32 ":%{!msoft-float:%{!msingle-float:" \
   "%{!modd-spreg:%{!mno-odd-spreg:-m%(VALUE)}" }, \
+  {"madd4", "%{!mmadd4=*:-mmadd4=%(VALUE)}" }, \
   {"divide", "%{!mdivide-traps:%{!mdivide-breaks:-mdivide-%(VALUE)}}" }, \
   {"llsc", "%{!mllsc:%{!mno-llsc:-m%(VALUE)}}" }, \
   {"mips-plt", "%{!mplt:%{!mno-plt:-m%(VALUE)}}" }, \
@@ -1056,11 +1057,12 @@ struct mips_cpu_info {
 
 /* ISA has 4 operand fused madd instructions of the form
'd = [+-] (a * b [+-] c)'.  */
-#define ISA_HAS_FUSED_MADD4TARGET_MIPS8000
+#define ISA_HAS_FUSED_MADD4(TARGET_MIPS8000 || TARGET_LOONGSON_3A || 
(mips_madd4==MIPS_MADD4_FUSED))
 
 /* ISA has 4 operand unfused madd instructions of the form
'd = [+-] (a * b [+-] c)'.  */
-#define ISA_HAS_UNFUSED_MADD4  (ISA_HAS_FP4 && !TARGET_MIPS8000)
+#define ISA_HAS_UNFUSED_MADD4  (ISA_HAS_FP4 && !TARGET_MIPS8000 && 
!TARGET_LOONGSON_3A && \
+   (mips_madd4!=MIPS_MADD4_FUSED) && (mips_madd4!=MIPS_MADD4_NO))
 
 /* ISA has 3 operand r6 fused madd instructions of the form
'c = c [+-] (a * b)'.  */
diff --git a/gcc/config/mips/mips.opt b/gcc/config/mips/mips.opt
index 08dd83e14ce..0d9a6e4362e 100644
--- a/gcc/config/mips/mips.opt
+++ b/gcc/config/mips/mips.opt
@@ -416,6 +416,23 @@ modd-spreg
 Target Report Mask(ODD_SPREG)
 Enable use of odd-numbered single-precision registers.
 
+mmadd4=
+Target RejectNegative Joined Enum(mips_madd4_value) Var(mips_madd4) 
Init(MIPS_MADD4_DEFAULT)
+-mmadd4=TYPE   Select madd.fmt/msub.fmt type.
+
+Enum
+Name(mips_madd4_value) Type(int)
+Known MIPS madd.fmt type settings (for use with the -mmadd4 options):
+
+EnumValue
+Enum(mips_madd4_value) String(unfused) Value(MIPS_MADD4_UNFUSED)
+
+EnumValue
+Enum(mips_madd4_value) String(fused) Value(MIPS_MADD4_FUSED)
+
+EnumValue
+Enum(mips_madd4_value) String(no) Value(MIPS_MADD4_NO)
+
 mframe-header-opt
 Target Report Var(flag_frame_header_optimization) Optimization
 Optimize frame header.
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index b911d76dd66..e548733537d 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1338,6 +1338,23 @@ In the absence of this configuration option the default 
convention is
 the legacy encoding, as when neither of the

Re: Pretty printers for versioned namespace

2016-12-24 Thread François Dumont

On 15/12/2016 15:57, Jonathan Wakely wrote:


And we could avoid three re.match expressions with complicated regular
expressions by creating a helper function to do the "startswith"
checks:

def is_specialization_of(type, template_name):
   return re.match('^std::(%s)?%s<.*>$' % (vers_nsp, template_name), 
type) is not None


Then replace impl_type.startswith('std::__uniq_ptr_impl<') with
is_specialization_of(impl_type, '__uniq_ptr_impl')

And replace impl_type.startswith('std::tuple<') with
is_specialization_of(impl_type, 'tuple')

And replace nodetype.name.startswith('std::_Rb_tree_node') with
is_specialization_of(nodetype.name, '_Rb_tree_node')

That makes the code much easier to read.


I agree that hiding the version namespace will be nicer. I just hope it 
is possible. I don't think we can really dictate gdb to hide this 
namespace during the rendering. In the attached path you will see what I 
tried to do. Problem is that I am not sure that printers.py is 
intercepting rendering of all types so version namespace will stay 
visible in those cases.


I think the 2 failures that I have with this patch are reflecting this 
problem:


type = holderstd::__7::char_traits, std::__7::allocator > >
got: type = holderstd::__7::char_traits, std::__7::allocator > >

FAIL: libstdc++-prettyprinters/whatis.cc whatis ustring_holder
type = holderstd::__7::char_traits, std::__7::allocator > >
got: type = holderstd::__7::char_traits, std::__7::allocator > >

FAIL: libstdc++-prettyprinters/whatis.cc whatis sstring_holder

Shall I simply use regex in those cases and adopt this approach ?

François


diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 86de1ca..55bdee9 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -36,6 +36,8 @@ import sys
 # We probably can't do much about this until this GDB PR is addressed:
 # 
 
+vers_nsp = '__7::'
+
 if sys.version_info[0] > 2:
 ### Python 3 stuff
 Iterator = object
@@ -100,11 +102,15 @@ def find_type(orig, name):
 raise ValueError("Cannot find type %s::%s" % (str(orig), name))
 typ = field.type
 
+# Test if a type is a given template instantiation.
+def is_specialization_of(type, template_name):
+   return re.match('^std::(%s)?%s<.*>$' % (vers_nsp, template_name), type) is not None
+
 class SharedPointerPrinter:
 "Print a shared_ptr or weak_ptr"
 
 def __init__ (self, typename, val):
-self.typename = typename
+self.typename = typename.replace(vers_nsp, '')
 self.val = val
 
 def to_string (self):
@@ -127,9 +133,9 @@ class UniquePointerPrinter:
 
 def to_string (self):
 impl_type = self.val.type.fields()[0].type.tag
-if impl_type.startswith('std::__uniq_ptr_impl<'): # New implementation
+if is_specialization_of(impl_type, '__uniq_ptr_impl'): # New implementation
 v = self.val['_M_t']['_M_t']['_M_head_impl']
-elif impl_type.startswith('std::tuple<'):
+elif is_specialization_of(impl_type, 'tuple'):
 v = self.val['_M_t']['_M_head_impl']
 else:
 raise ValueError("Unsupported implementation for unique_ptr: %s" % self.val.type.fields()[0].type.tag)
@@ -179,7 +185,7 @@ class StdListPrinter:
 return ('[%d]' % count, val)
 
 def __init__(self, typename, val):
-self.typename = typename
+self.typename = typename.replace(vers_nsp, '')
 self.val = val
 
 def children(self):
@@ -299,7 +305,7 @@ class StdVectorPrinter:
 return ('[%d]' % count, elt)
 
 def __init__(self, typename, val):
-self.typename = typename
+self.typename = typename.replace(vers_nsp, '')
 self.val = val
 self.is_bool = val.type.template_argument(0).code  == gdb.TYPE_CODE_BOOL
 
@@ -403,7 +409,7 @@ class StdTuplePrinter:
 return ('[%d]' % self.count, impl['_M_head_impl'])
 
 def __init__ (self, typename, val):
-self.typename = typename
+self.typename = typename.replace(vers_nsp, '')
 self.val = val;
 
 def children (self):
@@ -418,7 +424,7 @@ class StdStackOrQueuePrinter:
 "Print a std::stack or std::queue"
 
 def __init__ (self, typename, val):
-self.typename = typename
+self.typename = typename.replace(vers_nsp, '')
 self.visualizer = gdb.default_visualizer(val['c'])
 
 def children (self):
@@ -496,7 +502,10 @@ class StdRbtreeIteratorPrinter:
 def __init__ (self, typename, val):
 self.val = val
 valtype = self.val.type.template_argument(0).strip_typedefs()
-nodetype = gdb.lookup_type('std::_Rb_tree_node<' + str(valtype) + '>')
+if typename.startswith('std::' + vers_nsp):
+nodetype = gdb.lookup_type('std::' + vers_nsp + '_Rb_tree_node<' + str(valtype) + '>')
+else:
+

[PATCH] Sync config.sub with upstream

2016-12-24 Thread Jeremy Soller
Add support for Redox OS and fix a bug with PRU machine.

diff --git a/config.sub b/config.sub
index 3478c1f..62b8259 100755
--- a/config.sub
+++ b/config.sub
@@ -2,7 +2,7 @@
 # Configuration validation subroutine script.
 #   Copyright 1992-2016 Free Software Foundation, Inc.

-timestamp='2016-11-19'
+timestamp='2016-12-24'

 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -1409,7 +1409,7 @@ case $os in
  | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
  | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
  | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
- | -onefs* | -tirtos* | -phoenix* | -fuchsia*)
+ | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
@@ -1638,6 +1638,9 @@ case $basic_machine in
sparc-* | *-sun)
os=-sunos4.1.1
;;
+   pru-*)
+   os=-elf
+   ;;
*-be)
os=-beos
;;