changes for different byte orderings

This commit is contained in:
ceriel 1989-10-25 17:15:37 +00:00
parent 07f019213d
commit 13ea4896b0
8 changed files with 57 additions and 25 deletions

View file

@ -23,8 +23,13 @@ _double d1,d2;
int sign1,sign2;
int rv;
#if FL_MSL_AT_LOW_ADDRESS
l1 = get4((char *)&d1);
l2 = get4((char *)&d2);
#else
l1 = get4(((char *)&d1+4));
l2 = get4(((char *)&d2+4));
#endif
sign1 = SIGN(l1);
sign2 = SIGN(l2);
if (sign1 != sign2) {
@ -39,8 +44,13 @@ _double d1,d2;
}
else { /* decide in 2nd half */
unsigned long u1, u2;
#if FL_MSL_AT_LOW_ADDRESS
u1 = get4(((char *)&d1 + 4));
u2 = get4(((char *)&d2 + 4));
#else
u1 = get4((char *)&d1);
u2 = get4((char *)&d2);
#endif
if (u1 == u2)
return(0);
if (u1 < u2) rv = 1;

View file

@ -108,8 +108,16 @@ dbl_over: trap(EFOVFL);
* STORE MANTISSA
*/
#if FL_MSL_AT_LOW_ADDRESS
put4(DBL->_s.p1.fract, (char *) &DBL->_s.p1.fract);
put4(DBL->_s.p2, (char *) &DBL->_s.p2);
#else
{ unsigned long l;
put4(DBL->_s.p2, (char *) &l);
put4(DBL->_s.p1.fract, (char *) &DBL->_s.p2);
DBL->_s.p1.fract = l;
}
#endif
}
else {
/*

View file

@ -52,9 +52,20 @@ zero: zrf_ext(to);
goto zero;
}
/* there is a number to convert so lets get started */
/* first extract the exponent; its always in the first two bytes */
#if FL_MSL_AT_LOW_ADDRESS
#if FL_MSW_AT_LOW_ADDRESS
to->exp = uget2(cpt1);
#else
to->exp = uget2(cpt1+2);
#endif
#else
#if FL_MSW_AT_LOW_ADDRESS
to->exp = uget2(cpt1+4);
#else
to->exp = uget2(cpt1+6);
#endif
#endif
to->sign = (to->exp & 0x8000); /* set sign bit */
to->exp ^= to->sign;
if (size == sizeof(DOUBLE))
@ -65,17 +76,23 @@ zero: zrf_ext(to);
leadbit++; /* will set Lead bit later */
else to->exp++;
to->m1 = get4(cpt1);
if (size == sizeof(DOUBLE)) {
to->m1 <<= DBL_M1LEFT; /* shift */
to->exp -= DBL_BIAS; /* remove bias */
#if FL_MSL_AT_LOW_ADDRESS
to->m1 = get4(cpt1);
cpt1 += 4;
tmp = get4(cpt1);
#else
tmp = get4(cpt1);
cpt1 += 4;
to->m1 = get4(cpt1);
#endif
to->m1 <<= DBL_M1LEFT; /* shift */
to->exp -= DBL_BIAS; /* remove bias */
to->m1 |= (tmp>>DBL_RPACK); /* plus 10 == 32 */
to->m2 = (tmp<<DBL_LPACK); /* plus 22 == 32 */
}
else { /* size == sizeof(SINGLE) */
to->m1 = get4(cpt1);
to->m1 <<= SGL_M1LEFT; /* shift */
to->exp -= SGL_BIAS; /* remove bias */
to->m2 = 0L;

View file

@ -13,7 +13,11 @@
#define Xchar(ch) ((ch) & 0377)
#endif
#if ! BYTES_REVERSED
#define BYTES_REVERSED (MSB_AT_LOW_ADDRESS != FL_MSB_AT_LOW_ADDRESS)
#define WORDS_REVERSED (MSW_AT_LOW_ADDRESS != FL_MSW_AT_LOW_ADDRESS)
#define LONGS_REVERSED (FL_MSL_AT_LOW_ADDRESS)
#if BYTES_REVERSED
#define uget2(c) (Xchar((c)[1]) | ((unsigned) Xchar((c)[0]) << 8))
#define Xput2(i, c) (((c)[1] = (i)), ((c)[0] = (i) >> 8))
#define put2(i, c) { register int j = (i); Xput2(j, c); }
@ -25,7 +29,7 @@
#define get2(c) ((short) uget2(c))
#if WORDS_REVERSED || ! BYTES_REVERSED
#if WORDS_REVERSED || BYTES_REVERSED
#define get4(c) (uget2((c)+2) | ((long) uget2(c) << 16))
#define put4(l, c) { register long x=(l); \
Xput2((int)x,(c)+2); \

View file

@ -9,13 +9,11 @@
NEGATE A FLOATING POINT (NGF 4)
*/
/********************************************************/
/*
Assumes exponent is located in bytes 0 & 1
*/
/********************************************************/
#include "FP_types.h"
#include "get_put.h"
#define OFF ((FL_MSW_AT_LOW_ADDRESS ? 0 : 2) + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
_float
ngf4(f)
_float f;
@ -23,7 +21,7 @@ _float f;
unsigned char *p;
if (f != (_float) 0) {
p = (unsigned char *) &f;
p = (unsigned char *) &f + OFF;
*p ^= 0x80;
}
return f;

View file

@ -9,12 +9,11 @@
NEGATE A FLOATING POINT (NGF 8)
*/
/********************************************************/
/*
Assumes exponent is located in bytes 0 & 1
*/
/********************************************************/
#include "FP_types.h"
#include "get_put.h"
#define OFF ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
_double
ngf8(f)
@ -23,7 +22,7 @@ _double f;
unsigned char *p;
if (f.__double[0] != 0 || f.__double[1] != 0) {
p = (unsigned char *) &f;
p = (unsigned char *) &f + OFF;
*p ^= 0x80;
}
return f;

View file

@ -11,20 +11,18 @@
#include "FP_types.h"
extern _float adf4();
extern _float adf4(), ngf4();
_float
sbf4(s2,s1)
_float s1,s2;
{
unsigned char *p;
_float *result = &s1; /* s1 may not be in a register! */
if (s2 == (_float) 0) {
return s1;
}
p = (unsigned char *) &s2;
*p ^= 0x80; /* change sign of s2 */
s2 = ngf4(s2);
*result = adf4(s2,s1);
return(s1); /* add and return result */
}

View file

@ -11,20 +11,18 @@
#include "FP_types.h"
extern _double adf8();
extern _double adf8(), ngf8();
_double
sbf8(s2,s1)
_double s1,s2;
{
unsigned char *p; /* sufficient to access sign bit */
_double *result = &s1; /* s1 may not be in a register! */
if (s2.__double[0] == 0 && s2.__double[1] == 0) {
return s1;
}
p = (unsigned char *) &s2;
*p ^= 0x80; /* change sign of s2 */
s2 = ngf8(s2);
*result = adf8(s2,s1); /* add and return result */
return(s1);
}