0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "fpu_emu.h"
0020 #include "exception.h"
0021 #include "reg_constant.h"
0022 #include "fpu_system.h"
0023
0024
0025
0026
0027
0028
0029
0030 int FPU_mul(FPU_REG const *b, u_char tagb, int deststnr, int control_w)
0031 {
0032 FPU_REG *a = &st(deststnr);
0033 FPU_REG *dest = a;
0034 u_char taga = FPU_gettagi(deststnr);
0035 u_char saved_sign = getsign(dest);
0036 u_char sign = (getsign(a) ^ getsign(b));
0037 int tag;
0038
0039 if (!(taga | tagb)) {
0040
0041
0042 tag =
0043 FPU_u_mul(a, b, dest, control_w, sign,
0044 exponent(a) + exponent(b));
0045 if (tag < 0) {
0046 setsign(dest, saved_sign);
0047 return tag;
0048 }
0049 FPU_settagi(deststnr, tag);
0050 return tag;
0051 }
0052
0053 if (taga == TAG_Special)
0054 taga = FPU_Special(a);
0055 if (tagb == TAG_Special)
0056 tagb = FPU_Special(b);
0057
0058 if (((taga == TAG_Valid) && (tagb == TW_Denormal))
0059 || ((taga == TW_Denormal) && (tagb == TAG_Valid))
0060 || ((taga == TW_Denormal) && (tagb == TW_Denormal))) {
0061 FPU_REG x, y;
0062 if (denormal_operand() < 0)
0063 return FPU_Exception;
0064
0065 FPU_to_exp16(a, &x);
0066 FPU_to_exp16(b, &y);
0067 tag = FPU_u_mul(&x, &y, dest, control_w, sign,
0068 exponent16(&x) + exponent16(&y));
0069 if (tag < 0) {
0070 setsign(dest, saved_sign);
0071 return tag;
0072 }
0073 FPU_settagi(deststnr, tag);
0074 return tag;
0075 } else if ((taga <= TW_Denormal) && (tagb <= TW_Denormal)) {
0076 if (((tagb == TW_Denormal) || (taga == TW_Denormal))
0077 && (denormal_operand() < 0))
0078 return FPU_Exception;
0079
0080
0081
0082
0083 FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr);
0084
0085
0086
0087 setsign(dest, sign);
0088 return TAG_Zero;
0089 }
0090
0091 else if ((taga == TW_NaN) || (tagb == TW_NaN)) {
0092 return real_2op_NaN(b, tagb, deststnr, &st(0));
0093 } else if (((taga == TW_Infinity) && (tagb == TAG_Zero))
0094 || ((tagb == TW_Infinity) && (taga == TAG_Zero))) {
0095 return arith_invalid(deststnr);
0096 } else if (((taga == TW_Denormal) || (tagb == TW_Denormal))
0097 && (denormal_operand() < 0)) {
0098 return FPU_Exception;
0099 } else if (taga == TW_Infinity) {
0100 FPU_copy_to_regi(a, TAG_Special, deststnr);
0101 setsign(dest, sign);
0102 return TAG_Special;
0103 } else if (tagb == TW_Infinity) {
0104 FPU_copy_to_regi(b, TAG_Special, deststnr);
0105 setsign(dest, sign);
0106 return TAG_Special;
0107 }
0108 #ifdef PARANOID
0109 else {
0110 EXCEPTION(EX_INTERNAL | 0x102);
0111 return FPU_Exception;
0112 }
0113 #endif
0114
0115 return 0;
0116 }