This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] real.c cleanup


This removes unnecessary or unreachable special cases for DEC and IBM
arithmetic as well as support for ARM_EXTENDED_IEEE_FORMAT which doesn't
appear to be used. It also aborts the compilation if wrong endianness is
used for DEC and IBM (at the moment, it would just silently generate
incorrect code). It also fixes some comments and formatting.

Bootstrapped and regtested on sparc-sun-solaris2.8. Unfortunately I can't
test it on an IBM or a VAX - there seem to be no simulators for them. Does
anyone have access to these machines?

BTW, I've noticed that the emulator sets errno in some places. Is it
supposed to do that?

Bye

Roman

2002-05-24  Roman Lechtchinsky  <rl@cs.tu-berlin.de>

	* real.c (REAL_WORDS_BIG_ENDIAN): Make sure it is 0 for DEC and 1 for
	IBM.
	(e53toe, toe53): Assume IEEE if none of DEC, IBM and C4X is defined.
	(e64toe, toe64): Remove special cases for DEC and IBM. Remove support
	for ARM_EXTENDED_IEEE_FORMAT.
	(e24toe, toe24): Remove special cases for DEC.
	(significand_size): Simplify. Indent.

Index: real.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/real.c,v
retrieving revision 1.71
diff -c -3 -p -r1.71 real.c
*** real.c	12 May 2002 17:09:23 -0000	1.71
--- real.c	25 May 2002 10:09:26 -0000
*************** unknown arithmetic type
*** 128,133 ****
--- 128,142 ----
  
  #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
  
+ /* Make sure that the endianness is correct for IBM and DEC. */
+ #if defined(DEC) && REAL_WORDS_BIG_ENDIAN
+   #error "Big-endian representations are not supported for DEC."
+ #else
+ #if defined(IBM) && !REAL_WORDS_BIG_ENDIAN
+   #error "Little-endian representations are not supported for IBM."
+ #endif
+ #endif
+ 
  /* Define INFINITY for support of infinity.
     Define NANS for support of Not-a-Number's (NaN's).  */
  #if !defined(DEC) && !defined(IBM) && !defined(C4X)
*************** e53toe (pe, y)
*** 3130,3136 ****
    r += EXONE - 01777;
    yy[E] = r;
    p = &yy[M + 1];
! #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      {
        *p++ = *(--e);
--- 3139,3145 ----
    r += EXONE - 01777;
    yy[E] = r;
    p = &yy[M + 1];
! 
    if (! REAL_WORDS_BIG_ENDIAN)
      {
        *p++ = *(--e);
*************** e53toe (pe, y)
*** 3144,3150 ****
        *p++ = *e++;
        *p++ = *e++;
      }
! #endif
    eshift (yy, -5);
    if (denorm)
      {
--- 3153,3159 ----
        *p++ = *e++;
        *p++ = *e++;
      }
! 
    eshift (yy, -5);
    if (denorm)
      {
*************** e64toe (pe, y)
*** 3176,3199 ****
    p = yy;
    for (i = 0; i < NE - 5; i++)
      *p++ = 0;
! /* This precision is not ordinarily supported on DEC or IBM.  */
! #ifdef DEC
!   for (i = 0; i < 5; i++)
!     *p++ = *e++;
! #endif
! #ifdef IBM
!   p = &yy[0] + (NE - 1);
!   *p-- = *e++;
!   ++e;
!   for (i = 0; i < 5; i++)
!     *p-- = *e++;
! #endif
! #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      {
        for (i = 0; i < 5; i++)
  	*p++ = *e++;
  
        /* For denormal long double Intel format, shift significand up one
  	 -- but only if the top significand bit is zero.  A top bit of 1
  	 is "pseudodenormal" when the exponent is zero.  */
--- 3185,3199 ----
    p = yy;
    for (i = 0; i < NE - 5; i++)
      *p++ = 0;
! #ifndef C4X
!   /* REAL_WORDS_BIG_ENDIAN is always 0 for DEC and 1 for IBM.
!      This precision is not ordinarily supported on DEC or IBM.  */
    if (! REAL_WORDS_BIG_ENDIAN)
      {
        for (i = 0; i < 5; i++)
  	*p++ = *e++;
  
+ #ifdef IEEE
        /* For denormal long double Intel format, shift significand up one
  	 -- but only if the top significand bit is zero.  A top bit of 1
  	 is "pseudodenormal" when the exponent is zero.  */
*************** e64toe (pe, y)
*** 3206,3227 ****
  	  emovo (temp,y);
  	  return;
  	}
      }
    else
      {
        p = &yy[0] + (NE - 1);
- #ifdef ARM_EXTENDED_IEEE_FORMAT
-       /* For ARMs, the exponent is in the lowest 15 bits of the word.  */
-       *p-- = (e[0] & 0x8000) | (e[1] & 0x7ffff);
-       e += 2;
- #else
        *p-- = *e++;
        ++e;
- #endif
        for (i = 0; i < 4; i++)
  	*p-- = *e++;
      }
