Commit 7729f1ca by Richard Stallman

(ltoe, ultoe, eifrac, euifrac): Handle 64-bit longs.

(SFMODE_NAN, DFMODE_NAN, XFMODE_NAN, TFMODE_NAN): New macros
permit definitions of NaN patterns to be overridden in tm.h.

From-SVN: r4680
parent ffcf6393
...@@ -3297,10 +3297,18 @@ ltoe (lp, y) ...@@ -3297,10 +3297,18 @@ ltoe (lp, y)
ll = (unsigned long) (*lp); ll = (unsigned long) (*lp);
} }
/* move the long integer to yi significand area */ /* move the long integer to yi significand area */
#if HOST_BITS_PER_LONG == 64
yi[M] = (unsigned EMUSHORT) (ll >> 48);
yi[M + 1] = (unsigned EMUSHORT) (ll >> 32);
yi[M + 2] = (unsigned EMUSHORT) (ll >> 16);
yi[M + 3] = (unsigned EMUSHORT) ll;
yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
#else
yi[M] = (unsigned EMUSHORT) (ll >> 16); yi[M] = (unsigned EMUSHORT) (ll >> 16);
yi[M + 1] = (unsigned EMUSHORT) ll; yi[M + 1] = (unsigned EMUSHORT) ll;
yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */
#endif
if ((k = enormlz (yi)) > NBITS)/* normalize the significand */ if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
ecleaz (yi); /* it was zero */ ecleaz (yi); /* it was zero */
else else
...@@ -3329,10 +3337,18 @@ ultoe (lp, y) ...@@ -3329,10 +3337,18 @@ ultoe (lp, y)
ll = *lp; ll = *lp;
/* move the long integer to ayi significand area */ /* move the long integer to ayi significand area */
#if HOST_BITS_PER_LONG == 64
yi[M] = (unsigned EMUSHORT) (ll >> 48);
yi[M + 1] = (unsigned EMUSHORT) (ll >> 32);
yi[M + 2] = (unsigned EMUSHORT) (ll >> 16);
yi[M + 3] = (unsigned EMUSHORT) ll;
yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
#else
yi[M] = (unsigned EMUSHORT) (ll >> 16); yi[M] = (unsigned EMUSHORT) (ll >> 16);
yi[M + 1] = (unsigned EMUSHORT) ll; yi[M + 1] = (unsigned EMUSHORT) ll;
yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */
#endif
if ((k = enormlz (yi)) > NBITS)/* normalize the significand */ if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
ecleaz (yi); /* it was zero */ ecleaz (yi); /* it was zero */
else else
...@@ -3358,7 +3374,8 @@ eifrac (x, i, frac) ...@@ -3358,7 +3374,8 @@ eifrac (x, i, frac)
unsigned EMUSHORT *frac; unsigned EMUSHORT *frac;
{ {
unsigned EMUSHORT xi[NI]; unsigned EMUSHORT xi[NI];
int k; int j, k;
unsigned long ll;
emovi (x, xi); emovi (x, xi);
k = (int) xi[E] - (EXONE - 1); k = (int) xi[E] - (EXONE - 1);
...@@ -3371,10 +3388,8 @@ eifrac (x, i, frac) ...@@ -3371,10 +3388,8 @@ eifrac (x, i, frac)
} }
if (k > (HOST_BITS_PER_LONG - 1)) if (k > (HOST_BITS_PER_LONG - 1))
{ {
/* /* long integer overflow: output large integer
; long integer overflow: output large integer and correct fraction */
; and correct fraction
*/
if (xi[0]) if (xi[0])
*i = ((unsigned long) 1) << (HOST_BITS_PER_LONG - 1); *i = ((unsigned long) 1) << (HOST_BITS_PER_LONG - 1);
else else
...@@ -3382,33 +3397,33 @@ eifrac (x, i, frac) ...@@ -3382,33 +3397,33 @@ eifrac (x, i, frac)
eshift (xi, k); eshift (xi, k);
if (extra_warnings) if (extra_warnings)
warning ("overflow on truncation to integer"); warning ("overflow on truncation to integer");
goto lab11;
} }
else if (k > 16)
if (k > 16)
{ {
/* /* Shift more than 16 bits: first shift up k-16 mod 16,
; shift more than 16 bits: shift up k-16, output the integer, then shift up by 16's. */
; then complete the shift to get the fraction. j = k - ((k >> 4) << 4);
*/ eshift (xi, j);
k -= 16; ll = xi[M];
k -= j;
do
{
eshup6 (xi);
ll = (ll << 16) | xi[M];
}
while ((k -= 16) > 0);
*i = ll;
if (xi[0])
*i = -(*i);
}
else
{
/* shift not more than 16 bits */
eshift (xi, k); eshift (xi, k);
*i = (long) xi[M] & 0xffff;
*i = (long) (((unsigned long) xi[M] << 16) | xi[M + 1]); if (xi[0])
eshup6 (xi); *i = -(*i);
goto lab10;
} }
/* shift not more than 16 bits */
eshift (xi, k);
*i = (long) xi[M] & 0xffff;
lab10:
if (xi[0])
*i = -(*i);
lab11:
xi[0] = 0; xi[0] = 0;
xi[E] = EXONE - 1; xi[E] = EXONE - 1;
xi[M] = 0; xi[M] = 0;
...@@ -3421,24 +3436,19 @@ eifrac (x, i, frac) ...@@ -3421,24 +3436,19 @@ eifrac (x, i, frac)
} }
/* /* Find unsigned long integer and fractional parts.
; Find unsigned long integer and fractional parts A negative e type input yields integer output = 0
but correct fraction. */
; unsigned long i;
; unsigned EMUSHORT x[NE], frac[NE];
; xifrac (x, &i, frac);
A negative e type input yields integer output = 0
but correct fraction.
*/
void void
euifrac (x, i, frac) euifrac (x, i, frac)
unsigned EMUSHORT *x; unsigned EMUSHORT *x;
long *i; unsigned long *i;
unsigned EMUSHORT *frac; unsigned EMUSHORT *frac;
{ {
unsigned long ll;
unsigned EMUSHORT xi[NI]; unsigned EMUSHORT xi[NI];
int k; int j, k;
emovi (x, xi); emovi (x, xi);
k = (int) xi[E] - (EXONE - 1); k = (int) xi[E] - (EXONE - 1);
...@@ -3449,42 +3459,42 @@ euifrac (x, i, frac) ...@@ -3449,42 +3459,42 @@ euifrac (x, i, frac)
emovo (xi, frac); emovo (xi, frac);
return; return;
} }
if (k > 32) if (k > HOST_BITS_PER_LONG)
{ {
/* /* Long integer overflow: output large integer
; long integer overflow: output large integer and correct fraction.
; and correct fraction Note, the BSD microvax compiler says that ~(0UL)
*/ is a syntax error. */
*i = ~(0L); *i = ~(0L);
eshift (xi, k); eshift (xi, k);
if (extra_warnings) if (extra_warnings)
warning ("overflow on truncation to unsigned integer"); warning ("overflow on truncation to unsigned integer");
goto lab10;
} }
else if (k > 16)
if (k > 16)
{ {
/* /* Shift more than 16 bits: first shift up k-16 mod 16,
; shift more than 16 bits: shift up k-16, output the integer, then shift up by 16's. */
; then complete the shift to get the fraction. j = k - ((k >> 4) << 4);
*/ eshift (xi, j);
k -= 16; ll = xi[M];
k -= j;
do
{
eshup6 (xi);
ll = (ll << 16) | xi[M];
}
while ((k -= 16) > 0);
*i = ll;
}
else
{
/* shift not more than 16 bits */
eshift (xi, k); eshift (xi, k);
*i = (long) xi[M] & 0xffff;
*i = (long) (((unsigned long) xi[M] << 16) | xi[M + 1]);
eshup6 (xi);
goto lab10;
} }
/* shift not more than 16 bits */ if (xi[0]) /* A negative value yields unsigned integer 0. */
eshift (xi, k);
*i = (long) xi[M] & 0xffff;
lab10:
if (xi[0])
*i = 0L; *i = 0L;
xi[0] = 0; xi[0] = 0;
xi[E] = EXONE - 1; xi[E] = EXONE - 1;
xi[M] = 0; xi[M] = 0;
...@@ -4900,7 +4910,9 @@ todec (x, y) ...@@ -4900,7 +4910,9 @@ todec (x, y)
/* If special NaN bit patterns are required, define them in tm.h /* If special NaN bit patterns are required, define them in tm.h
as arrays of unsigned 16-bit shorts. Otherwise, use the default as arrays of unsigned 16-bit shorts. Otherwise, use the default
patterns here. */ patterns here. */
#ifndef TFMODE_NAN #ifdef TFMODE_NAN
TFMODE_NAN;
#else
#ifdef MIEEE #ifdef MIEEE
unsigned EMUSHORT TFnan[8] = unsigned EMUSHORT TFnan[8] =
{0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
...@@ -4910,7 +4922,9 @@ unsigned EMUSHORT TFnan[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff}; ...@@ -4910,7 +4922,9 @@ unsigned EMUSHORT TFnan[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
#endif #endif
#endif #endif
#ifndef XFMODE_NAN #ifdef XFMODE_NAN
XFMODE_NAN;
#else
#ifdef MIEEE #ifdef MIEEE
unsigned EMUSHORT XFnan[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; unsigned EMUSHORT XFnan[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
#endif #endif
...@@ -4919,7 +4933,9 @@ unsigned EMUSHORT XFnan[6] = {0, 0, 0, 0xc000, 0xffff, 0}; ...@@ -4919,7 +4933,9 @@ unsigned EMUSHORT XFnan[6] = {0, 0, 0, 0xc000, 0xffff, 0};
#endif #endif
#endif #endif
#ifndef DFMODE_NAN #ifdef DFMODE_NAN
DFMODE_NAN;
#else
#ifdef MIEEE #ifdef MIEEE
unsigned EMUSHORT DFnan[4] = {0x7fff, 0xffff, 0xffff, 0xffff}; unsigned EMUSHORT DFnan[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
#endif #endif
...@@ -4928,7 +4944,9 @@ unsigned EMUSHORT DFnan[4] = {0, 0, 0, 0xfff8}; ...@@ -4928,7 +4944,9 @@ unsigned EMUSHORT DFnan[4] = {0, 0, 0, 0xfff8};
#endif #endif
#endif #endif
#ifndef SFMODE_NAN #ifdef SFMODE_NAN
SFMODE_NAN;
#else
#ifdef MIEEE #ifdef MIEEE
unsigned EMUSHORT SFnan[2] = {0x7fff, 0xffff}; unsigned EMUSHORT SFnan[2] = {0x7fff, 0xffff};
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment