[FAST486]

Use intrinsics to count the leading zeros when possible.
Add FPU data to Fast486DumpState.


svn path=/trunk/; revision=64674
This commit is contained in:
Aleksandar Andrejevic 2014-10-11 15:42:00 +00:00
parent af3b46598e
commit a6b0b2c9f8
2 changed files with 51 additions and 3 deletions

View file

@ -24,6 +24,25 @@
/* PUBLIC FUNCTIONS ***********************************************************/
#if defined (__GNUC__)
#define CountLeadingZeros64(x) __builtin_clzll(x);
#elif (_MSC_VER >= 1500) && defined(_WIN64)
#define CountLeadingZeros64(x) __lzcnt64(x)
#elif (_MSC_VER >= 1500)
#define CountLeadingZeros64(x) ((x) >= 0xFFFFFFFFULL) \
? __lzcnt((x) >> 32) : (__lzcnt(x) + 32)
#else
static
FORCEINLINE
ULONG CountLeadingZeros64(ULONGLONG Value)
{
ULONG LeadingZeros = 0;
while (!(Value & (1 << (63 - LeadingZeros)))) LeadingZeros++;
return LeadingZeros;
}
#endif
FORCEINLINE
INT
Fast486GetCurrentPrivLevel(PFAST486_STATE State)
@ -1290,7 +1309,7 @@ FORCEINLINE
VOID
Fast486FpuNormalize(PFAST486_STATE State, PFAST486_FPU_DATA_REG Data)
{
UINT LeadingZeros = 0;
UINT LeadingZeros;
if (FPU_IS_NORMALIZED(Data)) return;
if (FPU_IS_ZERO(Data))
@ -1299,8 +1318,7 @@ Fast486FpuNormalize(PFAST486_STATE State, PFAST486_FPU_DATA_REG Data)
return;
}
/* Count the leading zeros */
while (!(Data->Mantissa & (1 << (63 - LeadingZeros)))) LeadingZeros++;
LeadingZeros = CountLeadingZeros64(Data->Mantissa);
if (LeadingZeros < Data->Exponent)
{

View file

@ -29,6 +29,7 @@
#include <fast486.h>
#include "common.h"
#include "opcodes.h"
#include "fpu.h"
/* DEFINES ********************************************************************/
@ -369,6 +370,35 @@ Fast486DumpState(PFAST486_STATE State)
State->DebugRegisters[FAST486_REG_DR3],
State->DebugRegisters[FAST486_REG_DR4],
State->DebugRegisters[FAST486_REG_DR5]);
#ifndef FAST486_NO_FPU
DbgPrint("\nFPU Registers:\n"
"ST0 = %04X%016llX\tST1 = %04X%016llX\n"
"ST2 = %04X%016llX\tST3 = %04X%016llX\n"
"ST4 = %04X%016llX\tST5 = %04X%016llX\n"
"ST6 = %04X%016llX\tST7 = %04X%016llX\n"
"Status: %04X\tControl: %04X\tTag: %04X\n",
FPU_ST(0).Exponent | ((USHORT)FPU_ST(0).Sign << 15),
FPU_ST(0).Mantissa,
FPU_ST(1).Exponent | ((USHORT)FPU_ST(1).Sign << 15),
FPU_ST(1).Mantissa,
FPU_ST(2).Exponent | ((USHORT)FPU_ST(2).Sign << 15),
FPU_ST(2).Mantissa,
FPU_ST(3).Exponent | ((USHORT)FPU_ST(3).Sign << 15),
FPU_ST(3).Mantissa,
FPU_ST(4).Exponent | ((USHORT)FPU_ST(4).Sign << 15),
FPU_ST(4).Mantissa,
FPU_ST(5).Exponent | ((USHORT)FPU_ST(5).Sign << 15),
FPU_ST(5).Mantissa,
FPU_ST(6).Exponent | ((USHORT)FPU_ST(6).Sign << 15),
FPU_ST(6).Mantissa,
FPU_ST(7).Exponent | ((USHORT)FPU_ST(7).Sign << 15),
FPU_ST(7).Mantissa,
State->FpuStatus,
State->FpuControl,
State->FpuTag);
#endif
DbgPrint("\n<-- Fast486DumpState\n\n");
}