! #endif
  #ifdef INFINITY
    /* Point to the exponent field and check max exponent cases.  */
    p = &yy[NE - 1];
--- 3206,3222 ----
  	  emovo (temp,y);
  	  return;
  	}
+ #endif /* IEEE */
      }
    else
      {
        p = &yy[0] + (NE - 1);
        *p-- = *e++;
        ++e;
        for (i = 0; i < 4; i++)
  	*p-- = *e++;
      }
! #endif  /* not C4X */
  #ifdef INFINITY
    /* Point to the exponent field and check max exponent cases.  */
    p = &yy[NE - 1];
*************** e64toe (pe, y)
*** 3243,3258 ****
  	}
        else
  	{
- #ifdef ARM_EXTENDED_IEEE_FORMAT
- 	  for (i = 2; i <= 5; i++)
- 	    {
- 	      if (pe[i] != 0)
- 		{
- 		  enan (y, (*p & 0x8000) != 0);
- 		  return;
- 		}
- 	    }
- #else /* not ARM */
  	  /* In Motorola extended precision format, the most significant
  	     bit of an infinity mantissa could be either 1 or 0.  It is
  	     the lower order bits that tell whether the value is a NaN.  */
--- 3238,3243 ----
*************** bigend_nan:
*** 3268,3274 ****
  		  return;
  		}
  	    }
- #endif /* not ARM */
  	}
  #endif /* NANS */
        eclear (y);
--- 3253,3258 ----
*************** e113toe (pe, y)
*** 3371,3377 ****
      }
    emovo (yy, y);
  }
! #endif
  
  /* Convert single precision float PE to e type Y.  */
  
--- 3355,3361 ----
      }
    emovo (yy, y);
  }
! #endif  /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
  
  /* Convert single precision float PE to e type Y.  */
  
*************** e24toe (pe, y)
*** 3401,3413 ****
    e = pe;
    denorm = 0;			/* flag if denormalized number */
    ecleaz (yy);
! #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      e += 1;
- #endif
- #ifdef DEC
-   e += 1;
- #endif
    r = *e;
    yy[0] = 0;
    if (r & 0x8000)
--- 3385,3394 ----
    e = pe;
    denorm = 0;			/* flag if denormalized number */
    ecleaz (yy);
! 
!   /* REAL_WORDS_BIG_ENDIAN is always 0 for DEC.  */
    if (! REAL_WORDS_BIG_ENDIAN)
      e += 1;
    r = *e;
    yy[0] = 0;
    if (r & 0x8000)
*************** e24toe (pe, y)
*** 3453,3462 ****
    r += EXONE - 0177;
    yy[E] = r;
    p = &yy[M + 1];
! #ifdef DEC
!   *p++ = *(--e);
! #endif
! #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      *p++ = *(--e);
    else
--- 3434,3441 ----
    r += EXONE - 0177;
    yy[E] = r;
    p = &yy[M + 1];
! 
!   /* REAL_WORDS_BIG_ENDIAN is always 0 for DEC.  */
    if (! REAL_WORDS_BIG_ENDIAN)
      *p++ = *(--e);
    else
*************** e24toe (pe, y)
*** 3464,3470 ****
        ++e;
        *p++ = *e++;
      }
! #endif
    eshift (yy, -8);
    if (denorm)
      {				/* if zero exponent, then normalize the significand */
--- 3443,3449 ----
        ++e;
        *p++ = *e++;
      }
! 
    eshift (yy, -8);
    if (denorm)
      {				/* if zero exponent, then normalize the significand */
*************** toe113 (a, b)
*** 3572,3578 ****
  	*q-- = *p++;
      }
  }
! #endif
  
  /* Convert e-type X to IEEE double extended format E.  */
  
--- 3551,3557 ----
  	*q-- = *p++;
      }
  }
! #endif  /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
  
  /* Convert e-type X to IEEE double extended format E.  */
  
*************** toe64 (a, b)
*** 3631,3685 ****
    if ((a[E] == 0) && ! REAL_WORDS_BIG_ENDIAN)
      eshdn1 (a);
    p = a;
