1 /////////////////////////////////////////////////////////////////////////
2 // $Id: fpu_misc.cc,v 1.14 2008/05/10 13:34:01 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2003 Stanislav Shwartsman
6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net]
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /////////////////////////////////////////////////////////////////////////
24 #define NEED_CPU_REG_SHORTCUTS 1
27 #define LOG_THIS BX_CPU_THIS_PTR
31 #include "softfloatx80.h"
34 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FXCH_STi(bxInstruction_c
*i
)
37 BX_CPU_THIS_PTR
prepareFPU(i
);
39 int st0_tag
= BX_CPU_THIS_PTR the_i387
.FPU_gettagi(0);
40 int sti_tag
= BX_CPU_THIS_PTR the_i387
.FPU_gettagi(i
->rm());
42 floatx80 st0_reg
= BX_READ_FPU_REG(0);
43 floatx80 sti_reg
= BX_READ_FPU_REG(i
->rm());
47 if (st0_tag
== FPU_Tag_Empty
|| sti_tag
== FPU_Tag_Empty
)
49 BX_CPU_THIS_PTR
FPU_exception(FPU_EX_Stack_Underflow
);
51 if(BX_CPU_THIS_PTR the_i387
.is_IA_masked())
54 if (st0_tag
== FPU_Tag_Empty
)
55 st0_reg
= floatx80_default_nan
;
57 if (sti_tag
== FPU_Tag_Empty
)
58 sti_reg
= floatx80_default_nan
;
63 BX_WRITE_FPU_REG(st0_reg
, i
->rm());
64 BX_WRITE_FPU_REG(sti_reg
, 0);
66 BX_INFO(("FXCH_STi: required FPU, configure --enable-fpu"));
71 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FCHS(bxInstruction_c
*i
)
74 BX_CPU_THIS_PTR
prepareFPU(i
);
76 if (IS_TAG_EMPTY(0)) {
77 BX_CPU_THIS_PTR
FPU_stack_underflow(0);
83 floatx80 st0_reg
= BX_READ_FPU_REG(0);
84 BX_WRITE_FPU_REG(floatx80_chs(st0_reg
), 0);
86 BX_INFO(("FCHS: required FPU, configure --enable-fpu"));
91 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FABS(bxInstruction_c
*i
)
94 BX_CPU_THIS_PTR
prepareFPU(i
);
96 if (IS_TAG_EMPTY(0)) {
97 BX_CPU_THIS_PTR
FPU_stack_underflow(0);
103 floatx80 st0_reg
= BX_READ_FPU_REG(0);
104 BX_WRITE_FPU_REG(floatx80_abs(st0_reg
), 0);
106 BX_INFO(("FABS: required FPU, configure --enable-fpu"));
111 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FDECSTP(bxInstruction_c
*i
)
114 BX_CPU_THIS_PTR
prepareFPU(i
);
118 BX_CPU_THIS_PTR the_i387
.tos
= (BX_CPU_THIS_PTR the_i387
.tos
-1) & 7;
120 BX_INFO(("FDECSTP: required FPU, configure --enable-fpu"));
125 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FINCSTP(bxInstruction_c
*i
)
128 BX_CPU_THIS_PTR
prepareFPU(i
);
132 BX_CPU_THIS_PTR the_i387
.tos
= (BX_CPU_THIS_PTR the_i387
.tos
+1) & 7;
134 BX_INFO(("FINCSTP: required FPU, configure --enable-fpu"));
139 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FFREE_STi(bxInstruction_c
*i
)
142 BX_CPU_THIS_PTR
prepareFPU(i
);
143 BX_CPU_THIS_PTR the_i387
.FPU_settagi(FPU_Tag_Empty
, i
->rm());
145 BX_INFO(("FFREE_STi: required FPU, configure --enable-fpu"));
150 * Free the st(0) register and pop it from the FPU stack.
151 * "Undocumented" by Intel & AMD but mentioned in AMDs Athlon Docs.
155 void BX_CPP_AttrRegparmN(1) BX_CPU_C::FFREEP_STi(bxInstruction_c
*i
)
158 BX_CPU_THIS_PTR
prepareFPU(i
);
159 BX_CPU_THIS_PTR the_i387
.FPU_settagi(FPU_Tag_Empty
, i
->rm());
160 BX_CPU_THIS_PTR the_i387
.FPU_pop();
162 BX_INFO(("FFREEP_STi: required FPU, configure --enable-fpu"));