[PATCH] MIPS: IEEE 754-2008 NaN encoding features

Maciej W. Rozycki macro@codesourcery.com
Mon Jul 8 15:44:00 GMT 2013


On Sat, 8 Dec 2012, Richard Sandiford wrote:

> >> >  As many of you have been aware it has been a long practice for software 
> >> > using IEEE 754 floating-point arithmetic run on MIPS processors to use an 
> >> > encoding of Not-a-Number (NaN) data different to one used by software run 
> >> > on other processors.  And as of IEEE 754-2008 revision this encoding does 
> >> > not follow one recommended in the standard, as specified in section 6.2.1, 
> >> > where it is stated that quiet NaNs should have the first bit (d1) of their 
> >> > significand set to 1 while signalling NaNs should have that bit set to 0, 
> >> > but MIPS software interprets the two bits in the opposite manner.
> >> >
> >> >  An upcoming MIPS Architecture revision will provide for processors that 
> >> > support the IEEE 754-2008 preferred NaN encoding format.  As the two 
> >> > formats (further referred to as "legacy NaN" and "2008 NaN") are 
> >> > incompatible to each other, tools will have to provide support for the two 
> >> > formats to help people avoid using incompatible binary modules.  Here is 
> >> > the binutils part.
> >> >
> >> >  Two new entities have been added to support static and dynamic linking.  
> >> > For the former a set of new ELF file attribute values have been defined.  
> >> > For the latter a new ELF file header flag has been defined.  These changes 
> >> > are described in detail below.
> >> 
> >> But an ELF flag supports static and dynamic linking on its own.
> >> Encoding the same information in the attribute seems redundant,
> >> and makes the implementation a fair bit more complicated.
> >
> >  Sources need to be annotated as NaN encodings will be present within them 
> > -- .gnu_attribute is suited for this purpose.  The header flag is required 
> > so that the kernel configures the FPU appropriately or rejects binaries 
> > that are incompatible with hardware being used that does not support the 
> > NaN encoding requested and also so that ld.so refuses to load incompatible 
> > modules together.
> >
> >  Do you have any better proposal?  I can drop the setting on the header 
> > flag on relocatables and keep it on final binaries only if that made you 
> > feel better.
> 
> Well, I don't agree the source _needs_ to be annotated with the NaN encoding.
> The annotation is as easy to forget as the command-line option.

 I disagree.  Source is usually annotated by the producer, be it a person 
who wrote the code or a compiler or a similar tool.  Command-line options 
on the other hand are often interfered with by random people building 
pieces of software, not necessarily skilled enough to understand 
consequences of using the wrong option unless an error or at least a 
warning is produced.

 In most cases using an option that would produce a broken binary, e.g. 
-KPIC on a non-PIC source that uses explicit relocs, causes the assembly 
to fail, or at the very least a link error later on.  And if somehow 
there's no error, then the resulting code will work correctly (i.e. there 
was nothing in that code that was incompatible with the PIC code model).  
Similarly, if the wrong -march= option is used, then the resulting code 
will (in most cases, i.e. modulo processor errata/oversights/etc.) crash 
if run on not capable enough a processor rather than producing incorrect 
results.

 Here only data encoding changes and that'll never cause an error; instead 
incorrect results will be produced by software for certain data inputs.  
And I think tools should provide some (i.e. reasonable) level of 
protection against producing broken code.

