1 /*---------------------------------------------------------------------------+
4 | Multiply one FPU_REG by another, put the result in a destination FPU_REG. |
6 | Copyright (C) 1992,1993,1997 |
7 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
8 | E-mail billm@suburbia.net |
10 | Returns the tag of the result if no exceptions or errors occurred. |
12 +---------------------------------------------------------------------------*/
14 /*---------------------------------------------------------------------------+
15 | The destination may be any FPU_REG, including one of the source FPU_REGs. |
16 +---------------------------------------------------------------------------*/
19 #include "exception.h"
20 #include "reg_constant.h"
21 #include "fpu_system.h"
25 Multiply two registers to give a register result.
26 The sources are st(deststnr) and (b,tagb,signb).
27 The destination is st(deststnr).
29 /* This routine must be called with non-empty source registers */
30 int FPU_mul(FPU_REG const *b, u_char tagb, int deststnr, int control_w)
32 FPU_REG *a = &st(deststnr);
34 u_char taga = FPU_gettagi(deststnr);
35 u_char saved_sign = getsign(dest);
36 u_char sign = (getsign(a) ^ getsign(b));
42 /* Both regs Valid, this should be the most common case. */
44 tag = FPU_u_mul(a, b, dest, control_w, sign, exponent(a) + exponent(b));
47 setsign(dest, saved_sign);
50 FPU_settagi(deststnr, tag);
54 if ( taga == TAG_Special )
55 taga = FPU_Special(a);
56 if ( tagb == TAG_Special )
57 tagb = FPU_Special(b);
59 if ( ((taga == TAG_Valid) && (tagb == TW_Denormal))
60 || ((taga == TW_Denormal) && (tagb == TAG_Valid))
61 || ((taga == TW_Denormal) && (tagb == TW_Denormal)) )
64 if ( denormal_operand() < 0 )
69 tag = FPU_u_mul(&x, &y, dest, control_w, sign,
70 exponent16(&x) + exponent16(&y));
73 setsign(dest, saved_sign);
76 FPU_settagi(deststnr, tag);
79 else if ( (taga <= TW_Denormal) && (tagb <= TW_Denormal) )
81 if ( ((tagb == TW_Denormal) || (taga == TW_Denormal))
82 && (denormal_operand() < 0) )
85 /* Must have either both arguments == zero, or
86 one valid and the other zero.
87 The result is therefore zero. */
88 FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
89 /* The 80486 book says that the answer is +0, but a real
90 80486 behaves this way.
91 IEEE-754 apparently says it should be this way. */
95 /* Must have infinities, NaNs, etc */
96 else if ( (taga == TW_NaN) || (tagb == TW_NaN) )
98 return real_2op_NaN(b, tagb, deststnr, &st(0));
100 else if ( ((taga == TW_Infinity) && (tagb == TAG_Zero))
101 || ((tagb == TW_Infinity) && (taga == TAG_Zero)) )
103 return arith_invalid(deststnr); /* Zero*Infinity is invalid */
105 else if ( ((taga == TW_Denormal) || (tagb == TW_Denormal))
106 && (denormal_operand() < 0) )
108 return FPU_Exception;
110 else if (taga == TW_Infinity)
112 FPU_copy_to_regi(a, TAG_Special, deststnr);
116 else if (tagb == TW_Infinity)
118 FPU_copy_to_regi(b, TAG_Special, deststnr);
126 EXCEPTION(EX_INTERNAL|0x102);
127 return FPU_Exception;
129 #endif /* PARANOID */