/* 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 Count = 0;
+ ULONGLONG Mask = 1ULL << 63;
+
+ while (!(Value & Mask))
+ {
+ Count++;
+ Mask >>= 1;
+ }
+
+ return Count;
+ }
+#endif
+
FORCEINLINE
INT
Fast486GetCurrentPrivLevel(PFAST486_STATE State)
return TRUE;
}
-FORCEINLINE
-BOOLEAN
-Fast486GetIntVector(PFAST486_STATE State,
- UCHAR Number,
- PFAST486_IDT_ENTRY IdtEntry)
-{
- ULONG FarPointer;
-
- /* Check for protected mode */
- if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE)
- {
- /* Read from the IDT */
- if (!Fast486ReadLinearMemory(State,
- State->Idtr.Address
- + Number * sizeof(*IdtEntry),
- IdtEntry,
- sizeof(*IdtEntry)))
- {
- /* Exception occurred */
- return FALSE;
- }
- }
- else
- {
- /* Read from the real-mode IVT */
-
- /* Paging is always disabled in real mode */
- State->MemReadCallback(State,
- State->Idtr.Address
- + Number * sizeof(FarPointer),
- &FarPointer,
- sizeof(FarPointer));
-
- /* Fill a fake IDT entry */
- IdtEntry->Offset = LOWORD(FarPointer);
- IdtEntry->Selector = HIWORD(FarPointer);
- IdtEntry->Zero = 0;
- IdtEntry->Type = FAST486_IDT_INT_GATE;
- IdtEntry->Storage = FALSE;
- IdtEntry->Dpl = 0;
- IdtEntry->Present = TRUE;
- IdtEntry->OffsetHigh = 0;
- }
-
- return TRUE;
-}
-
FORCEINLINE
BOOLEAN
Fast486CalculateParity(UCHAR Number)
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))
return;
}
- /* Count the leading zeros */
- while (!(Data->Mantissa & (1 << (63 - LeadingZeros)))) LeadingZeros++;
+ LeadingZeros = CountLeadingZeros64(Data->Mantissa);
if (LeadingZeros < Data->Exponent)
{