This source file includes following definitions.
- FPU_mul
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "fpu_emu.h"
20 #include "exception.h"
21 #include "reg_constant.h"
22 #include "fpu_system.h"
23
24
25
26
27
28
29
30 int FPU_mul(FPU_REG const *b, u_char tagb, int deststnr, int control_w)
31 {
32 FPU_REG *a = &st(deststnr);
33 FPU_REG *dest = a;
34 u_char taga = FPU_gettagi(deststnr);
35 u_char saved_sign = getsign(dest);
36 u_char sign = (getsign(a) ^ getsign(b));
37 int tag;
38
39 if (!(taga | tagb)) {
40
41
42 tag =
43 FPU_u_mul(a, b, dest, control_w, sign,
44 exponent(a) + exponent(b));
45 if (tag < 0) {
46 setsign(dest, saved_sign);
47 return tag;
48 }
49 FPU_settagi(deststnr, tag);
50 return tag;
51 }
52
53 if (taga == TAG_Special)
54 taga = FPU_Special(a);
55 if (tagb == TAG_Special)
56 tagb = FPU_Special(b);
57
58 if (((taga == TAG_Valid) && (tagb == TW_Denormal))
59 || ((taga == TW_Denormal) && (tagb == TAG_Valid))
60 || ((taga == TW_Denormal) && (tagb == TW_Denormal))) {
61 FPU_REG x, y;
62 if (denormal_operand() < 0)
63 return FPU_Exception;
64
65 FPU_to_exp16(a, &x);
66 FPU_to_exp16(b, &y);
67 tag = FPU_u_mul(&x, &y, dest, control_w, sign,
68 exponent16(&x) + exponent16(&y));
69 if (tag < 0) {
70 setsign(dest, saved_sign);
71 return tag;
72 }
73 FPU_settagi(deststnr, tag);
74 return tag;
75 } else if ((taga <= TW_Denormal) && (tagb <= TW_Denormal)) {
76 if (((tagb == TW_Denormal) || (taga == TW_Denormal))
77 && (denormal_operand() < 0))
78 return FPU_Exception;
79
80
81
82
83 FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
84
85
86
87 setsign(dest, sign);
88 return TAG_Zero;
89 }
90
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);
96 } else if (((taga == TW_Denormal) || (tagb == TW_Denormal))
97 && (denormal_operand() < 0)) {
98 return FPU_Exception;
99 } else if (taga == TW_Infinity) {
100 FPU_copy_to_regi(a, TAG_Special, deststnr);
101 setsign(dest, sign);
102 return TAG_Special;
103 } else if (tagb == TW_Infinity) {
104 FPU_copy_to_regi(b, TAG_Special, deststnr);
105 setsign(dest, sign);
106 return TAG_Special;
107 }
108 #ifdef PARANOID
109 else {
110 EXCEPTION(EX_INTERNAL | 0x102);
111 return FPU_Exception;
112 }
113 #endif
114
115 return 0;
116 }