Author: aandrejevic
Date: Wed Feb 4 02:47:13 2015
New Revision: 66154
URL:
http://svn.reactos.org/svn/reactos?rev=66154&view=rev
Log:
[FAST486]
Implement FCHS, FABS, FTST, FXAM, FLD1, FLDL2T, FLDL2E, FLDPI, FLDLG2, FLDLN2 and FLDZ.
Modified:
trunk/reactos/include/reactos/libs/fast486/fast486.h
trunk/reactos/lib/fast486/common.inl
trunk/reactos/lib/fast486/fpu.c
Modified: trunk/reactos/include/reactos/libs/fast486/fast486.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/fast4…
==============================================================================
--- trunk/reactos/include/reactos/libs/fast486/fast486.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/libs/fast486/fast486.h [iso-8859-1] Wed Feb 4 02:47:13
2015
@@ -428,6 +428,8 @@
USHORT Exponent;
UCHAR Sign;
} FAST486_FPU_DATA_REG, *PFAST486_FPU_DATA_REG;
+
+typedef const FAST486_FPU_DATA_REG *PCFAST486_FPU_DATA_REG;
typedef union _FAST486_FPU_STATUS_REG
{
Modified: trunk/reactos/lib/fast486/common.inl
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fast486/common.inl?rev…
==============================================================================
--- trunk/reactos/lib/fast486/common.inl [iso-8859-1] (original)
+++ trunk/reactos/lib/fast486/common.inl [iso-8859-1] Wed Feb 4 02:47:13 2015
@@ -1578,7 +1578,7 @@
BOOLEAN
FASTCALL
Fast486FpuPush(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG Data)
+ PCFAST486_FPU_DATA_REG Data)
{
State->FpuStatus.Top--;
Modified: trunk/reactos/lib/fast486/fpu.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fast486/fpu.c?rev=6615…
==============================================================================
--- trunk/reactos/lib/fast486/fpu.c [iso-8859-1] (original)
+++ trunk/reactos/lib/fast486/fpu.c [iso-8859-1] Wed Feb 4 02:47:13 2015
@@ -30,6 +30,64 @@
#include "common.h"
#include "fpu.h"
+/* CONSTANTS ******************************************************************/
+
+/* 0.00 */
+static const FAST486_FPU_DATA_REG FpuZero =
+{
+ .Sign = FALSE,
+ .Exponent = 0,
+ .Mantissa = 0ULL
+};
+
+/* 1.00 */
+static const FAST486_FPU_DATA_REG FpuOne =
+{
+ .Sign = FALSE,
+ .Exponent = FPU_REAL10_BIAS,
+ .Mantissa = 0x8000000000000000ULL
+};
+
+/* Pi */
+static const FAST486_FPU_DATA_REG FpuPi =
+{
+ .Sign = FALSE,
+ .Exponent = FPU_REAL10_BIAS + 1,
+ .Mantissa = 0xC90FDAA22168C234ULL
+};
+
+/* lb(10) */
+static const FAST486_FPU_DATA_REG FpuL2Ten =
+{
+ .Sign = FALSE,
+ .Exponent = FPU_REAL10_BIAS + 1,
+ .Mantissa = 0xD49A784BCD1D8AFEULL
+};
+
+/* lb(e) */
+static const FAST486_FPU_DATA_REG FpuL2E =
+{
+ .Sign = FALSE,
+ .Exponent = FPU_REAL10_BIAS,
+ .Mantissa = 0xB8AA3B295C17F0BBULL
+};
+
+/* lg(2) */
+static const FAST486_FPU_DATA_REG FpuLgTwo =
+{
+ .Sign = FALSE,
+ .Exponent = FPU_REAL10_BIAS - 2,
+ .Mantissa = 0x9A209A84FBCFF798ULL
+};
+
+/* ln(2) */
+static const FAST486_FPU_DATA_REG FpuLnTwo =
+{
+ .Sign = FALSE,
+ .Exponent = FPU_REAL10_BIAS - 1,
+ .Mantissa = 0xB17217F7D1CF79ABULL
+};
+
/* PRIVATE FUNCTIONS **********************************************************/
#ifndef FAST486_NO_FPU
@@ -167,7 +225,7 @@
static inline BOOLEAN FASTCALL
Fast486FpuToInteger(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG Value,
+ PCFAST486_FPU_DATA_REG Value,
PLONGLONG Result)
{
ULONG Bits;
@@ -272,7 +330,7 @@
static inline BOOLEAN FASTCALL
Fast486FpuToSingleReal(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG Value,
+ PCFAST486_FPU_DATA_REG Value,
PULONG Result)
{
ULONGLONG Remainder;
@@ -404,7 +462,7 @@
static inline BOOLEAN FASTCALL
Fast486FpuToDoubleReal(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG Value,
+ PCFAST486_FPU_DATA_REG Value,
PULONGLONG Result)
{
ULONGLONG Remainder;
@@ -536,7 +594,7 @@
static inline BOOLEAN FASTCALL
Fast486FpuToPackedBcd(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG Value,
+ PCFAST486_FPU_DATA_REG Value,
PUCHAR Result)
{
INT i;
@@ -562,8 +620,8 @@
static inline VOID FASTCALL
Fast486FpuAdd(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG FirstOperand,
- PFAST486_FPU_DATA_REG SecondOperand,
+ PCFAST486_FPU_DATA_REG FirstOperand,
+ PCFAST486_FPU_DATA_REG SecondOperand,
PFAST486_FPU_DATA_REG Result)
{
FAST486_FPU_DATA_REG FirstAdjusted = *FirstOperand;
@@ -656,8 +714,8 @@
static inline VOID FASTCALL
Fast486FpuSubtract(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG FirstOperand,
- PFAST486_FPU_DATA_REG SecondOperand,
+ PCFAST486_FPU_DATA_REG FirstOperand,
+ PCFAST486_FPU_DATA_REG SecondOperand,
PFAST486_FPU_DATA_REG Result)
{
FAST486_FPU_DATA_REG NegativeSecondOperand = *SecondOperand;
@@ -671,8 +729,8 @@
static inline VOID FASTCALL
Fast486FpuCompare(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG FirstOperand,
- PFAST486_FPU_DATA_REG SecondOperand)
+ PCFAST486_FPU_DATA_REG FirstOperand,
+ PCFAST486_FPU_DATA_REG SecondOperand)
{
if (FPU_IS_NAN(FirstOperand) || FPU_IS_NAN(SecondOperand))
{
@@ -724,8 +782,8 @@
static inline VOID FASTCALL
Fast486FpuMultiply(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG FirstOperand,
- PFAST486_FPU_DATA_REG SecondOperand,
+ PCFAST486_FPU_DATA_REG FirstOperand,
+ PCFAST486_FPU_DATA_REG SecondOperand,
PFAST486_FPU_DATA_REG Result)
{
FAST486_FPU_DATA_REG TempResult;
@@ -756,8 +814,8 @@
static inline VOID FASTCALL
Fast486FpuDivide(PFAST486_STATE State,
- PFAST486_FPU_DATA_REG FirstOperand,
- PFAST486_FPU_DATA_REG SecondOperand,
+ PCFAST486_FPU_DATA_REG FirstOperand,
+ PCFAST486_FPU_DATA_REG SecondOperand,
PFAST486_FPU_DATA_REG Result)
{
FAST486_FPU_DATA_REG TempResult;
@@ -1309,8 +1367,16 @@
/* FCHS */
case 0x20:
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
+ if (FPU_GET_TAG(0) == FPU_TAG_EMPTY)
+ {
+ State->FpuStatus.Ie = TRUE;
+
+ if (!State->FpuControl.Im) Fast486FpuException(State);
+ break;
+ }
+
+ /* Invert the sign */
+ FPU_ST(0).Sign = !FPU_ST(0).Sign;
break;
}
@@ -1318,8 +1384,16 @@
/* FABS */
case 0x21:
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
+ if (FPU_GET_TAG(0) == FPU_TAG_EMPTY)
+ {
+ State->FpuStatus.Ie = TRUE;
+
+ if (!State->FpuControl.Im) Fast486FpuException(State);
+ break;
+ }
+
+ /* Set the sign to positive */
+ FPU_ST(0).Sign = FALSE;
break;
}
@@ -1327,26 +1401,58 @@
/* FTST */
case 0x24:
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
+ Fast486FpuCompare(State, &FPU_ST(0), &FpuZero);
break;
}
/* FXAM */
case 0x25:
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- break;
- }
-
- /* FTSTP */
- case 0x26:
- {
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
+ /* The sign bit goes in C1, even if the register's empty */
+ State->FpuStatus.Code1 = FPU_ST(0).Sign;
+
+ if (FPU_GET_TAG(0) == FPU_TAG_EMPTY)
+ {
+ State->FpuStatus.Code0 = 1;
+ State->FpuStatus.Code2 = 0;
+ State->FpuStatus.Code3 = 1;
+ }
+ else if (FPU_GET_TAG(0) == FPU_TAG_SPECIAL)
+ {
+ if (FPU_IS_INFINITY(&FPU_ST(0)))
+ {
+ State->FpuStatus.Code0 = 1;
+ State->FpuStatus.Code2 = 1;
+ State->FpuStatus.Code3 = 0;
+ }
+ else
+ {
+ State->FpuStatus.Code0 = 1;
+ State->FpuStatus.Code2 = 0;
+ State->FpuStatus.Code3 = 0;
+ }
+ }
+ else if (FPU_GET_TAG(0) == FPU_TAG_ZERO)
+ {
+ State->FpuStatus.Code0 = 0;
+ State->FpuStatus.Code2 = 0;
+ State->FpuStatus.Code3 = 1;
+ }
+ else
+ {
+ if (FPU_IS_NORMALIZED(&FPU_ST(0)))
+ {
+ State->FpuStatus.Code0 = 0;
+ State->FpuStatus.Code2 = 1;
+ State->FpuStatus.Code3 = 0;
+ }
+ else
+ {
+ State->FpuStatus.Code0 = 0;
+ State->FpuStatus.Code2 = 1;
+ State->FpuStatus.Code3 = 1;
+ }
+ }
break;
}
@@ -1366,9 +1472,18 @@
/* FLDZ */
case 0x2E:
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
+ PCFAST486_FPU_DATA_REG Constants[] =
+ {
+ &FpuOne,
+ &FpuL2Ten,
+ &FpuL2E,
+ &FpuPi,
+ &FpuLgTwo,
+ &FpuLnTwo,
+ &FpuZero
+ };
+
+ Fast486FpuPush(State, Constants[ModRegRm.SecondRegister]);
break;
}