! #ifdef IBM
!   q = b;
! #endif
! #ifdef DEC
!   q = b + 4;
! #endif
! #ifdef IEEE
    if (REAL_WORDS_BIG_ENDIAN)
      q = b;
    else
      {
        q = b + 4;			/* point to output exponent */
        /* Clear the last two bytes of 12-byte Intel format.  q is pointing
  	 into an array of size 6 (e.g. x[NE]), so the last two bytes are
  	 always there, and there are never more bytes, even when we are using
  	 INTEL_EXTENDED_IEEE_FORMAT.  */
        *(q+1) = 0;
-     }
  #endif
  
    /* combine sign and exponent */
    i = *p++;
! #ifdef IBM
!   if (i)
!     *q++ = *p++ | 0x8000;
!   else
!     *q++ = *p++;
!   *q++ = 0;
! #endif
! #ifdef DEC
!   if (i)
!     *q-- = *p++ | 0x8000;
!   else
!     *q-- = *p++;
! #endif
! #ifdef IEEE
    if (REAL_WORDS_BIG_ENDIAN)
      {
- #ifdef ARM_EXTENDED_IEEE_FORMAT
-       /* The exponent is in the lowest 15 bits of the first word.  */
-       *q++ = i ? 0x8000 : 0;
-       *q++ = *p++;
- #else
        if (i)
  	*q++ = *p++ | 0x8000;
        else
  	*q++ = *p++;
        *q++ = 0;
- #endif
      }
    else
      {
--- 3610,3643 ----
    if ((a[E] == 0) && ! REAL_WORDS_BIG_ENDIAN)
      eshdn1 (a);
    p = a;
! #ifndef C4X
!   /* REAL_WORDS_BIG_ENDIAN is always 0 for DEC and 1 for IBM.  */
    if (REAL_WORDS_BIG_ENDIAN)
      q = b;
    else
      {
        q = b + 4;			/* point to output exponent */
+ #ifdef IEEE
        /* Clear the last two bytes of 12-byte Intel format.  q is pointing
  	 into an array of size 6 (e.g. x[NE]), so the last two bytes are
  	 always there, and there are never more bytes, even when we are using
  	 INTEL_EXTENDED_IEEE_FORMAT.  */
        *(q+1) = 0;
  #endif
+     }
+ #endif /* not C4X */
  
    /* combine sign and exponent */
    i = *p++;
! 
! #ifndef C4X
    if (REAL_WORDS_BIG_ENDIAN)
      {
        if (i)
  	*q++ = *p++ | 0x8000;
        else
  	*q++ = *p++;
        *q++ = 0;
      }
    else
      {
*************** toe64 (a, b)
*** 3688,3706 ****
        else
  	*q-- = *p++;
      }
! #endif
    /* skip over guard word */
    ++p;
    /* move the significand */
! #ifdef IBM
!   for (i = 0; i < 4; i++)
!     *q++ = *p++;
! #endif
! #ifdef DEC
!   for (i = 0; i < 4; i++)
!     *q-- = *p++;
! #endif
! #ifdef IEEE
    if (REAL_WORDS_BIG_ENDIAN)
      {
        for (i = 0; i < 4; i++)
--- 3646,3657 ----
        else
  	*q-- = *p++;
      }
! #endif /* not C4X */
! 
    /* skip over guard word */
    ++p;
    /* move the significand */
! #ifndef C4X
    if (REAL_WORDS_BIG_ENDIAN)
      {
        for (i = 0; i < 4; i++)
*************** toe64 (a, b)
*** 3722,3728 ****
        for (i = 0; i < 4; i++)
  	*q-- = *p++;
      }
! #endif
  }
  
  /* e type to double precision.  */
--- 3673,3679 ----
        for (i = 0; i < 4; i++)
  	*q-- = *p++;
      }
! #endif /* not C4X */
  }
  
  /* e type to double precision.  */
*************** etoe53 (x, e)
*** 3735,3741 ****
       const UEMUSHORT *x;
       UEMUSHORT *e;
  {
!   etodec (x, e);		/* see etodec.c */
  }
  
  /* Convert exploded e-type X, that has already been rounded to
--- 3686,3692 ----
       const UEMUSHORT *x;
       UEMUSHORT *e;
  {
!   etodec (x, e);
  }
  
  /* Convert exploded e-type X, that has already been rounded to
*************** toe53 (x, y)
*** 3853,3862 ****
        return;
      }
    p = &x[0];
- #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      y += 3;
- #endif
    *y = 0;			/* output high order */
    if (*p++)
      *y = 0x8000;		/* output sign bit */
--- 3804,3811 ----
*************** toe24 (x, y)
*** 3953,3959 ****
    toibm (x, y, SFmode);
  }
  
! #else
  
  #ifdef C4X
  /* Convert e-type X to C4X float E.  */
--- 3902,3908 ----
    toibm (x, y, SFmode);
  }
  
! #else /* it's not IBM */
  
  #ifdef C4X
  /* Convert e-type X to C4X float E.  */
