/** @file\r
Bit field functions of BaseLib.\r
\r
- Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2006 - 2018, 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
in Operand and the value specified by AndData. All other bits in Operand are\r
preserved. The new value is returned.\r
\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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
@param EndBit The ordinal of the most significant bit in the bit field.\r
IN UINTN OrData\r
)\r
{\r
+ //\r
+ // Higher bits in OrData those are not used must be zero.\r
+ //\r
+ // EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,\r
+ // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.\r
+ //\r
+ ASSERT ((OrData >> (EndBit - StartBit)) == ((OrData >> (EndBit - StartBit)) & 1));\r
+\r
//\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
in Operand and the value specified by AndData. All other bits in Operand are\r
preserved. The new value is returned.\r
\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, 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
@param EndBit The ordinal of the most significant bit in the bit field.\r
IN UINTN AndData\r
)\r
{\r
+ //\r
+ // Higher bits in AndData those are not used must be zero.\r
+ //\r
+ // EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,\r
+ // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.\r
+ //\r
+ ASSERT ((AndData >> (EndBit - StartBit)) == ((AndData >> (EndBit - StartBit)) & 1));\r
+\r
//\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
If StartBit is greater than 7, then ASSERT().\r
If EndBit is greater than 7, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If Value is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 7, then ASSERT().\r
If EndBit is greater than 7, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 7, then ASSERT().\r
If EndBit is greater than 7, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, 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
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
+ 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 StartBit is greater than 7, then ASSERT().\r
If EndBit is greater than 7, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 15, then ASSERT().\r
If EndBit is greater than 15, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If Value is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 15, then ASSERT().\r
If EndBit is greater than 15, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 15, then ASSERT().\r
If EndBit is greater than 15, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, 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
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
+ 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 StartBit is greater than 15, then ASSERT().\r
If EndBit is greater than 15, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 31, then ASSERT().\r
If EndBit is greater than 31, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If Value is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 31, then ASSERT().\r
If EndBit is greater than 31, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 31, then ASSERT().\r
If EndBit is greater than 31, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, 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
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
+ 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 StartBit is greater than 31, then ASSERT().\r
If EndBit is greater than 31, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 63, then ASSERT().\r
If EndBit is greater than 63, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If Value is larger than the bitmask value range specified by StartBit and EndBit, 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 StartBit is greater than 63, then ASSERT().\r
If EndBit is greater than 63, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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
\r
ASSERT (EndBit < 64);\r
ASSERT (StartBit <= EndBit);\r
+ //\r
+ // Higher bits in OrData those are not used must be zero.\r
+ //\r
+ // EndBit - StartBit + 1 might be 64 while the result right shifting 64 on RShiftU64() API is invalid,\r
+ // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.\r
+ //\r
+ ASSERT (RShiftU64 (OrData, EndBit - StartBit) == (RShiftU64 (OrData, EndBit - StartBit) & 1));\r
\r
Value1 = LShiftU64 (OrData, StartBit);\r
Value2 = LShiftU64 ((UINT64) - 2, EndBit);\r
If StartBit is greater than 63, then ASSERT().\r
If EndBit is greater than 63, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, 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
{\r
UINT64 Value1;\r
UINT64 Value2;\r
- \r
+\r
ASSERT (EndBit < 64);\r
ASSERT (StartBit <= EndBit);\r
+ //\r
+ // Higher bits in AndData those are not used must be zero.\r
+ //\r
+ // EndBit - StartBit + 1 might be 64 while the right shifting 64 on RShiftU64() API is invalid,\r
+ // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.\r
+ //\r
+ ASSERT (RShiftU64 (AndData, EndBit - StartBit) == (RShiftU64 (AndData, EndBit - StartBit) & 1));\r
\r
Value1 = LShiftU64 (~AndData, StartBit);\r
Value2 = LShiftU64 ((UINT64)-2, EndBit);\r
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
+ 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 StartBit is greater than 63, then ASSERT().\r
If EndBit is greater than 63, then ASSERT().\r
If EndBit is less than StartBit, then ASSERT().\r
+ If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+ If OrData is larger than the bitmask value range specified by StartBit and EndBit, 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