0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "fpu_system.h"
0015 #include "exception.h"
0016 #include "fpu_emu.h"
0017 #include "status_w.h"
0018 #include "reg_constant.h"
0019
0020 static void fchs(FPU_REG *st0_ptr, u_char st0tag)
0021 {
0022 if (st0tag ^ TAG_Empty) {
0023 signbyte(st0_ptr) ^= SIGN_NEG;
0024 clear_C1();
0025 } else
0026 FPU_stack_underflow();
0027 }
0028
0029 static void fabs(FPU_REG *st0_ptr, u_char st0tag)
0030 {
0031 if (st0tag ^ TAG_Empty) {
0032 setpositive(st0_ptr);
0033 clear_C1();
0034 } else
0035 FPU_stack_underflow();
0036 }
0037
0038 static void ftst_(FPU_REG *st0_ptr, u_char st0tag)
0039 {
0040 switch (st0tag) {
0041 case TAG_Zero:
0042 setcc(SW_C3);
0043 break;
0044 case TAG_Valid:
0045 if (getsign(st0_ptr) == SIGN_POS)
0046 setcc(0);
0047 else
0048 setcc(SW_C0);
0049 break;
0050 case TAG_Special:
0051 switch (FPU_Special(st0_ptr)) {
0052 case TW_Denormal:
0053 if (getsign(st0_ptr) == SIGN_POS)
0054 setcc(0);
0055 else
0056 setcc(SW_C0);
0057 if (denormal_operand() < 0) {
0058 #ifdef PECULIAR_486
0059
0060 if (getsign(st0_ptr) == SIGN_POS)
0061 setcc(SW_C3);
0062 #endif
0063 return;
0064 }
0065 break;
0066 case TW_NaN:
0067 setcc(SW_C0 | SW_C2 | SW_C3);
0068 EXCEPTION(EX_Invalid);
0069 break;
0070 case TW_Infinity:
0071 if (getsign(st0_ptr) == SIGN_POS)
0072 setcc(0);
0073 else
0074 setcc(SW_C0);
0075 break;
0076 default:
0077 setcc(SW_C0 | SW_C2 | SW_C3);
0078 EXCEPTION(EX_INTERNAL | 0x14);
0079 break;
0080 }
0081 break;
0082 case TAG_Empty:
0083 setcc(SW_C0 | SW_C2 | SW_C3);
0084 EXCEPTION(EX_StackUnder);
0085 break;
0086 }
0087 }
0088
0089 static void fxam(FPU_REG *st0_ptr, u_char st0tag)
0090 {
0091 int c = 0;
0092 switch (st0tag) {
0093 case TAG_Empty:
0094 c = SW_C3 | SW_C0;
0095 break;
0096 case TAG_Zero:
0097 c = SW_C3;
0098 break;
0099 case TAG_Valid:
0100 c = SW_C2;
0101 break;
0102 case TAG_Special:
0103 switch (FPU_Special(st0_ptr)) {
0104 case TW_Denormal:
0105 c = SW_C2 | SW_C3;
0106 break;
0107 case TW_NaN:
0108
0109 if ((st0_ptr->sigh & 0x80000000)
0110 && (exponent(st0_ptr) == EXP_OVER))
0111 c = SW_C0;
0112 break;
0113 case TW_Infinity:
0114 c = SW_C2 | SW_C0;
0115 break;
0116 }
0117 }
0118 if (getsign(st0_ptr) == SIGN_NEG)
0119 c |= SW_C1;
0120 setcc(c);
0121 }
0122
0123 static FUNC_ST0 const fp_etc_table[] = {
0124 fchs, fabs, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal,
0125 ftst_, fxam, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal
0126 };
0127
0128 void FPU_etc(void)
0129 {
0130 (fp_etc_table[FPU_rm]) (&st(0), FPU_gettag0());
0131 }