1 // SPDX-License-Identifier: GPL-2.0
2 /*---------------------------------------------------------------------------+
5 | Multiply one FPU_REG by another, put the result in a destination FPU_REG. |
7 | Copyright (C) 1992,1993,1997 |
8 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
9 | E-mail billm@suburbia.net |
11 | Returns the tag of the result if no exceptions or errors occurred. |
13 +---------------------------------------------------------------------------*/
15 /*---------------------------------------------------------------------------+
16 | The destination may be any FPU_REG, including one of the source FPU_REGs. |
17 +---------------------------------------------------------------------------*/
20 #include "exception.h"
21 #include "reg_constant.h"
22 #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
));
40 /* Both regs Valid, this should be the most common case. */
43 FPU_u_mul(a
, b
, dest
, control_w
, sign
,
44 exponent(a
) + exponent(b
));
46 setsign(dest
, saved_sign
);
49 FPU_settagi(deststnr
, tag
);
53 if (taga
== TAG_Special
)
54 taga
= FPU_Special(a
);
55 if (tagb
== TAG_Special
)
56 tagb
= FPU_Special(b
);
58 if (((taga
== TAG_Valid
) && (tagb
== TW_Denormal
))
59 || ((taga
== TW_Denormal
) && (tagb
== TAG_Valid
))
60 || ((taga
== TW_Denormal
) && (tagb
== TW_Denormal
))) {
62 if (denormal_operand() < 0)
67 tag
= FPU_u_mul(&x
, &y
, dest
, control_w
, sign
,
68 exponent16(&x
) + exponent16(&y
));
70 setsign(dest
, saved_sign
);
73 FPU_settagi(deststnr
, tag
);
75 } else if ((taga
<= TW_Denormal
) && (tagb
<= TW_Denormal
)) {
76 if (((tagb
== TW_Denormal
) || (taga
== TW_Denormal
))
77 && (denormal_operand() < 0))
80 /* Must have either both arguments == zero, or
81 one valid and the other zero.
82 The result is therefore zero. */
83 FPU_copy_to_regi(&CONST_Z
, TAG_Zero
, deststnr
);
84 /* The 80486 book says that the answer is +0, but a real
85 80486 behaves this way.
86 IEEE-754 apparently says it should be this way. */
90 /* Must have infinities, NaNs, etc */
91 else if ((taga
== TW_NaN
) || (tagb
== TW_NaN
)) {
92 return real_2op_NaN(b
, tagb
, deststnr
, &st(0));
93 } else if (((taga
== TW_Infinity
) && (tagb
== TAG_Zero
))
94 || ((tagb
== TW_Infinity
) && (taga
== TAG_Zero
))) {
95 return arith_invalid(deststnr
); /* Zero*Infinity is invalid */
96 } else if (((taga
== TW_Denormal
) || (tagb
== TW_Denormal
))
97 && (denormal_operand() < 0)) {
99 } else if (taga
== TW_Infinity
) {
100 FPU_copy_to_regi(a
, TAG_Special
, deststnr
);
103 } else if (tagb
== TW_Infinity
) {
104 FPU_copy_to_regi(b
, TAG_Special
, deststnr
);
110 EXCEPTION(EX_INTERNAL
| 0x102);
111 return FPU_Exception
;
113 #endif /* PARANOID */