summaryrefslogtreecommitdiff
path: root/src/pal/inc/pal.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/inc/pal.h')
-rw-r--r--src/pal/inc/pal.h38
1 files changed, 15 insertions, 23 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index f117a6eb9c..690804013e 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -3254,10 +3254,10 @@ typedef EXCEPTION_DISPOSITION (PALAPI *PVECTORED_EXCEPTION_HANDLER)(
// Define BitScanForward64 and BitScanForward
// Per MSDN, BitScanForward64 will search the mask data from LSB to MSB for a set bit.
-// If one is found, its bit position is returned in the out PDWORD argument and 1 is returned.
-// Otherwise, 0 is returned.
+// If one is found, its bit position is stored in the out PDWORD argument and 1 is returned;
+// otherwise, an undefined value is stored in the out PDWORD argument and 0 is returned.
//
-// On GCC, the equivalent function is __builtin_ffsl. It returns 1+index of the least
+// On GCC, the equivalent function is __builtin_ffsll. It returns 1+index of the least
// significant set bit, or 0 if if mask is zero.
//
// The same is true for BitScanForward, except that the GCC function is __builtin_ffs.
@@ -3270,16 +3270,12 @@ BitScanForward(
IN OUT PDWORD Index,
IN UINT qwMask)
{
- unsigned char bRet = FALSE;
- int iIndex = __builtin_ffsl(qwMask);
- if (iIndex != 0)
- {
- // Set the Index after deducting unity
- *Index = (DWORD)(iIndex - 1);
- bRet = TRUE;
- }
-
- return bRet;
+ int iIndex = __builtin_ffs(qwMask);
+ // Set the Index after deducting unity
+ *Index = (DWORD)(iIndex - 1);
+ // Both GCC and Clang generate better, smaller code if we check whether the
+ // mask was/is zero rather than the equivalent check that iIndex is zero.
+ return qwMask != 0 ? TRUE : FALSE;
}
EXTERN_C
@@ -3291,16 +3287,12 @@ BitScanForward64(
IN OUT PDWORD Index,
IN UINT64 qwMask)
{
- unsigned char bRet = FALSE;
- int iIndex = __builtin_ffsl(qwMask);
- if (iIndex != 0)
- {
- // Set the Index after deducting unity
- *Index = (DWORD)(iIndex - 1);
- bRet = TRUE;
- }
-
- return bRet;
+ int iIndex = __builtin_ffsll(qwMask);
+ // Set the Index after deducting unity
+ *Index = (DWORD)(iIndex - 1);
+ // Both GCC and Clang generate better, smaller code if we check whether the
+ // mask was/is zero rather than the equivalent check that iIndex is zero.
+ return qwMask != 0 ? TRUE : FALSE;
}
FORCEINLINE void PAL_ArmInterlockedOperationBarrier()