>  However,
> I realise that's a bit of a religious debate, and that others think that:
> 
>    gcc -c foo.c -mfoo -mblah -mfrob
> 
> ought to be equivalent to:
> 
>    gcc -S foo.c -mfoo -mblah -mfrob
>    as foo.s
> 
> Although it doesn't seem that important to me, I've no objection if
> there's a concerted attempt to move in that direction.  The approach
> taken in the patch is different though.  When the source sets an IEEE
> NaN FP attribute, the patch also requires -mnan2008 to be passed on
> the command line and reports an error if the user forgets.
> 
> If we require -mnan2008 to be passed anyway, then all the source
> annotation does is provide a bit of extra error checking.  I'm not
> convinced that that check is worth all the extra complexity.  The
> file-level PIC, ABI and architecture header flags are all set from
> similar, unchecked, options, and I'm not aware that passing the wrong
> options is a common source of error.  Either way, the consistency
> check should be contained within the assembler, whereas using
> ".gnu_attribute" for the source annotation requires an underlying
> attribute flag that must at all times mirror the header flag.
> 
> If instead we want to support source annotation without command-line options
> the "as foo.s" stance above), and command-line options without source
> annotation (e.g. for assembler source that doesn't use FP), then how about
> having a command-line option:
> 
>   -mnan=2008|legacy
> 
> and a directive:
> 
>   .nan 2008|legacy
> 
> Both would act in the same way and it would be an error to contradict
> a previous setting.  (I wondered about ".set nan..." instead of ".nan",
> but this doesn't really work like other .set options, and shouldn't for
> example be used in a push/pop sequence.)  Of course, if neither are used,
> we assume legacy.

 I think your proposal makes sense, however I decided there's no absolute 
need to make the command-line option and the directive to behave in this 
unique way.  Here's an implementation where they behave just like about 
any other such pairs we support, that is the directive overrides any such 
command-line options, and the last setting always wins.  This is similar 
to .abicalls -- which however does not have a negated form -- and its 
interaction with -call_shared/-call_nonpic/-non_shared.  Such an 
arrangement still protects code integrity at the link time -- LD will 
terminate if trying to link incompatible object modules.

 I have updated/reduced the test suite accordingly.  I have dropped the 
shared library cases, because of the dynobj handling bug considered in the 
discussion about attribute merging 
(http://sourceware.org/ml/binutils/2012-12/msg00003.html) -- I'll see if I 
can address the bug separately and then adding these test cases back may 
make sense.  I have also updated documentation.

 No regressions across the usual targets.  OK to apply?

2013-07-08  Maciej W. Rozycki  <macro@codesourcery.com>

	include/elf/
	* mips.h (EF_MIPS_NAN2008): New macro.

	bfd/
	* elfxx-mips.c (_bfd_mips_elf_merge_private_bfd_data): Handle
	EF_MIPS_NAN2008.
	(_bfd_mips_elf_print_private_bfd_data): Likewise.

	binutils/
	* readelf.c (get_machine_flags): Handle EF_MIPS_NAN2008.

	gas/
	* config/tc-mips.c (mips_flag_nan2008): New variable.
        (options): Add OPTION_NAN enum value.
        (md_longopts): Handle it.
        (md_parse_option): Likewise.
        (s_nan): New function.
        (mips_elf_final_processing): Handle EF_MIPS_NAN2008.
        (md_show_usage): Add -mnan.

        * doc/as.texinfo (Overview): Add -mnan.
        * doc/c-mips.texi (MIPS Opts): Document -mnan.
	(MIPS nan): New node.  Document .nan directive.
	(MIPS-Dependent): List the new node.

	gas/testsuite/
	* gas/mips/nan-2008-1.d: New test.
	* gas/mips/nan-2008-2.d: New test.
	* gas/mips/nan-2008-3.d: New test.
	* gas/mips/nan-2008-4.d: New test.
	* gas/mips/nan-legacy-1.d: New test.
	* gas/mips/nan-legacy-2.d: New test.
	* gas/mips/nan-legacy-3.d: New test.
	* gas/mips/nan-legacy-4.d: New test.
	* gas/mips/nan-legacy-5.d: New test.
	* gas/mips/nan-error-1.l: New list test.
	* gas/mips/nan-error-2.l: New list test.
	* gas/mips/nan-2008-override.s: New test source.
	* gas/mips/nan-2008.s: New test source.
	* gas/mips/nan-legacy-override.s: New test source.
	* gas/mips/nan-legacy.s: New test source.
	* gas/mips/nan-error-1.s: New test source.
	* gas/mips/nan-error-2.s: New test source.
	* gas/mips/mips.exp: Run the new tests.

	ld/testsuite/
	* ld-mips-elf/nan-2008.d: New test.
	* ld-mips-elf/nan-legacy.d: New test.
	* ld-mips-elf/nan-mixed-1.d: New test.
	* ld-mips-elf/nan-mixed-2.d: New test.
	* ld-mips-elf/nan-2008.s: New test source.
	* ld-mips-elf/nan-legacy.s: New test source.

  Maciej

binutils-mips-nan2008.diff
Index: binutils-fsf-trunk-quilt/bfd/elfxx-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/bfd/elfxx-mips.c	2013-07-08 13:07:31.000000000 +0100
+++ binutils-fsf-trunk-quilt/bfd/elfxx-mips.c	2013-07-08 13:07:34.300922755 +0100
@@ -14730,6 +14730,20 @@ _bfd_mips_elf_merge_private_bfd_data (bf
       old_flags &= ~ EF_MIPS_ARCH_ASE;
     }
 
+  /* Compare NaN encodings.  */
+  if ((new_flags & EF_MIPS_NAN2008) != (old_flags & EF_MIPS_NAN2008))
+    {
+      _bfd_error_handler (_("%B: linking %s module with previous %s modules"),
+			  ibfd,
+			  (new_flags & EF_MIPS_NAN2008
+			   ? "2008 NaN" : "legacy NaN"),
+			  (old_flags & EF_MIPS_NAN2008
+			   ? "2008 NaN" : "legacy NaN"));
+      ok = FALSE;
+      new_flags &= ~EF_MIPS_NAN2008;
+      old_flags &= ~EF_MIPS_NAN2008;
+    }
+
   /* Warn about any other mismatches */
   if (new_flags != old_flags)
     {
@@ -14921,6 +14935,9 @@ _bfd_mips_elf_print_private_bfd_data (bf
   if (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
     fprintf (file, " [micromips]");
 
+  if (elf_elfheader (abfd)->e_flags & EF_MIPS_NAN2008)
+    fprintf (file, " [nan2008]");
+
   if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE)
     fprintf (file, " [32bitmode]");
   else
Index: binutils-fsf-trunk-quilt/binutils/readelf.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/binutils/readelf.c	2013-07-08 13:07:31.000000000 +0100
+++ binutils-fsf-trunk-quilt/binutils/readelf.c	2013-07-08 13:07:34.300922755 +0100
@@ -2568,6 +2568,9 @@ get_machine_flags (unsigned e_flags, uns
 	  if (e_flags & EF_MIPS_32BITMODE)
 	    strcat (buf, ", 32bitmode");
 
+	  if (e_flags & EF_MIPS_NAN2008)
+	    strcat (buf, ", nan2008");
+
 	  switch ((e_flags & EF_MIPS_MACH))
 	    {
 	    case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c	2013-07-08 13:07:31.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c	2013-07-08 16:18:00.819980773 +0100
@@ -272,6 +272,9 @@ static int file_mips_soft_float = 0;
 /* 1 if -msingle-float, 0 if -mdouble-float.  The default is 0.   */
 static int file_mips_single_float = 0;
 
+/* True if -mnan=2008, false if -mnan=legacy.  */
+static bfd_boolean mips_flag_nan2008 = FALSE;
+
 static struct mips_set_options mips_opts =
 {
   /* isa */ ISA_UNKNOWN, /* ase */ 0, /* mips16 */ -1, /* micromips */ -1,
@@ -1321,6 +1324,7 @@ static void s_gpdword (int);
 static void s_ehword (int);
 static void s_cpadd (int);
 static void s_insn (int);
+static void s_nan (int);
 static void md_obj_begin (void);
 static void md_obj_end (void);
 static void s_mips_ent (int);
@@ -1452,6 +1456,7 @@ enum options
     OPTION_PDR,
     OPTION_NO_PDR,
     OPTION_MVXWORKS_PIC,
+    OPTION_NAN,
     OPTION_END_OF_ENUM
   };
 
@@ -1567,6 +1572,7 @@ struct option md_longopts[] =
   {"mpdr", no_argument, NULL, OPTION_PDR},
   {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
   {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
+  {"mnan", required_argument, NULL, OPTION_NAN},
 
   {NULL, no_argument, NULL, 0}
 };
@@ -1691,6 +1697,7 @@ static const pseudo_typeS mips_pseudo_ta
   {"ehword", s_ehword, 0},
   {"cpadd", s_cpadd, 0},
   {"insn", s_insn, 0},
+  {"nan", s_nan, 0},
 
   /* Relatively generic pseudo-ops that happen to be used on MIPS
      chips.  */
@@ -15357,6 +15364,18 @@ md_parse_option (int c, char *arg)
       mips_pic = VXWORKS_PIC;
       break;
 
+    case OPTION_NAN:
+      if (strcmp (arg, "2008") == 0)
+	mips_flag_nan2008 = TRUE;
+      else if (strcmp (arg, "legacy") == 0)
+	mips_flag_nan2008 = FALSE;
+      else
+	{
+	  as_fatal (_("Invalid NaN setting -mnan=%s"), arg);
+	  return 0;
+	}
+      break;
+
     default:
       return 0;
     }
@@ -17247,6 +17266,30 @@ s_insn (int ignore ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 }
 
+/* Handle the .nan pseudo-op.  */
+
+static void
+s_nan (int ignore ATTRIBUTE_UNUSED)
+{
+  static const char str_legacy[] = "legacy";
+  static const char str_2008[] = "2008";
+  size_t i;
+
+  for (i = 0; !is_end_of_line[(unsigned char) input_line_pointer[i]]; i++);
+
+  if (i == sizeof (str_2008) - 1
+      && memcmp (input_line_pointer, str_2008, i) == 0)
+    mips_flag_nan2008 = TRUE;
+  else if (i == sizeof (str_legacy) - 1
+	   && memcmp (input_line_pointer, str_legacy, i) == 0)
+    mips_flag_nan2008 = FALSE;
+  else
+    as_bad (_("Bad .nan directive"));
+
+  input_line_pointer += i;
+  demand_empty_rest_of_line ();
+}
+
 /* Handle a .stab[snd] directive.  Ideally these directives would be
    implemented in a transparent way, so that removing them would not
    have any effect on the generated instructions.  However, s_stab
@@ -18846,6 +18889,9 @@ mips_elf_final_processing (void)
   if (mips_32bitmode)
     elf_elfheader (stdoutput)->e_flags |= EF_MIPS_32BITMODE;
 
+  if (mips_flag_nan2008)
+    elf_elfheader (stdoutput)->e_flags |= EF_MIPS_NAN2008;
+
 #if 0 /* XXX FIXME */
   /* 32 bit code with 64 bit FP registers.  */
   if (!file_mips_fp32 && ABI_NEEDS_32BIT_REGS (mips_abi))
@@ -19683,8 +19729,16 @@ MIPS options:\n\
 -msingle-float		only allow 32-bit floating-point operations\n\
 -mdouble-float		allow 32-bit and 64-bit floating-point operations\n\
 --[no-]construct-floats	[dis]allow floating point values to be constructed\n\
---[no-]relax-branch	[dis]allow out-of-range branches to be relaxed\n"
-		     ));
+--[no-]relax-branch	[dis]allow out-of-range branches to be relaxed\n\
+-mnan=ENCODING		select an IEEE 754 NaN encoding convention, either of:\n"));
+
+  first = 1;
+
+  show (stream, "legacy", &column, &first);
+  show (stream, "2008", &column, &first);
+
+  fputc ('\n', stream);
+
   fprintf (stream, _("\
 -KPIC, -call_shared	generate SVR4 position independent code\n\
 -call_nonpic		generate non-PIC code that can operate with DSOs\n\
Index: binutils-fsf-trunk-quilt/gas/doc/as.texinfo
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/doc/as.texinfo	2013-07-08 13:07:31.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/doc/as.texinfo	2013-07-08 13:07:34.300922755 +0100
@@ -402,6 +402,7 @@ gcc(1), ld(1), and the Info entries for 
    [@b{-mips3}] [@b{-mips4}] [@b{-mips5}] [@b{-mips32}] [@b{-mips32r2}]
    [@b{-mips64}] [@b{-mips64r2}]
    [@b{-construct-floats}] [@b{-no-construct-floats}]
+   [@b{-mnan=@var{encoding}}]
    [@b{-trap}] [@b{-no-break}] [@b{-break}] [@b{-no-trap}]
    [@b{-mips16}] [@b{-no-mips16}]
    [@b{-mmicromips}] [@b{-mno-micromips}]
@@ -1363,6 +1364,10 @@ The @samp{--relax-branch} option enables
 branches.  By default @samp{--no-relax-branch} is selected, causing any
 out-of-range branches to produce an error.
 
+@item -mnan=@var{encoding}
+Select between the IEEE 754-2008 (@option{-mnan=2008}) or the legacy
+(@option{-mnan=legacy}) NaN encoding format.  The latter is the default.
+
 @cindex emulation
 @item --emulation=@var{name}
 This option was formerly used to switch between ELF and ECOFF output
Index: binutils-fsf-trunk-quilt/gas/doc/c-mips.texi
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/doc/c-mips.texi	2013-07-08 13:07:31.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/doc/c-mips.texi	2013-07-08 13:07:34.300922755 +0100
@@ -30,6 +30,7 @@ Assembly Language Programming'' in the s
 * MIPS assembly options:: Directives to control code generation
 * MIPS autoextend::	Directives for extending MIPS 16 bit instructions
 * MIPS insn::		Directive to mark data as an instruction
+* MIPS nan::		Directives to mark IEEE 754 NaN data encoding
 * MIPS Option Stack::	Directives to save and restore options
 * MIPS ASE Instruction Generation Overrides:: Directives to control
   			generation of MIPS ASE instructions
@@ -416,6 +417,48 @@ Also no MIPS16 branches are ever relaxed
 By default @samp{--no-relax-branch} is selected, causing any out-of-range
 branches to produce an error.
 
+@cindex @option{-mnan=@var{encoding}} command line option, MIPS
+@item -mnan=@var{encoding}
+This options controls the encoding of the special not-a-number (NaN)
+IEEE 754 floating-point symbolic data.
+
+By default @option{-mnan=legacy} or the legacy encoding is selected.  In
+this case quiet NaNs (qNaNs) are denoted by the first bit of their
+trailing significand field being 0, whereas signalling NaNs (sNaNs) are
+denoted by the first bit of their trailing significand field being 1.
+
+The @option{-mnan=2008} option selects the IEEE 754-2008 encoding.  In
+this case qNaNs are denoted by the first bit of their trailing significand
+field being 1, whereas sNaNs are denoted by the first bit of their
+trailing significand field being 0.
+
+@sc{gnu} @code{@value{AS}} does not produce NaNs itself and therefore this
+option does not affect code generated.  Instead it is used, in combination
+with the @code{.nan} directive (@pxref{MIPS nan}), to control link-time
+compatibility of ELF object files, by setting the @code{NAN2008} ELF file
+header flag as appropriate.
+
+In the absence of a @code{.nan} directive to set the @code{NAN2008} ELF
+file header flag in a file being assembled the option is processed as
+follows:
+
+@itemize @bullet
+@item
+for maximum backwards compatibility, by default or in the presence of
+the @option{-mnan=legacy} option the @code{NAN2008} ELF file header flag
+is cleared, marking the object file compatible with objects that use the
+legacy NaN encoding,
+@item
+in the presence of the @option{-mnan=2008} option the @code{NAN2008} ELF
+file header flag is set, marking the object file compatible with objects
+that use the IEEE 754-2008 NaN encoding.
+@end itemize
+
+In the presence of a @code{.nan} directive to set the @code{NAN2008} ELF
+file header flag a file being assembled, the effective (last) value
+requested with the directive overrides any setting requested with the
+@option{-mnan=@var{encoding}} option.
+
 @item --trap
 @itemx --no-break
 @c FIXME!  (1) reflect these options (next item too) in option summaries;
@@ -722,6 +765,41 @@ to be a code section, then the symbol wi
 
 @end example
 
+@node MIPS nan
+@section Directives to mark IEEE 754 NaN data encoding
+
+@cindex MIPS IEEE 754 NaN data encoding selection
+@kindex @code{.nan legacy}
+@kindex @code{.nan 2008}
+These directives control the encoding of the special not-a-number (NaN)
+IEEE 754 floating-point symbolic data.
+
+@sc{gnu} @code{@value{AS}} does not produce NaNs itself and therefore
+these directives do not affect code generated.  Instead they are used to
+control link-time compatibility of ELF object files, by setting the
+@code{NAN2008} ELF file header flag as appropriate.
+
+By default or when @code{.nan legacy} is used the legacy encoding is
+selected.  In this case quiet NaNs (qNaNs) are denoted by the first bit of
+their trailing significand field being 0, whereas signalling NaNs (sNaNs)
+are denoted by the first bit of their trailing significand field being 1.
+This setting is recorded in the output file by the @code{NAN2008} ELF file
+header flag being cleared, marking the object file compatible with objects
+that use the legacy NaN encoding.
+
+The @code{.nan 2008} directive selects the IEEE 754-2008 encoding.  In
+this case qNaNs are denoted by the first bit of their trailing significand
+field being 1, whereas sNaNs are denoted by the first bit of their
+trailing significand field being 0.  This setting is recorded in the
+output file by the @code{NAN2008} ELF file header flag being set, marking
+the object file compatible with objects that use the IEEE 754-2008 NaN
+encoding.
+
+In the presence of multiple @code{.nan} directives within a source file
+the last setting is used.
+
+Traditional MIPS assemblers do not support these directives.
+
 @node MIPS Option Stack
 @section Directives to save and restore options
 
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp	2013-07-08 13:07:27.000000000 +0100
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp	2013-07-08 13:07:49.300970690 +0100
@@ -914,6 +914,20 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test_arches "loc-swap-2"	[mips_arch_list_all]
     run_dump_test_arches "loc-swap-3"	[mips_arch_list_all]
 
+    run_dump_test "nan-legacy-1"
+    run_dump_test "nan-legacy-2"
+    run_dump_test "nan-legacy-3"
+    run_dump_test "nan-legacy-4"
+    run_dump_test "nan-legacy-5"
+
+    run_dump_test "nan-2008-1"
+    run_dump_test "nan-2008-2"
+    run_dump_test "nan-2008-3"
+    run_dump_test "nan-2008-4"
+
+    run_list_test "nan-error-1"
+    run_list_test "nan-error-2" "-mnan=foo"
+
     if $has_newabi {
 	run_dump_test "n32-consec"
     }
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-1.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-1.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,6 @@
+#name: MIPS 2008 NaN setting 1
+#source: nan-2008.s
+#objdump: -p
+
+.*:.*file format.*mips.*
+private flags = [0-9a-f]*[4-7c-f]..: .*[[,]nan2008[],].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-2.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,7 @@
+#name: MIPS 2008 NaN setting 2
+#source: nan-2008.s
+#objdump: -p
+#as: -mnan=legacy
+
+.*:.*file format.*mips.*
+private flags = [0-9a-f]*[4-7c-f]..: .*[[,]nan2008[],].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-3.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-3.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,6 @@
+#name: MIPS 2008 NaN setting 3
+#source: nan-2008-override.s
+#objdump: -p
+
+.*:.*file format.*mips.*
+private flags = [0-9a-f]*[4-7c-f]..: .*[[,]nan2008[],].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-4.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-4.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,7 @@
+#name: MIPS 2008 NaN setting 4
+#source: empty.s
+#objdump: -p
+#as: -mnan=2008
+
+.*:.*file format.*mips.*
+private flags = [0-9a-f]*[4-7c-f]..: .*[[,]nan2008[],].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-override.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008-override.s	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,2 @@
+	.nan	legacy
+	.nan	2008
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-2008.s	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1 @@
+	.nan	2008
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-1.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-1.l	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,2 @@
+.*\.s: Assembler messages:
+.*\.s:1: Error: Bad .nan directive
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-1.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-1.s	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1 @@
+	.nan	foo
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-2.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-2.l	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,2 @@
+Assembler messages:
+Fatal error: Invalid NaN setting -mnan=foo
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-2.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-error-2.s	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1 @@
+# No contents necessary.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-1.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-1.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,7 @@
+#name: MIPS legacy NaN setting 1
+#source: nan-legacy.s
+#objdump: -p
+
+.*:.*file format.*mips.*
+#failif
+private flags = [0-9a-f]*[4-7c-f]..: .*[[]nan2008[]].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-2.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,8 @@
+#name: MIPS legacy NaN setting 2
+#source: nan-legacy.s
+#objdump: -p
+#as: -mnan=2008
+
+.*:.*file format.*mips.*
+#failif
+private flags = [0-9a-f]*[4-7c-f]..: .*[[]nan2008[]].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-3.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-3.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,7 @@
+#name: MIPS legacy NaN setting 3
+#source: nan-legacy-override.s
+#objdump: -p
+
+.*:.*file format.*mips.*
+#failif
+private flags = [0-9a-f]*[4-7c-f]..: .*[[]nan2008[]].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-4.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-4.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,8 @@
+#name: MIPS legacy NaN setting 4
+#source: empty.s
+#objdump: -p
+#as: -mnan=legacy
+
+.*:.*file format.*mips.*
+#failif
+private flags = [0-9a-f]*[4-7c-f]..: .*[[]nan2008[]].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-5.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-5.d	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,7 @@
+#name: MIPS legacy NaN setting 5
+#source: empty.s
+#objdump: -p
+
+.*:.*file format.*mips.*
+#failif
+private flags = [0-9a-f]*[4-7c-f]..: .*[[]nan2008[]].*
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-override.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy-override.s	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1,2 @@
+	.nan	2008
+	.nan	legacy
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/nan-legacy.s	2013-07-08 13:07:49.300970690 +0100
@@ -0,0 +1 @@
+	.nan	legacy
Index: binutils-fsf-trunk-quilt/include/elf/mips.h
===================================================================
--- binutils-fsf-trunk-quilt.orig/include/elf/mips.h	2013-07-08 13:07:31.000000000 +0100
+++ binutils-fsf-trunk-quilt/include/elf/mips.h	2013-07-08 13:07:34.300922755 +0100
@@ -191,6 +191,9 @@ END_RELOC_NUMBERS (R_MIPS_maxext)
    (regs are 32-bits wide).  */
 #define EF_MIPS_32BITMODE	0x00000100
 
+/* Code in file uses the IEEE 754-2008 NaN encoding convention.  */
+#define EF_MIPS_NAN2008		0x00000400
+
 /* Architectural Extensions used by this file */
 #define EF_MIPS_ARCH_ASE	0x0f000000
 
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/ld/testsuite/ld-mips-elf/mips-elf.exp	2013-07-08 13:07:27.000000000 +0100
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/mips-elf.exp	2013-07-08 13:07:49.300970690 +0100
@@ -666,6 +666,11 @@ run_dump_test "attr-gnu-4-44"
 run_dump_test "attr-gnu-4-45"
 run_dump_test "attr-gnu-4-51"
 
+run_dump_test "nan-legacy"
+run_dump_test "nan-2008"
+run_dump_test "nan-mixed-1"
+run_dump_test "nan-mixed-2"
+
 if { $linux_gnu } {
     run_ld_link_tests {
 	{"GOT and versioning 1"
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-2008.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-2008.d	2013-07-08 13:07:49.800921964 +0100
@@ -0,0 +1,7 @@
+#source: nan-2008.s
+#source: nan-2008.s
+#ld: -r
+#objdump: -p
+
+.*:.*file format.*mips.*
+private flags = [0-9a-f]*[4-7c-f]..: .*[[,]nan2008[],].*
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-2008.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-2008.s	2013-07-08 13:07:49.800921964 +0100
@@ -0,0 +1,6 @@
+	.nan	2008
+
+# We need some section contents for the ELF header flag compatibility check
+# to trigger.
+	.data
+	.byte	0
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-legacy.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-legacy.d	2013-07-08 13:07:49.800921964 +0100
@@ -0,0 +1,8 @@
+#source: nan-legacy.s
+#source: nan-legacy.s
+#ld: -r
+#objdump: -p
+
+.*:.*file format.*mips.*
+#failif
+private flags = [0-9a-f]*[4-7c-f]..: .*[[]nan2008[]].*
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-legacy.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-legacy.s	2013-07-08 13:07:49.800921964 +0100
@@ -0,0 +1,6 @@
+	.nan	legacy
+
+# We need some section contents for the ELF header flag compatibility check
+# to trigger.
+	.data
+	.byte	0
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-mixed-1.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-mixed-1.d	2013-07-08 13:07:49.800921964 +0100
@@ -0,0 +1,5 @@
+#source: nan-legacy.s
+#source: nan-2008.s
+#ld: -r
+#error: \A[^\n]*: [^\n]* linking 2008 NaN module with previous legacy NaN modules\n
+#error:   [^\n]*: failed to merge target specific data of file [^\n]*\.o\Z
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-mixed-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-mips-elf/nan-mixed-2.d	2013-07-08 13:07:49.800921964 +0100
@@ -0,0 +1,5 @@
+#source: nan-2008.s
+#source: nan-legacy.s
+#ld: -r
+#error: \A[^\n]*: [^\n]* linking legacy NaN module with previous 2008 NaN modules\n
+#error:   [^\n]*: failed to merge target specific data of file [^\n]*\.o\Z



More information about the Binutils mailing list