]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/BitField.c
Make MDE package pass intel IPF compiler with /W4 /WX switched on.
[mirror_edk2.git] / MdePkg / Library / BaseLib / BitField.c
index 9c1aff1c6f09ce6122cd1346d8173d8ac1bb4920..3db8a23c950ebbc4f23b84b73277ecfc9f9b048a 100644 (file)
 \r
 **/\r
 \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
 unsigned int\r
-EFIAPI\r
 BitFieldReadUint (\r
   IN      unsigned int              Operand,\r
   IN      UINTN                     StartBit,\r
@@ -29,8 +42,23 @@ BitFieldReadUint (
   return (Operand & ~((unsigned int)-2 << EndBit)) >> StartBit;\r
 }\r
 \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
 unsigned int\r
-EFIAPI\r
 BitFieldOrUint (\r
   IN      unsigned int              Operand,\r
   IN      UINTN                     StartBit,\r
@@ -42,11 +70,26 @@ BitFieldOrUint (
   // ~((unsigned int)-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) & ~((unsigned int) -2 << EndBit));\r
 }\r
 \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
 unsigned int\r
-EFIAPI\r
 BitFieldAndUint (\r
   IN      unsigned int              Operand,\r
   IN      UINTN                     StartBit,\r
@@ -58,7 +101,7 @@ BitFieldAndUint (
   // ~((unsigned int)-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) & ~((unsigned int) -2 << EndBit));\r
 }\r
 \r
 /**\r
@@ -722,10 +765,16 @@ BitFieldOr64 (
   IN      UINT64                    OrData\r
   )\r
 {\r
+  UINT64  Value1;\r
+  UINT64  Value2;\r
+\r
   ASSERT (EndBit < sizeof (Operand) * 8);\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
@@ -760,10 +809,16 @@ BitFieldAnd64 (
   IN      UINT64                    AndData\r
   )\r
 {\r
+  UINT64  Value1;\r
+  UINT64  Value2;\r
+  \r
   ASSERT (EndBit < sizeof (Operand) * 8);\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