]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/BitField.c
Minor grammatical work--mostly adding periods. Items with ONLY period added did...
[mirror_edk2.git] / MdePkg / Library / BaseLib / BitField.c
index 372ba12355b82cc5de3ffc6d28b0ab707cfcab05..2b9fa66295c317ce4520045726630227a7f84838 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Bit field functions of BaseLib.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  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
   http://opensource.org/licenses/bsd-license.php\r
 \r
 **/\r
 \r
-//\r
-// Include common header file for this module.\r
-//\r
-\r
-\r
 #include "BaseLibInternals.h"\r
 \r
 /**\r
-  Worker function that returns a bit field from Operand\r
+  Worker function that returns a bit field from Operand.\r
 \r
   Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
 \r
   @return The bit field read.\r
 \r
 **/\r
-unsigned int\r
-BitFieldReadUint (\r
-  IN      unsigned int              Operand,\r
+UINTN\r
+EFIAPI\r
+InternalBaseLibBitFieldReadUint (\r
+  IN      UINTN                     Operand,\r
   IN      UINTN                     StartBit,\r
   IN      UINTN                     EndBit\r
   )\r
 {\r
   //\r
-  // ~((unsigned int)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r
+  // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r
   // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.\r
   //\r
-  return (Operand & ~((unsigned int)-2 << EndBit)) >> StartBit;\r
+  return (Operand & ~((UINTN)-2 << EndBit)) >> StartBit;\r
 }\r
 \r
 /**\r
-  Worker function that reads a bit field from Operand, performs a bitwise OR, \r
+  Worker function that reads a bit field from Operand, performs a bitwise OR,\r
   and returns the result.\r
 \r
   Performs a bitwise OR between the bit field specified by StartBit and EndBit\r
@@ -61,23 +57,24 @@ BitFieldReadUint (
   @return The new value.\r
 \r
 **/\r
-unsigned int\r
-BitFieldOrUint (\r
-  IN      unsigned int              Operand,\r
+UINTN\r
+EFIAPI\r
+InternalBaseLibBitFieldOrUint (\r
+  IN      UINTN                     Operand,\r
   IN      UINTN                     StartBit,\r
   IN      UINTN                     EndBit,\r
-  IN      unsigned int              OrData\r
+  IN      UINTN                     OrData\r
   )\r
 {\r
   //\r
-  // ~((unsigned int)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r
+  // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r
   // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.\r
   //\r
-  return Operand | ((OrData << StartBit) & ~((unsigned int) -2 << EndBit));\r
+  return Operand | ((OrData << StartBit) & ~((UINTN) -2 << EndBit));\r
 }\r
 \r
 /**\r
-  Worker function that reads a bit field from Operand, performs a bitwise AND, \r
+  Worker function that reads a bit field from Operand, performs a bitwise AND,\r
   and returns the result.\r
 \r
   Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
@@ -92,19 +89,20 @@ BitFieldOrUint (
   @return The new value.\r
 \r
 **/\r
-unsigned int\r
-BitFieldAndUint (\r
-  IN      unsigned int              Operand,\r
+UINTN\r
+EFIAPI\r
+InternalBaseLibBitFieldAndUint (\r
+  IN      UINTN                     Operand,\r
   IN      UINTN                     StartBit,\r
   IN      UINTN                     EndBit,\r
-  IN      unsigned int              AndData\r
+  IN      UINTN                     AndData\r
   )\r
 {\r
   //\r
-  // ~((unsigned int)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r
+  // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r
   // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.\r
   //\r
-  return Operand & ~((~AndData << StartBit) & ~((unsigned int) -2 << EndBit));\r
+  return Operand & ~((~AndData << StartBit) & ~((UINTN)-2 << EndBit));\r
 }\r
 \r
 /**\r
@@ -134,9 +132,9 @@ BitFieldRead8 (
   IN      UINTN                     EndBit\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 8);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT8)BitFieldReadUint (Operand, StartBit, EndBit);\r
+  return (UINT8)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);\r
 }\r
 \r
 /**\r
@@ -170,7 +168,7 @@ BitFieldWrite8 (
   IN      UINT8                     Value\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 8);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldAndThenOr8 (Operand, StartBit, EndBit, 0, Value);\r
 }\r
@@ -179,7 +177,7 @@ BitFieldWrite8 (
   Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the\r
   result.\r
 \r
-  Performs a bitwise inclusive OR between the bit field specified by StartBit\r
+  Performs a bitwise OR between the bit field specified by StartBit\r
   and EndBit in Operand and the value specified by OrData. All other bits in\r
   Operand are preserved. The new 8-bit value is returned.\r
 \r
@@ -207,9 +205,9 @@ BitFieldOr8 (
   IN      UINT8                     OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 8);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT8)BitFieldOrUint (Operand, StartBit, EndBit, OrData);\r
+  return (UINT8)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);\r
 }\r
 \r
 /**\r
@@ -244,9 +242,9 @@ BitFieldAnd8 (
   IN      UINT8                     AndData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 8);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT8)BitFieldAndUint (Operand, StartBit, EndBit, AndData);\r
+  return (UINT8)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);\r
 }\r
 \r
 /**\r
@@ -254,8 +252,8 @@ BitFieldAnd8 (
   bitwise OR, and returns the result.\r
 \r
   Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
-  in Operand and the value specified by AndData, followed by a bitwise\r
-  inclusive OR with value specified by OrData. All other bits in Operand are\r
+  in Operand and the value specified by AndData, followed by a bitwise \r
+  OR with value specified by OrData. All other bits in Operand are\r
   preserved. The new 8-bit value is returned.\r
 \r
   If 8-bit operations are not supported, then ASSERT().\r
@@ -284,7 +282,7 @@ BitFieldAndThenOr8 (
   IN      UINT8                     OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 8);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldOr8 (\r
            BitFieldAnd8 (Operand, StartBit, EndBit, AndData),\r
@@ -321,9 +319,9 @@ BitFieldRead16 (
   IN      UINTN                     EndBit\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 16);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT16)BitFieldReadUint (Operand, StartBit, EndBit);\r
+  return (UINT16)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);\r
 }\r
 \r
 /**\r
@@ -357,7 +355,7 @@ BitFieldWrite16 (
   IN      UINT16                    Value\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 16);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldAndThenOr16 (Operand, StartBit, EndBit, 0, Value);\r
 }\r
@@ -366,7 +364,7 @@ BitFieldWrite16 (
   Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the\r
   result.\r
 \r
-  Performs a bitwise inclusive OR between the bit field specified by StartBit\r
+  Performs a bitwise OR between the bit field specified by StartBit\r
   and EndBit in Operand and the value specified by OrData. All other bits in\r
   Operand are preserved. The new 16-bit value is returned.\r
 \r
@@ -394,9 +392,9 @@ BitFieldOr16 (
   IN      UINT16                    OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 16);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT16)BitFieldOrUint (Operand, StartBit, EndBit, OrData);\r
+  return (UINT16)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);\r
 }\r
 \r
 /**\r
@@ -431,9 +429,9 @@ BitFieldAnd16 (
   IN      UINT16                    AndData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 16);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT16)BitFieldAndUint (Operand, StartBit, EndBit, AndData);\r
+  return (UINT16)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);\r
 }\r
 \r
 /**\r
@@ -441,8 +439,8 @@ BitFieldAnd16 (
   bitwise OR, and returns the result.\r
 \r
   Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
-  in Operand and the value specified by AndData, followed by a bitwise\r
-  inclusive OR with value specified by OrData. All other bits in Operand are\r
+  in Operand and the value specified by AndData, followed by a bitwise \r
+  OR with value specified by OrData. All other bits in Operand are\r
   preserved. The new 16-bit value is returned.\r
 \r
   If 16-bit operations are not supported, then ASSERT().\r
@@ -471,7 +469,7 @@ BitFieldAndThenOr16 (
   IN      UINT16                    OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 16);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldOr16 (\r
            BitFieldAnd16 (Operand, StartBit, EndBit, AndData),\r
@@ -508,9 +506,9 @@ BitFieldRead32 (
   IN      UINTN                     EndBit\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 32);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT32)BitFieldReadUint (Operand, StartBit, EndBit);\r
+  return (UINT32)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);\r
 }\r
 \r
 /**\r
@@ -544,7 +542,7 @@ BitFieldWrite32 (
   IN      UINT32                    Value\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 32);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldAndThenOr32 (Operand, StartBit, EndBit, 0, Value);\r
 }\r
@@ -553,7 +551,7 @@ BitFieldWrite32 (
   Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the\r
   result.\r
 \r
-  Performs a bitwise inclusive OR between the bit field specified by StartBit\r
+  Performs a bitwise OR between the bit field specified by StartBit\r
   and EndBit in Operand and the value specified by OrData. All other bits in\r
   Operand are preserved. The new 32-bit value is returned.\r
 \r
@@ -581,9 +579,9 @@ BitFieldOr32 (
   IN      UINT32                    OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 32);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT32)BitFieldOrUint (Operand, StartBit, EndBit, OrData);\r
+  return (UINT32)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);\r
 }\r
 \r
 /**\r
@@ -618,9 +616,9 @@ BitFieldAnd32 (
   IN      UINT32                    AndData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 32);\r
   ASSERT (StartBit <= EndBit);\r
-  return (UINT32)BitFieldAndUint (Operand, StartBit, EndBit, AndData);\r
+  return (UINT32)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);\r
 }\r
 \r
 /**\r
@@ -628,8 +626,8 @@ BitFieldAnd32 (
   bitwise OR, and returns the result.\r
 \r
   Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
-  in Operand and the value specified by AndData, followed by a bitwise\r
-  inclusive OR with value specified by OrData. All other bits in Operand are\r
+  in Operand and the value specified by AndData, followed by a bitwise \r
+  OR with value specified by OrData. All other bits in Operand are\r
   preserved. The new 32-bit value is returned.\r
 \r
   If 32-bit operations are not supported, then ASSERT().\r
@@ -658,7 +656,7 @@ BitFieldAndThenOr32 (
   IN      UINT32                    OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 32);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldOr32 (\r
            BitFieldAnd32 (Operand, StartBit, EndBit, AndData),\r
@@ -695,7 +693,7 @@ BitFieldRead64 (
   IN      UINTN                     EndBit\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
   return RShiftU64 (Operand & ~LShiftU64 ((UINT64)-2, EndBit), StartBit);\r
 }\r
@@ -731,7 +729,7 @@ BitFieldWrite64 (
   IN      UINT64                    Value\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldAndThenOr64 (Operand, StartBit, EndBit, 0, Value);\r
 }\r
@@ -740,7 +738,7 @@ BitFieldWrite64 (
   Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the\r
   result.\r
 \r
-  Performs a bitwise inclusive OR between the bit field specified by StartBit\r
+  Performs a bitwise OR between the bit field specified by StartBit\r
   and EndBit in Operand and the value specified by OrData. All other bits in\r
   Operand are preserved. The new 64-bit value is returned.\r
 \r
@@ -771,7 +769,7 @@ BitFieldOr64 (
   UINT64  Value1;\r
   UINT64  Value2;\r
 \r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
 \r
   Value1 = LShiftU64 (OrData, StartBit);\r
@@ -815,7 +813,7 @@ BitFieldAnd64 (
   UINT64  Value1;\r
   UINT64  Value2;\r
   \r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
 \r
   Value1 = LShiftU64 (~AndData, StartBit);\r
@@ -829,8 +827,8 @@ BitFieldAnd64 (
   bitwise OR, and returns the result.\r
 \r
   Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
-  in Operand and the value specified by AndData, followed by a bitwise\r
-  inclusive OR with value specified by OrData. All other bits in Operand are\r
+  in Operand and the value specified by AndData, followed by a bitwise \r
+  OR with value specified by OrData. All other bits in Operand are\r
   preserved. The new 64-bit value is returned.\r
 \r
   If 64-bit operations are not supported, then ASSERT().\r
@@ -859,7 +857,7 @@ BitFieldAndThenOr64 (
   IN      UINT64                    OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
   return BitFieldOr64 (\r
            BitFieldAnd64 (Operand, StartBit, EndBit, AndData),\r