/** @file\r
Math worker functions.\r
\r
- Copyright (c) 2006, Intel Corporation<BR>\r
+ Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
**/\r
\r
+\r
+\r
+\r
#include "BaseLibInternals.h"\r
\r
/**\r
\r
@param Operand The 64-bit operand to evaluate.\r
\r
- @return Position of the highest bit set in Operand if found.\r
- @retval -1 Operand is zero.\r
+ @retval 0..63 Position of the highest bit set in Operand if found.\r
+ @retval -1 Operand is zero.\r
\r
**/\r
INTN\r
IN UINT64 Operand\r
)\r
{\r
- INTN BitIndex;\r
-\r
- for (BitIndex = -1;\r
- Operand != 0;\r
- BitIndex++, Operand = RShiftU64 (Operand, 1));\r
- return BitIndex;\r
+ if (Operand == (UINT32)Operand) {\r
+ //\r
+ // Operand is just a 32-bit integer\r
+ //\r
+ return HighBitSet32 ((UINT32)Operand);\r
+ }\r
+\r
+ //\r
+ // Operand is really a 64-bit integer\r
+ //\r
+ if (sizeof (UINTN) == sizeof (UINT32)) {\r
+ return HighBitSet32 (((UINT32*)&Operand)[1]) + 32;\r
+ } else {\r
+ return HighBitSet32 ((UINT32)RShiftU64 (Operand, 32)) + 32;\r
+ }\r
}\r