*************** toe24 (x, y)
*** 3976,3982 ****
    toc4x (x, y, QFmode);
  }
  
! #else
  
  /* Convert e-type X to IEEE float E.  DEC float is the same as IEEE float.  */
  
--- 3925,3931 ----
    toc4x (x, y, QFmode);
  }
  
! #else /* it's neither IBM nor C4X */
  
  /* Convert e-type X to IEEE float E.  DEC float is the same as IEEE float.  */
  
*************** toe24 (x, y)
*** 4037,4049 ****
        return;
      }
    p = &x[0];
! #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      y += 1;
- #endif
- #ifdef DEC
-   y += 1;
- #endif
    *y = 0;			/* output high order */
    if (*p++)
      *y = 0x8000;		/* output sign bit */
--- 3986,3994 ----
        return;
      }
    p = &x[0];
!   /* REAL_WORDS_BIG_ENDIAN is alwys 0 for DEC.  */
    if (! REAL_WORDS_BIG_ENDIAN)
      y += 1;
    *y = 0;			/* output high order */
    if (*p++)
      *y = 0x8000;		/* output sign bit */
*************** toe24 (x, y)
*** 4054,4063 ****
      {
  #ifdef INFINITY
        *y |= (UEMUSHORT) 0x7f80;
- #ifdef DEC
-       *(--y) = 0;
- #endif
- #ifdef IEEE
        if (! REAL_WORDS_BIG_ENDIAN)
  	*(--y) = 0;
        else
--- 3999,4004 ----
*************** toe24 (x, y)
*** 4065,4077 ****
  	  ++y;
  	  *y = 0;
  	}
- #endif
  #else  /* no INFINITY */
        *y |= (UEMUSHORT) 0x7f7f;
- #ifdef DEC
-       *(--y) = 0xffff;
- #endif
- #ifdef IEEE
        if (! REAL_WORDS_BIG_ENDIAN)
  	*(--y) = 0xffff;
        else
--- 4006,4013 ----
*************** toe24 (x, y)
*** 4079,4085 ****
  	  ++y;
  	  *y = 0xffff;
  	}
- #endif
  #ifdef ERANGE
        errno = ERANGE;
  #endif
--- 4015,4020 ----
*************** toe24 (x, y)
*** 4098,4107 ****
    i |= *p++ & (UEMUSHORT) 0x7f;	/* *p = xi[M] */
    /* High order output already has sign bit set.  */
    *y |= i;
- #ifdef DEC
-   *(--y) = *p;
- #endif
- #ifdef IEEE
    if (! REAL_WORDS_BIG_ENDIAN)
      *(--y) = *p;
    else
--- 4033,4038 ----
*************** toe24 (x, y)
*** 4109,4115 ****
        ++y;
        *y = *p;
      }
- #endif
  }
  #endif  /* not C4X */
  #endif  /* not IBM */
--- 4040,4045 ----
*************** read_expnt:
*** 5454,5460 ****
      {
  #ifdef DEC
      case 56:
!       todec (yy, y);		/* see etodec.c */
        break;
  #endif
  #ifdef IBM
--- 5384,5390 ----
      {
  #ifdef DEC
      case 56:
!       todec (yy, y);
        break;
  #endif
  #ifdef IBM
*************** significand_size (mode)
*** 6903,6951 ****
       enum machine_mode mode;
  {
  
! /* Don't test the modes, but their sizes, lest this
!    code won't work for BITS_PER_UNIT != 8 .  */
  
! switch (GET_MODE_BITSIZE (mode))
!   {
!   case 32:
  
! #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
!     return 56;
  #endif
  
!     return 24;
! 
!   case 64:
! #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
!     return 53;
! #else
! #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
!     return 56;
! #else
! #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
!     return 56;
! #else
! #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
!     return 56;
  #else
!     abort ();
! #endif
! #endif
! #endif
  #endif
  
!   case 96:
!     return 64;
  
!   case 128:
  #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
!     return 113;
  #else
!     return 64;
  #endif
  
!   default:
!     abort ();
!   }
  }
--- 6833,6869 ----
       enum machine_mode mode;
  {
  
!   /* Don't test the modes, but their sizes, lest this
!      code won't work for BITS_PER_UNIT != 8 .  */
  
!   switch (GET_MODE_BITSIZE (mode))
!     {
!      case 32:
  
! #ifdef C4X
!        return 56;
! #else
!        return 24;
  #endif
  
!      case 64:
! #ifdef IEEE
!        return 53;
  #else
!        return 56;
  #endif
  
!      case 96:
!        return 64;
  
!      case 128:
  #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
!        return 113;
  #else
!        return 64;
  #endif
  
!      default:
!        abort ();
!     }
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]