1 /////////////////////////////////////////////////////////////////////////
2 // $Id: ferr.cc,v 1.13 2008/09/02 19:46:30 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 "softfloat-specialize.h"
33 void BX_CPU_C::FPU_stack_overflow(void)
35 /* The masked response */
36 if (BX_CPU_THIS_PTR the_i387
.is_IA_masked())
38 BX_CPU_THIS_PTR the_i387
.FPU_push();
39 BX_WRITE_FPU_REG(floatx80_default_nan
, 0);
41 FPU_exception(FPU_EX_Stack_Overflow
);
44 void BX_CPU_C::FPU_stack_underflow(int stnr
, int pop_stack
)
46 /* The masked response */
47 if (BX_CPU_THIS_PTR the_i387
.is_IA_masked())
49 BX_WRITE_FPU_REG(floatx80_default_nan
, stnr
);
51 BX_CPU_THIS_PTR the_i387
.FPU_pop();
53 FPU_exception(FPU_EX_Stack_Underflow
);
56 /* Returns unmasked exceptions if occured */
57 unsigned BX_CPU_C::FPU_exception(unsigned exception
, bx_bool is_mem
)
59 /* Extract only the bits which we use to set the status word */
60 exception
&= (FPU_SW_Exceptions_Mask
);
62 /* Set the corresponding exception bits */
63 FPU_PARTIAL_STATUS
|= exception
;
65 unsigned unmasked
= FPU_PARTIAL_STATUS
& ~FPU_CONTROL_WORD
& FPU_CW_Exceptions_Mask
;
67 /* Set summary bits iff exception isn't masked */
69 FPU_PARTIAL_STATUS
|= (FPU_SW_Summary
| FPU_SW_Backward
);
71 if (exception
& (FPU_SW_Stack_Fault
| FPU_EX_Precision
))
73 if (! (exception
& FPU_SW_C1
)) {
74 /* This bit distinguishes over- from underflow for a stack fault,
75 and roundup from round-down for precision loss. */
76 FPU_PARTIAL_STATUS
&= ~FPU_SW_C1
;
80 // If #P unmasked exception occured the result still has to be
81 // written to the destination.
82 unmasked
&= ~FPU_CW_Precision
;
84 // If unmasked overflow or underflow occurs and destination is a memory
85 // location, the TOS and destination operands remain unchanged and no
86 // result is stored in the memory. If the destination is in the register
87 // stack, adjusted resulting value is stored in the destination operand.
89 unmasked
&= ~(FPU_CW_Underflow
| FPU_CW_Overflow
);