public inbox for gas2@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <alan@spri.levels.unisa.edu.au>
To: hjl@lucon.org (H.J. Lu)
Cc: mikeg@weiden.de, gas2@cygnus.com, egcs@cygnus.com, gcc2@cygnus.com
Subject: Re: gcc generates invalid i386 fmulp
Date: Wed, 15 Apr 1998 07:18:00 -0000	[thread overview]
Message-ID: <199804151416.XAA08842@mullet.Levels.UniSA.Edu.Au> (raw)
In-Reply-To: <m0yP7Uc-00058vC@ocean.lucon.org>

I fiddled around with the glibc source that generated the invalid
`fmulp %st(1),%st', and came up with the following test case.  It's
not all that small, but reducing the complexity seems to make the
problem go away.

------------------ fop_pop_bug.c ------------------
/*
 * inspired by glibc-2.0.6/sysdeps/libm-ieee754/s_nextafterf.c
 *
 * gcc -O2 -S -DOP=+ gives faddp %st(1),%st
 * gcc -O2 -S -DOP=* gives fmulp %st(1),%st
 * gcc -O2 -S -DOP=- gives fsubrp %st(1),%st
 * gcc -O2 -S -DOP=/ gives fdivrp %st(1),%st
 */

#ifndef OP
#define OP *
#endif

typedef int int32_t __attribute__ ((__mode__ (  __SI__ ))) ;
typedef unsigned int u_int32_t __attribute__ ((__mode__ (  __SI__ ))) ;

typedef union
{
  float value;
  u_int32_t word;
} ieee_float_shape_type;

float __nextafterf(float x, float y)
{
 int32_t hx,hy,ix,iy;

 {
  ieee_float_shape_type gf_u;
  gf_u.value = x;
  hx = gf_u.word;
 }
 {
  ieee_float_shape_type gf_u;
  gf_u.value = y;
  hy = gf_u.word;
 }
 ix = hx&0x7fffffff;
 iy = hy&0x7fffffff;

 if ( ix > 0x7f800000 || iy > 0x7f800000 )
    return x+y;
 if (x == y) return x;
 if (ix == 0)
   {
    {
     ieee_float_shape_type sf_u;
     sf_u.word = (hy&0x80000000) | 1;
     x = sf_u.value;
    }
    y = x*x;
    if (y == x) return y; else return x;
   }
 if (hx >= 0)
   {
    if (hx > hy)
       hx -= 1;
    else
       hx += 1;
   }
 else
   {
    if (hy >= 0 || hx > hy)
       hx -= 1;
    else
       hx += 1;
   }
 hy = hx & 0x7f800000;
 if (hy >= 0x7f800000)
    return x+x;
 if (hy < 0x00800000)
   {
    y = x OP x;
    if (y != x)
      {
       ieee_float_shape_type sf_u;
       sf_u.word = hx;
       y = sf_u.value;
       return y;
      }
   }
 {
  ieee_float_shape_type sf_u;
  sf_u.word = hx;
  x = sf_u.value;
 }
 return x;
}

  parent reply	other threads:[~1998-04-15  7:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-14  0:15 Alan Modra
1998-04-14  8:19 ` H.J. Lu
1998-04-14 16:45   ` Alan Modra
1998-04-14 20:18     ` Michael L. Galbraith
1998-04-14 20:30       ` H.J. Lu
1998-04-14 21:35         ` Michael L. Galbraith
1998-04-14 20:44       ` H.J. Lu
1998-04-15  7:18   ` Alan Modra [this message]
1998-04-15  9:01     ` Robert Lipe
1998-04-15 10:05       ` Ulrich Drepper

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=199804151416.XAA08842@mullet.Levels.UniSA.Edu.Au \
    --to=alan@spri.levels.unisa.edu.au \
    --cc=egcs@cygnus.com \
    --cc=gas2@cygnus.com \
    --cc=gcc2@cygnus.com \
    --cc=hjl@lucon.org \
    --cc=mikeg@weiden.de \
    /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).