From: Aleksandar Andrejevic Date: Sat, 11 Oct 2014 15:42:00 +0000 (+0000) Subject: [FAST486] X-Git-Tag: backups/0.3.17@66124~82 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=a6b0b2c9f8a6754c36211227a641ff7bae378893 [FAST486] Use intrinsics to count the leading zeros when possible. Add FPU data to Fast486DumpState. svn path=/trunk/; revision=64674 --- diff --git a/reactos/lib/fast486/common.inl b/reactos/lib/fast486/common.inl index a2186edd7de..a5901f45f84 100644 --- a/reactos/lib/fast486/common.inl +++ b/reactos/lib/fast486/common.inl @@ -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) { diff --git a/reactos/lib/fast486/fast486.c b/reactos/lib/fast486/fast486.c index ccce63bec9a..d56a2e0e851 100644 --- a/reactos/lib/fast486/fast486.c +++ b/reactos/lib/fast486/fast486.c @@ -29,6 +29,7 @@ #include #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"); }