/*
* Copyright 1996 1995 by Open Software Foundation, Inc.
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appears in all copies and
* that both the copyright notice and this permission notice appear in
* supporting documentation.
*
* OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
* NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* pmk1.1
*/
/*
* (c) Copyright 1986 HEWLETT-PACKARD COMPANY
*
* To anyone who acknowledges that this file is provided "AS IS"
* without any express or implied warranty:
* permission to use, copy, modify, and distribute this file
* for any purpose is hereby granted without fee, provided that
* the above copyright notice and this notice appears in all
* copies, and that the name of Hewlett-Packard Company not be
* used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose.
*/
/* dbl_and_signs ands the sign bits of each argument and puts the result
* into the first argument. dbl_or_signs ors those same sign bits */
#define Dbl_and_signs( src1dst, src2) \
Dallp1(src1dst) = (Dallp1(src2)|~(1<<31)) & Dallp1(src1dst)
#define Dbl_or_signs( src1dst, src2) \
Dallp1(src1dst) = (Dallp1(src2)&(1<<31)) | Dallp1(src1dst)
/* The hidden bit is always the low bit of the exponent */
#define Dbl_clear_exponent_set_hidden(srcdst) Deposit_dexponent(srcdst,1)
#define Dbl_clear_signexponent_set_hidden(srcdst) \
Deposit_dsignexponent(srcdst,1)
#define Dbl_clear_sign(srcdst) Dallp1(srcdst) &= ~(1<<31)
#define Dbl_clear_signexponent(srcdst) \
Dallp1(srcdst) &= Dmantissap1((unsigned)-1)
/* Exponent field for doubles has already been cleared and may be
* included in the shift. Here we need to generate two double width
* variable shifts. The insignificant bits can be ignored.
* MTSAR f(varamount)
* VSHD srcdst.high,srcdst.low => srcdst.low
* VSHD 0,srcdst.high => srcdst.high
* This is very difficult to model with C expressions since the shift amount
* could exceed 32. */
/* varamount must be less than 64 */
#define Dbl_rightshift(srcdstA, srcdstB, varamount) \
{if((varamount) >= 32) { \
Dallp2(srcdstB) = Dallp1(srcdstA) >> (varamount-32); \
Dallp1(srcdstA)=0; \
} \
else if(varamount > 0) { \
Variable_shift_double(Dallp1(srcdstA), Dallp2(srcdstB), \
(varamount), Dallp2(srcdstB)); \
Dallp1(srcdstA) >>= varamount; \
} }
/* varamount must be less than 64 */
#define Dbl_rightshift_exponentmantissa(srcdstA, srcdstB, varamount) \
{if((varamount) >= 32) { \
Dallp2(srcdstB) = Dexponentmantissap1(srcdstA) >> ((varamount)-32); \
Dallp1(srcdstA) &= (1<<31); /* clear exponentmantissa field */ \
} \
else if(varamount > 0) { \
Variable_shift_double(Dexponentmantissap1(srcdstA), Dallp2(srcdstB), \
(varamount), Dallp2(srcdstB)); \
Deposit_dexponentmantissap1(srcdstA, \
(Dexponentmantissap1(srcdstA)>>(varamount))); \
} }
/* varamount must be less than 64 */
#define Dbl_leftshift(srcdstA, srcdstB, varamount) \
{if((varamount) >= 32) { \
Dallp1(srcdstA) = Dallp2(srcdstB) << (varamount-32); \
Dallp2(srcdstB)=0; \
} \
else { \
if ((varamount) > 0) { \
Dallp1(srcdstA) = (Dallp1(srcdstA) << (varamount)) | \
(Dallp2(srcdstB) >> (32-(varamount))); \
Dallp2(srcdstB) <<= varamount; \
} \
} }
#define Dbl_leftshiftby1_withextent(lefta,leftb,right,resulta,resultb) \
Shiftdouble(Dallp1(lefta), Dallp2(leftb), 31, Dallp1(resulta)); \
Shiftdouble(Dallp2(leftb), Extall(right), 31, Dallp2(resultb))
/* This magnitude comparison uses the signless first words and
* the regular part2 words. The comparison is graphically:
*
* 1st greater? -------------
* |
* 1st less?-----------------+---------
* | |
* 2nd greater or equal----->| |
* False True
*/
#define Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \
((signlessleft <= signlessright) && \
( (signlessleft < signlessright) || (Dallp2(leftB)<Dallp2(rightB)) ))
#define Dbl_copytoint_exponentmantissap1(src,dest) \
dest = Dexponentmantissap1(src)
/* A quiet NaN has the high mantissa bit clear and at least on other (in this
* case the adjacent bit) bit set. */
#define Dbl_set_quiet(dbl_value) Deposit_dhigh2mantissa(dbl_value,1)
#define Dbl_set_exponent(dbl_value, exp) Deposit_dexponent(dbl_value,exp)
/* Use the following macro for both overflow & underflow conditions */
#define ovfl -
#define unfl +
#define Dbl_setwrapped_exponent(dbl_value,exponent,op) \
Deposit_dexponent(dbl_value,(exponent op DBL_WRAP))
/* The high bit is always zero so arithmetic or logical shifts will work. */
#define Dbl_right_align(srcdstA,srcdstB,shift,extent) \
if( shift >= 32 ) \
{ \
/* Big shift requires examining the portion shift off \
the end to properly set inexact. */ \
if(shift < 64) \
{ \
if(shift > 32) \
{ \
Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB), \
shift-32, Extall(extent)); \
if(Dallp2(srcdstB) << (64 - (shift))) Ext_setone_low(extent); \
} \
else Extall(extent) = Dallp2(srcdstB); \
Dallp2(srcdstB) = Dallp1(srcdstA) >> (shift - 32); \
} \
else \
{ \
Extall(extent) = Dallp1(srcdstA); \
if(Dallp2(srcdstB)) Ext_setone_low(extent); \
Dallp2(srcdstB) = 0; \
} \
Dallp1(srcdstA) = 0; \
} \
else \
{ \
/* Small alignment is simpler. Extension is easily set. */ \
if (shift > 0) \
{ \
Extall(extent) = Dallp2(srcdstB) << (32 - (shift)); \
Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB),shift, \
Dallp2(srcdstB)); \
Dallp1(srcdstA) >>= shift; \
} \
else Extall(extent) = 0; \
}
/*
* Here we need to shift the result right to correct for an overshift
* (due to the exponent becoming negative) during normalization.
*/
#define Dbl_fix_overshift(srcdstA,srcdstB,shift,extent) \
Extall(extent) = Dallp2(srcdstB) << (32 - (shift)); \
Dallp2(srcdstB) = (Dallp1(srcdstA) << (32 - (shift))) | \
(Dallp2(srcdstB) >> (shift)); \
Dallp1(srcdstA) = Dallp1(srcdstA) >> shift
/* The left argument is never smaller than the right argument */
#define Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb) \
if( Dallp2(rightb) > Dallp2(leftb) ) Dallp1(lefta)--; \
Dallp2(resultb) = Dallp2(leftb) - Dallp2(rightb); \
Dallp1(resulta) = Dallp1(lefta) - Dallp1(righta)
/* Subtract right augmented with extension from left augmented with zeros and
* store into result and extension. */
#define Dbl_subtract_withextension(lefta,leftb,righta,rightb,extent,resulta,resultb) \
Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb); \
if( (Extall(extent) = 0-Extall(extent)) ) \
{ \
if((Dallp2(resultb)--) == 0) Dallp1(resulta)--; \
}
#define Dbl_addition(lefta,leftb,righta,rightb,resulta,resultb) \
/* If the sum of the low words is less than either source, then \
* an overflow into the next word occurred. */ \
Dallp1(resulta) = Dallp1(lefta) + Dallp1(righta); \
if((Dallp2(resultb) = Dallp2(leftb) + Dallp2(rightb)) < Dallp2(rightb)) \
Dallp1(resulta)++
#define Dbl_xortointp1(left,right,result) \
result = Dallp1(left) XOR Dallp1(right)
#define Dbl_xorfromintp1(left,right,result) \
Dallp1(result) = left XOR Dallp1(right)
int dbl_fadd(dbl_floating_point *, dbl_floating_point*, dbl_floating_point*, unsigned int *);
int dbl_fcmp(dbl_floating_point *, dbl_floating_point*, unsigned int, unsigned int *);
int dbl_fdiv(dbl_floating_point *, dbl_floating_point *, dbl_floating_point *, unsigned int *);
int dbl_fmpy(dbl_floating_point *, dbl_floating_point *, dbl_floating_point*, unsigned int *);
int dbl_frem(dbl_floating_point *, dbl_floating_point *, dbl_floating_point*, unsigned int *);
int dbl_fsqrt(dbl_floating_point *, dbl_floating_point *, unsigned int *);
int dbl_fsub(dbl_floating_point *, dbl_floating_point *, dbl_floating_point*, unsigned int *);
dbl_floating_point dbl_setoverflow(unsigned int);
int sgl_to_dbl_fcnvff(sgl_floating_point *, dbl_floating_point *, unsigned int *);
int dbl_to_sgl_fcnvff(dbl_floating_point *, sgl_floating_point *, unsigned int *);
int dbl_frnd(dbl_floating_point *, dbl_floating_point *, unsigned int *);