]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/HighBitSet64.c
Update copyright for files modified in this year
[mirror_edk2.git] / MdePkg / Library / BaseLib / HighBitSet64.c
index 50889777b5420b1878f8c72bc007b79ec6965290..28772df2024e240548105f8763547a69cf505496 100644 (file)
@@ -1,7 +1,7 @@
 /** @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
@@ -12,6 +12,9 @@
 \r
 **/\r
 \r
+\r
+\r
+\r
 #include "BaseLibInternals.h"\r
 \r
 /**\r
@@ -24,8 +27,8 @@
 \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
@@ -34,10 +37,19 @@ HighBitSet64 (
   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