public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au>
To: gcc@gcc.gnu.org
Subject: libgcc2 __fixsfdi
Date: Fri, 04 Oct 2002 08:11:00 -0000	[thread overview]
Message-ID: <20021005002244.H25369@bubble.sa.bigpond.net.au> (raw)

gcc's __fixsfdi function returns extremely surprising results for
floats that overflow the range of DWtype.  The integer value
wraps rather than limiting to min/max values.  I know that return
values for the overflow case are unspecified, even in current
draft ieee-754, but "each of the operations shall be performed as if
it first produced an intermediate result correct to infinite precision
and with unbounded range, and then coerced this intermediate result to
fit in the destination's format" could be taken as support for this
patch.  After all, the nearest values that the intermediate result can
be coerced to in case of overflow, are the min and max integers.  Also
see http://754r.ucbtest.org/proposals/integer/integer.html where this
behaviour is specified.

If the following is reasonable, I'll do the same for __fixtfdi,
__fixxfdi and __fixdfdi, and submit a proper patch with changelog.

Index: gcc/libgcc2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/libgcc2.c,v
retrieving revision 1.149
diff -u -p -r1.149 libgcc2.c
--- gcc/libgcc2.c	8 Sep 2002 12:47:26 -0000	1.149
+++ gcc/libgcc2.c	4 Oct 2002 14:25:34 -0000
@@ -994,12 +994,27 @@ __fixunssfDI (SFtype original_a)
 #endif
 
 #ifdef L_fixsfdi
+#define DWORD_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
+#define MAXDWtype ((((DWtype) 1) << (DWORD_SIZE-1))-1)
+
 DWtype
 __fixsfdi (SFtype a)
 {
+  DWtype tmp;
+
   if (a < 0)
-    return - __fixunssfDI (-a);
-  return __fixunssfDI (a);
+    {
+      tmp = __fixunssfDI (-a);
+      tmp = -tmp;
+      if (tmp > 0)
+	tmp = -MAXDWtype - 1;
+      return tmp;
+    }
+
+  tmp = __fixunssfDI (a);
+  if (tmp < 0)
+    tmp = MAXDWtype;
+  return tmp;
 }
 #endif
 

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

             reply	other threads:[~2002-10-04 14:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-04  8:11 Alan Modra [this message]
2002-10-04 12:45 ` Richard Henderson
2002-10-08  1:46   ` Alan Modra
2002-10-08 11:48     ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021005002244.H25369@bubble.sa.bigpond.net.au \
    --to=amodra@bigpond.net.au \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).