2004-06-18 18:11:11 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2005-03-21 00:19:38 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-06-18 18:11:11 +04:00
|
|
|
//
|
2009-10-15 00:45:29 +04:00
|
|
|
// Copyright (c) 2003-2009 Stanislav Shwartsman
|
2007-03-24 00:27:13 +03:00
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
2004-06-18 18:11:11 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 20:29:34 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-05-12 22:07:48 +04:00
|
|
|
//
|
2004-06-18 18:11:11 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu/cpu.h"
|
2004-06-18 18:11:11 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
|
|
|
|
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
|
|
|
|
#include "softfloatx80.h"
|
|
|
|
|
|
|
|
const floatx80 Const_QNaN = packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction);
|
|
|
|
const floatx80 Const_Z = packFloatx80(0, 0x0000, 0);
|
|
|
|
const floatx80 Const_1 = packFloatx80(0, 0x3fff, BX_CONST64(0x8000000000000000));
|
|
|
|
const floatx80 Const_L2T = packFloatx80(0, 0x4000, BX_CONST64(0xd49a784bcd1b8afe));
|
|
|
|
const floatx80 Const_L2E = packFloatx80(0, 0x3fff, BX_CONST64(0xb8aa3b295c17f0bc));
|
|
|
|
const floatx80 Const_PI = packFloatx80(0, 0x4000, BX_CONST64(0xc90fdaa22168c235));
|
|
|
|
const floatx80 Const_LG2 = packFloatx80(0, 0x3ffd, BX_CONST64(0x9a209a84fbcff799));
|
|
|
|
const floatx80 Const_LN2 = packFloatx80(0, 0x3ffe, BX_CONST64(0xb17217f7d1cf79ac));
|
|
|
|
const floatx80 Const_INF = packFloatx80(0, 0x7fff, BX_CONST64(0x8000000000000000));
|
|
|
|
|
|
|
|
/* A fast way to find out whether x is one of RC_DOWN or RC_CHOP
|
|
|
|
(and not one of RC_RND or RC_UP).
|
|
|
|
*/
|
|
|
|
#define DOWN_OR_CHOP() (FPU_CONTROL_WORD & FPU_CW_RC & FPU_RC_DOWN)
|
|
|
|
|
|
|
|
BX_CPP_INLINE floatx80 FPU_round_const(const floatx80 &a, int adj)
|
|
|
|
{
|
|
|
|
floatx80 result = a;
|
|
|
|
result.fraction += adj;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLDL2T(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
2009-04-13 12:37:49 +04:00
|
|
|
BX_WRITE_FPU_REG(FPU_round_const(Const_L2T, (FPU_CONTROL_WORD & FPU_CW_RC) == FPU_RC_UP), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLDL2E(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
|
|
|
BX_WRITE_FPU_REG(FPU_round_const(Const_L2E, DOWN_OR_CHOP() ? -1 : 0), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLDPI(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
|
|
|
BX_WRITE_FPU_REG(FPU_round_const(Const_PI, DOWN_OR_CHOP() ? -1 : 0), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLDLG2(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
|
|
|
BX_WRITE_FPU_REG(FPU_round_const(Const_LG2, DOWN_OR_CHOP() ? -1 : 0), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLDLN2(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
|
|
|
BX_WRITE_FPU_REG(FPU_round_const(Const_LN2, DOWN_OR_CHOP() ? -1 : 0), 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLD1(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
|
|
|
BX_WRITE_FPU_REG(Const_1, 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::FLDZ(bxInstruction_c *i)
|
2004-06-18 18:11:11 +04:00
|
|
|
{
|
|
|
|
BX_CPU_THIS_PTR prepareFPU(i);
|
2009-04-27 18:00:55 +04:00
|
|
|
BX_CPU_THIS_PTR FPU_update_last_instruction(i);
|
2004-06-18 18:11:11 +04:00
|
|
|
|
|
|
|
clear_C1();
|
|
|
|
|
|
|
|
if (! IS_TAG_EMPTY(-1))
|
|
|
|
{
|
2009-05-28 23:25:33 +04:00
|
|
|
FPU_stack_overflow();
|
2009-03-11 00:43:11 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_CPU_THIS_PTR the_i387.FPU_push();
|
|
|
|
BX_WRITE_FPU_REG(Const_Z, 0);
|
2004-06-18 18:11:11 +04:00
|
|
|
}
|
|
|
|
}
|
2008-04-05 01:05:37 +04:00
|
|
|
|
|
|
|
#endif
|