public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix printing of floating point numbers in objdump
@ 2012-08-11 15:42 Andreas Schwab
  0 siblings, 0 replies; only message in thread
From: Andreas Schwab @ 2012-08-11 15:42 UTC (permalink / raw)
  To: binutils

floatformat_to_double mishandles floating point numbers between 1 and 2
(ie. with zero unbiased exponent) for floating point formats with more
then 32 mantissa bits: the bits beyond the first 32 are not correctly
shifted.

I have also simplified the handling of denormal numbers.  The special
case can be reduced to setting the exponent to the minimum and assuming
a zero integer bit.

Andreas.

binutils/
	* binutils-all/m68k/objdump.exp: Add flonum test.
	* binutils-all/m68k/flonum.s: New file.

libiberty/
	* floatformat.c (floatformat_to_double): Correctly handle numbers
	between 1 and 2.  Simplify handling of denormal number.

diff --git a/binutils/testsuite/binutils-all/m68k/flonum.s b/binutils/testsuite/binutils-all/m68k/flonum.s
new file mode 100644
index 0000000..22e92bb
--- /dev/null
+++ b/binutils/testsuite/binutils-all/m68k/flonum.s
@@ -0,0 +1,2 @@
+	fmove.d #0r1.1,%fp0
+	fmove.d #0r1e-310,%fp0
diff --git a/binutils/testsuite/binutils-all/m68k/objdump.exp b/binutils/testsuite/binutils-all/m68k/objdump.exp
index 5043ef7..e0b1d29 100644
--- a/binutils/testsuite/binutils-all/m68k/objdump.exp
+++ b/binutils/testsuite/binutils-all/m68k/objdump.exp
@@ -77,3 +77,35 @@ if [regexp $want $got] then {
 } else {
     fail "fnop test"
 }
+
+#############################
+# Set up the test of flonum.s
+#############################
+
+if {![binutils_assemble $srcdir/$subdir/flonum.s tmpdir/flonum.o]} then {
+    return
+}
+
+if [is_remote host] {
+    set objfile [remote_download host tmpdir/flonum.o]
+} else {
+    set objfile tmpdir/flonum.o
+}
+
+# Test printing of floating point numbers
+
+set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble $objfile"]
+
+set want1 "0:\[ \t\]+f23c 5400 3ff1\[ \t\]+fmoved #0e1\\.1,%fp0"
+set want2 "c:\[ \t\]+f23c 5400 0000\[ \t\]+fmoved #0e1e-310,%fp0"
+
+if [regexp $want1 $got] then {
+    pass "flonum test 1"
+} else {
+    fail "flonum test 1"
+}
+if [regexp $want2 $got] then {
+    pass "flonum test 2"
+} else {
+    fail "flonum test 2"
+}
diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c
index 1116c63..4e762d0 100644
--- a/libiberty/floatformat.c
+++ b/libiberty/floatformat.c
@@ -1,5 +1,5 @@
 /* IEEE floating point support routines, for GDB, the GNU Debugger.
-   Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006, 2010
+   Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006, 2010, 2012
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -503,20 +503,20 @@ floatformat_to_double (const struct floatformat *fmt,
   mant_off = fmt->man_start;
   dto = 0.0;
 
-  special_exponent = exponent == 0 || (unsigned long) exponent == fmt->exp_nan;
-
-  /* Don't bias zero's, denorms or NaNs.  */
-  if (!special_exponent)
-    exponent -= fmt->exp_bias;
-
   /* Build the result algebraically.  Might go infinite, underflow, etc;
      who cares. */
 
-  /* If this format uses a hidden bit, explicitly add it in now.  Otherwise,
-     increment the exponent by one to account for the integer bit.  */
-
-  if (!special_exponent)
+  /* For denorms use minimum exponent.  */
+  if (exponent == 0)
+    exponent = 1 - fmt->exp_bias;
+  else
     {
+      exponent -= fmt->exp_bias;
+
+      /* If this format uses a hidden bit, explicitly add it in now.
+	 Otherwise, increment the exponent by one to account for the
+	 integer bit.  */
+
       if (fmt->intbit == floatformat_intbit_no)
 	dto = ldexp (1.0, exponent);
       else
@@ -530,18 +530,8 @@ floatformat_to_double (const struct floatformat *fmt,
       mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
 			 mant_off, mant_bits);
 
-      /* Handle denormalized numbers.  FIXME: What should we do for
-	 non-IEEE formats?  */
-      if (special_exponent && exponent == 0 && mant != 0)
-	dto += ldexp ((double)mant,
-		      (- fmt->exp_bias
-		       - mant_bits
-		       - (mant_off - fmt->man_start)
-		       + 1));
-      else
-	dto += ldexp ((double)mant, exponent - mant_bits);
-      if (exponent != 0)
-	exponent -= mant_bits;
+      dto += ldexp ((double) mant, exponent - mant_bits);
+      exponent -= mant_bits;
       mant_off += mant_bits;
       mant_bits_left -= mant_bits;
     }
-- 
1.7.11.4

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-08-11 14:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-11 15:42 [PATCH] Fix printing of floating point numbers in objdump Andreas Schwab

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