Add BSF and BSR instruction wrappers
All checks were successful
Builds / ExectOS (amd64, debug) (push) Successful in 55s
Builds / ExectOS (amd64, release) (push) Successful in 52s
Builds / ExectOS (i686, debug) (push) Successful in 42s
Builds / ExectOS (i686, release) (push) Successful in 40s

This commit is contained in:
2026-06-01 00:36:52 +02:00
parent 7d8b33390a
commit 0aabc206a1
4 changed files with 108 additions and 0 deletions

View File

@@ -617,6 +617,56 @@ AR::CpuFunctions::ReadWriteBarrier(VOID)
: "memory"); : "memory");
} }
/**
* Performs a Bit Scan Forward instruction to locate the most significant set bit.
*
* @param Index
* Receives the zero-based index of the highest set bit when one is found.
*
* @param Mask
* Supplies the bitmap to scan.
*
* @return This routine returns TRUE when a set bit was found, otherwise FALSE.
*
* @since XT 1.0
*/
XTCDECL
BOOLEAN
AR::CpuFunctions::ScanForwardBit(OUT PULONG Index,
IN ULONG Mask)
{
/* Defer to the BSF instruction */
__asm__("bsfl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask));
/* Report whether the input had any bit set */
return Mask ? TRUE : FALSE;
}
/**
* Performs a Bit Scan Reverse instruction to locate the most significant set bit.
*
* @param Index
* Receives the zero-based index of the highest set bit when one is found.
*
* @param Mask
* Supplies the bitmap to scan.
*
* @return This routine returns TRUE when a set bit was found, otherwise FALSE.
*
* @since XT 1.0
*/
XTCDECL
BOOLEAN
AR::CpuFunctions::ScanReverseBit(OUT PULONG Index,
IN ULONG Mask)
{
/* Defer to the BSR instruction */
__asm__("bsrl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask));
/* Report whether the input had any bit set */
return Mask ? TRUE : FALSE;
}
/** /**
* Instructs the processor to set the interrupt flag. * Instructs the processor to set the interrupt flag.
* *

View File

@@ -587,6 +587,56 @@ AR::CpuFunctions::ReadWriteBarrier(VOID)
: "memory"); : "memory");
} }
/**
* Performs a Bit Scan Forward instruction to locate the most significant set bit.
*
* @param Index
* Receives the zero-based index of the highest set bit when one is found.
*
* @param Mask
* Supplies the bitmap to scan.
*
* @return This routine returns TRUE when a set bit was found, otherwise FALSE.
*
* @since XT 1.0
*/
XTCDECL
BOOLEAN
AR::CpuFunctions::ScanForwardBit(OUT PULONG Index,
IN ULONG Mask)
{
/* Defer to the BSF instruction */
__asm__("bsfl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask));
/* Report whether the input had any bit set */
return Mask ? TRUE : FALSE;
}
/**
* Performs a Bit Scan Reverse instruction to locate the most significant set bit.
*
* @param Index
* Receives the zero-based index of the highest set bit when one is found.
*
* @param Mask
* Supplies the bitmap to scan.
*
* @return This routine returns TRUE when a set bit was found, otherwise FALSE.
*
* @since XT 1.0
*/
XTCDECL
BOOLEAN
AR::CpuFunctions::ScanReverseBit(OUT PULONG Index,
IN ULONG Mask)
{
/* Defer to the BSR instruction */
__asm__("bsrl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask));
/* Report whether the input had any bit set */
return Mask ? TRUE : FALSE;
}
/** /**
* Instructs the processor to set the interrupt flag. * Instructs the processor to set the interrupt flag.
* *

View File

@@ -42,6 +42,10 @@ namespace AR
STATIC XTCDECL ULONGLONG ReadTimeStampCounter(VOID); STATIC XTCDECL ULONGLONG ReadTimeStampCounter(VOID);
STATIC XTCDECL ULONGLONG ReadTimeStampCounterProcessor(OUT PULONG TscAux); STATIC XTCDECL ULONGLONG ReadTimeStampCounterProcessor(OUT PULONG TscAux);
STATIC XTCDECL VOID ReadWriteBarrier(VOID); STATIC XTCDECL VOID ReadWriteBarrier(VOID);
STATIC XTCDECL BOOLEAN ScanForwardBit(OUT PULONG Index,
IN ULONG Mask);
STATIC XTCDECL BOOLEAN ScanReverseBit(OUT PULONG Index,
IN ULONG Mask);
STATIC XTCDECL VOID SetInterruptFlag(VOID); STATIC XTCDECL VOID SetInterruptFlag(VOID);
STATIC XTCDECL VOID StoreGlobalDescriptorTable(OUT PVOID Destination); STATIC XTCDECL VOID StoreGlobalDescriptorTable(OUT PVOID Destination);
STATIC XTCDECL VOID StoreInterruptDescriptorTable(OUT PVOID Destination); STATIC XTCDECL VOID StoreInterruptDescriptorTable(OUT PVOID Destination);

View File

@@ -41,6 +41,10 @@ namespace AR
STATIC XTCDECL ULONGLONG ReadTimeStampCounter(VOID); STATIC XTCDECL ULONGLONG ReadTimeStampCounter(VOID);
STATIC XTCDECL ULONGLONG ReadTimeStampCounterProcessor(OUT PULONG TscAux); STATIC XTCDECL ULONGLONG ReadTimeStampCounterProcessor(OUT PULONG TscAux);
STATIC XTCDECL VOID ReadWriteBarrier(VOID); STATIC XTCDECL VOID ReadWriteBarrier(VOID);
STATIC XTCDECL BOOLEAN ScanForwardBit(OUT PULONG Index,
IN ULONG Mask);
STATIC XTCDECL BOOLEAN ScanReverseBit(OUT PULONG Index,
IN ULONG Mask);
STATIC XTCDECL VOID SetInterruptFlag(VOID); STATIC XTCDECL VOID SetInterruptFlag(VOID);
STATIC XTCDECL VOID StoreGlobalDescriptorTable(OUT PVOID Destination); STATIC XTCDECL VOID StoreGlobalDescriptorTable(OUT PVOID Destination);
STATIC XTCDECL VOID StoreInterruptDescriptorTable(OUT PVOID Destination); STATIC XTCDECL VOID StoreInterruptDescriptorTable(OUT PVOID Destination);