[fast486]: code formatting + add a comment about the instruction 0xF1.
[reactos.git] / reactos / lib / fast486 / fpu.h
1 /*
2 * Fast486 386/486 CPU Emulation Library
3 * fpu.h
4 *
5 * Copyright (C) 2014 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #ifndef _FPU_H_
23 #define _FPU_H_
24
25 #pragma once
26
27 #include "opcodes.h"
28
29 /* DEFINES ********************************************************************/
30
31 #define FPU_CHECK() if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_EM) \
32 { \
33 Fast486Exception(State, FAST486_EXCEPTION_NM); \
34 return FALSE; \
35 }
36 #define FPU_ST(i) State->FpuRegisters[(State->FpuStatus.Top + (i)) % FAST486_NUM_FPU_REGS]
37 #define FPU_GET_TAG(i) ((State->FpuTag >> ((i) * 2)) & 3)
38 #define FPU_SET_TAG(i, t) { \
39 State->FpuTag &= ~((1 << ((i) * 2)) | (1 << (((i) * 2) + 1))); \
40 State->FpuTag |= ((t) & 3) << ((i) * 2); \
41 }
42
43 #define FPU_REAL4_BIAS 0x7F
44 #define FPU_REAL8_BIAS 0x3FF
45 #define FPU_REAL10_BIAS 0x3FFF
46 #define FPU_MAX_EXPONENT 0x7FFE
47 #define FPU_MANTISSA_HIGH_BIT 0x8000000000000000ULL
48
49 #define FPU_IS_NORMALIZED(x) (!FPU_IS_ZERO(x) && (((x)->Mantissa & FPU_MANTISSA_HIGH_BIT) != 0ULL))
50 #define FPU_IS_ZERO(x) ((x)->Mantissa == 0ULL)
51 #define FPU_IS_NAN(x) ((x)->Exponent == (FPU_MAX_EXPONENT + 1))
52 #define FPU_IS_INFINITY(x) (FPU_IS_NAN(x) && (x)->Mantissa & FPU_MANTISSA_HIGH_BIT)
53 #define FPU_IS_POS_INF(x) (FPU_IS_INFINITY(x) && !(x)->Sign)
54 #define FPU_IS_NEG_INF(x) (FPU_IS_INFINITY(x) && (x)->Sign)
55
56 enum
57 {
58 FPU_SINGLE_PRECISION = 0,
59 FPU_DOUBLE_PRECISION = 2,
60 FPU_DOUBLE_EXT_PRECISION = 3
61 };
62
63 enum
64 {
65 FPU_TAG_VALID = 0,
66 FPU_TAG_ZERO = 1,
67 FPU_TAG_SPECIAL = 2,
68 FPU_TAG_EMPTY = 3
69 };
70
71 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD8DC);
72 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD9);
73 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDA);
74 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDB);
75 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDD);
76 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDE);
77 FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDF);
78
79 #endif // _FPU_H_
80
81 /* EOF */