Revised GetPowerOfTwo32() and GetPowerOfTwo64() to be more efficient.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@963 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
bxing 2006-07-13 08:05:35 +00:00
parent 0898f77162
commit 3cc092acf2
2 changed files with 9 additions and 7 deletions

View File

@ -33,8 +33,9 @@ GetPowerOfTwo32 (
IN UINT32 Operand IN UINT32 Operand
) )
{ {
INTN BitPos; if (Operand == 0) {
return 0;
}
BitPos = HighBitSet32 (Operand); return 1ul << HighBitSet32 (Operand);
return BitPos >= 0 ? 1ul << BitPos : 0;
} }

View File

@ -33,8 +33,9 @@ GetPowerOfTwo64 (
IN UINT64 Operand IN UINT64 Operand
) )
{ {
INTN BitPos; if (Operand == 0) {
return 0;
}
BitPos = HighBitSet64 (Operand); return LShiftU64 (1, HighBitSet64 (Operand));
return BitPos >= 0 ? LShiftU64 (1, BitPos) : 0;
} }