]> 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 ad953396ac369794693c68819bc55630f393f0f0..d17e5624072a0880915823c17461f6ae8eeb35c9 100644 (file)
 /** @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 - 2010, 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
+  http://opensource.org/licenses/bsd-license.php.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  BitField.c\r
-\r
 **/\r
 \r
-unsigned int\r
+#include "BaseLibInternals.h"\r
+\r
+/**\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
+  @param  Operand   Operand on which to perform the bitfield operation.\r
+  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
+  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
+\r
+  @return The bit field read.\r
+\r
+**/\r
+UINTN\r
 EFIAPI\r
-BitFieldReadUint (\r
-  IN      unsigned int              Operand,\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
-unsigned int\r
+/**\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
+  in Operand and the value specified by AndData. All other bits in Operand are\r
+  preserved. The new value is returned.\r
+\r
+  @param  Operand   Operand on which to perform the bitfield operation.\r
+  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
+  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
+  @param  OrData    The value to OR with the read value from the value.\r
+\r
+  @return The new value.\r
+\r
+**/\r
+UINTN\r
 EFIAPI\r
-BitFieldOrUint (\r
-  IN      unsigned int              Operand,\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
-unsigned int\r
+/**\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
+  in Operand and the value specified by AndData. All other bits in Operand are\r
+  preserved. The new value is returned.\r
+\r
+  @param  Operand   Operand on which to perform the bitfield operation.\r
+  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
+  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
+  @param  AndData    The value to And with the read value from the value.\r
+\r
+  @return The new value.\r
+\r
+**/\r
+UINTN\r
 EFIAPI\r
-BitFieldAndUint (\r
-  IN      unsigned int              Operand,\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
@@ -69,7 +113,7 @@ BitFieldAndUint (
   If 8-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -88,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
@@ -103,14 +147,14 @@ BitFieldRead8 (
   If 8-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..7.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The new 8-bit value.\r
 \r
@@ -124,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
@@ -133,21 +177,21 @@ 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
   If 8-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..7.\r
-  @param  OrData    The value to OR with the read value from the value\r
+  @param  OrData    The value to OR with the read value from the value.\r
 \r
   @return The new 8-bit value.\r
 \r
@@ -161,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
@@ -177,7 +221,7 @@ BitFieldOr8 (
   If 8-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -198,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
@@ -208,14 +252,14 @@ 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
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -238,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
@@ -256,7 +300,7 @@ BitFieldAndThenOr8 (
   If 16-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -275,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
@@ -290,14 +334,14 @@ BitFieldRead16 (
   If 16-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..15.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The new 16-bit value.\r
 \r
@@ -311,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
@@ -320,21 +364,21 @@ 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
   If 16-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..15.\r
-  @param  OrData    The value to OR with the read value from the value\r
+  @param  OrData    The value to OR with the read value from the value.\r
 \r
   @return The new 16-bit value.\r
 \r
@@ -348,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
@@ -364,14 +408,14 @@ BitFieldOr16 (
   If 16-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..15.\r
-  @param  AndData   The value to AND with the read value from the value\r
+  @param  AndData   The value to AND with the read value from the value.\r
 \r
   @return The new 16-bit value.\r
 \r
@@ -385,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
@@ -395,14 +439,14 @@ 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
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -425,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
@@ -443,7 +487,7 @@ BitFieldAndThenOr16 (
   If 32-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -462,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
@@ -477,14 +521,14 @@ BitFieldRead32 (
   If 32-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The new 32-bit value.\r
 \r
@@ -498,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
@@ -507,21 +551,21 @@ 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
   If 32-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
-  @param  OrData    The value to OR with the read value from the value\r
+  @param  OrData    The value to OR with the read value from the value.\r
 \r
   @return The new 32-bit value.\r
 \r
@@ -535,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
@@ -551,14 +595,14 @@ BitFieldOr32 (
   If 32-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
-  @param  AndData   The value to AND with the read value from the value\r
+  @param  AndData   The value to AND with the read value from the value.\r
 \r
   @return The new 32-bit value.\r
 \r
@@ -572,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
@@ -582,14 +626,14 @@ 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
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -612,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
@@ -630,7 +674,7 @@ BitFieldAndThenOr32 (
   If 64-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -649,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
@@ -664,14 +708,14 @@ BitFieldRead64 (
   If 64-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..63.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..63.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The new 64-bit value.\r
 \r
@@ -685,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
@@ -694,14 +738,14 @@ 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
   If 64-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -722,10 +766,16 @@ BitFieldOr64 (
   IN      UINT64                    OrData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  UINT64  Value1;\r
+  UINT64  Value2;\r
+\r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
-  return Operand |\r
-         (LShiftU64 (OrData, StartBit) & ~LShiftU64 ((UINT64)-2, EndBit));\r
+\r
+  Value1 = LShiftU64 (OrData, StartBit);\r
+  Value2 = LShiftU64 ((UINT64) - 2, EndBit);\r
+\r
+  return Operand | (Value1 & ~Value2);\r
 }\r
 \r
 /**\r
@@ -739,14 +789,14 @@ BitFieldOr64 (
   If 64-bit operations are not supported, then ASSERT().\r
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..63.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..63.\r
-  @param  AndData   The value to AND with the read value from the value\r
+  @param  AndData   The value to AND with the read value from the value.\r
 \r
   @return The new 64-bit value.\r
 \r
@@ -760,10 +810,16 @@ BitFieldAnd64 (
   IN      UINT64                    AndData\r
   )\r
 {\r
-  ASSERT (EndBit < sizeof (Operand) * 8);\r
+  UINT64  Value1;\r
+  UINT64  Value2;\r
+  \r
+  ASSERT (EndBit < 64);\r
   ASSERT (StartBit <= EndBit);\r
-  return Operand &\r
-         ~(LShiftU64 (~AndData, StartBit) & ~LShiftU64 ((UINT64)-2, EndBit));\r
+\r
+  Value1 = LShiftU64 (~AndData, StartBit);\r
+  Value2 = LShiftU64 ((UINT64)-2, EndBit);\r
+\r
+  return Operand & ~(Value1 & ~Value2);\r
 }\r
 \r
 /**\r
@@ -771,14 +827,14 @@ 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
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -801,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