]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/HighBitSet64.c
Synchronize function comment in MdePkg\Library\BaseLib.h with the instance of this...
[mirror_edk2.git] / MdePkg / Library / BaseLib / HighBitSet64.c
index 50889777b5420b1878f8c72bc007b79ec6965290..621284c2a45781d979e0eab8116fa6a406c53e13 100644 (file)
@@ -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