diff options
author | bxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-07-13 08:05:35 +0000 |
---|---|---|
committer | bxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-07-13 08:05:35 +0000 |
commit | 3cc092acf2aa8b76815a1adca2cc3775dd9f7753 (patch) | |
tree | dee4ab5b49b7a89102a9d948e84d51004ceab1ed /MdePkg/Library | |
parent | 0898f771628c4c9004d5e2716612c57b13123a93 (diff) | |
download | edk2-platforms-3cc092acf2aa8b76815a1adca2cc3775dd9f7753.tar.xz |
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
Diffstat (limited to 'MdePkg/Library')
-rw-r--r-- | MdePkg/Library/BaseLib/GetPowerOfTwo32.c | 9 | ||||
-rw-r--r-- | MdePkg/Library/BaseLib/GetPowerOfTwo64.c | 7 |
2 files changed, 9 insertions, 7 deletions
diff --git a/MdePkg/Library/BaseLib/GetPowerOfTwo32.c b/MdePkg/Library/BaseLib/GetPowerOfTwo32.c index dbf4ca6513..a639fd4a6d 100644 --- a/MdePkg/Library/BaseLib/GetPowerOfTwo32.c +++ b/MdePkg/Library/BaseLib/GetPowerOfTwo32.c @@ -33,8 +33,9 @@ GetPowerOfTwo32 ( IN UINT32 Operand
)
{
- INTN BitPos;
-
- BitPos = HighBitSet32 (Operand);
- return BitPos >= 0 ? 1ul << BitPos : 0;
+ if (Operand == 0) {
+ return 0;
+ }
+
+ return 1ul << HighBitSet32 (Operand);
}
diff --git a/MdePkg/Library/BaseLib/GetPowerOfTwo64.c b/MdePkg/Library/BaseLib/GetPowerOfTwo64.c index 8372a7f136..52d148c924 100644 --- a/MdePkg/Library/BaseLib/GetPowerOfTwo64.c +++ b/MdePkg/Library/BaseLib/GetPowerOfTwo64.c @@ -33,8 +33,9 @@ GetPowerOfTwo64 ( IN UINT64 Operand
)
{
- INTN BitPos;
+ if (Operand == 0) {
+ return 0;
+ }
- BitPos = HighBitSet64 (Operand);
- return BitPos >= 0 ? LShiftU64 (1, BitPos) : 0;
+ return LShiftU64 (1, HighBitSet64 (Operand));
}
|