\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
+\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
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
// ~((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
// ~((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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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