645a662e810b01ed0491f8d8bd22c5660d9596e9
2 Bit field functions of BaseLib.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "BaseLibInternals.h"
18 Worker function that returns a bit field from Operand.
20 Returns the bitfield specified by the StartBit and the EndBit from Operand.
22 @param Operand Operand on which to perform the bitfield operation.
23 @param StartBit The ordinal of the least significant bit in the bit field.
24 @param EndBit The ordinal of the most significant bit in the bit field.
26 @return The bit field read.
31 InternalBaseLibBitFieldReadUint (
38 // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
39 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
41 return (Operand
& ~((UINTN
)-2 << EndBit
)) >> StartBit
;
45 Worker function that reads a bit field from Operand, performs a bitwise OR,
46 and returns the result.
48 Performs a bitwise OR between the bit field specified by StartBit and EndBit
49 in Operand and the value specified by AndData. All other bits in Operand are
50 preserved. The new value is returned.
52 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
54 @param Operand Operand on which to perform the bitfield operation.
55 @param StartBit The ordinal of the least significant bit in the bit field.
56 @param EndBit The ordinal of the most significant bit in the bit field.
57 @param OrData The value to OR with the read value from the value.
59 @return The new value.
64 InternalBaseLibBitFieldOrUint (
72 // Higher bits in OrData those are not used must be zero.
74 // EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,
75 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
77 ASSERT ((OrData
>> (EndBit
- StartBit
)) == ((OrData
>> (EndBit
- StartBit
)) & 1));
80 // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
81 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
83 return Operand
| ((OrData
<< StartBit
) & ~((UINTN
) -2 << EndBit
));
87 Worker function that reads a bit field from Operand, performs a bitwise AND,
88 and returns the result.
90 Performs a bitwise AND between the bit field specified by StartBit and EndBit
91 in Operand and the value specified by AndData. All other bits in Operand are
92 preserved. The new value is returned.
94 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
96 @param Operand Operand on which to perform the bitfield operation.
97 @param StartBit The ordinal of the least significant bit in the bit field.
98 @param EndBit The ordinal of the most significant bit in the bit field.
99 @param AndData The value to And with the read value from the value.
101 @return The new value.
106 InternalBaseLibBitFieldAndUint (
114 // Higher bits in AndData those are not used must be zero.
116 // EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,
117 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
119 ASSERT ((AndData
>> (EndBit
- StartBit
)) == ((AndData
>> (EndBit
- StartBit
)) & 1));
122 // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
123 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
125 return Operand
& ~((~AndData
<< StartBit
) & ~((UINTN
)-2 << EndBit
));
129 Returns a bit field from an 8-bit value.
131 Returns the bitfield specified by the StartBit and the EndBit from Operand.
133 If 8-bit operations are not supported, then ASSERT().
134 If StartBit is greater than 7, then ASSERT().
135 If EndBit is greater than 7, then ASSERT().
136 If EndBit is less than StartBit, then ASSERT().
138 @param Operand Operand on which to perform the bitfield operation.
139 @param StartBit The ordinal of the least significant bit in the bit field.
141 @param EndBit The ordinal of the most significant bit in the bit field.
144 @return The bit field read.
156 ASSERT (StartBit
<= EndBit
);
157 return (UINT8
)InternalBaseLibBitFieldReadUint (Operand
, StartBit
, EndBit
);
161 Writes a bit field to an 8-bit value, and returns the result.
163 Writes Value to the bit field specified by the StartBit and the EndBit in
164 Operand. All other bits in Operand are preserved. The new 8-bit value is
167 If 8-bit operations are not supported, then ASSERT().
168 If StartBit is greater than 7, then ASSERT().
169 If EndBit is greater than 7, then ASSERT().
170 If EndBit is less than StartBit, then ASSERT().
171 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
173 @param Operand Operand on which to perform the bitfield operation.
174 @param StartBit The ordinal of the least significant bit in the bit field.
176 @param EndBit The ordinal of the most significant bit in the bit field.
178 @param Value The new value of the bit field.
180 @return The new 8-bit value.
193 ASSERT (StartBit
<= EndBit
);
194 return BitFieldAndThenOr8 (Operand
, StartBit
, EndBit
, 0, Value
);
198 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
201 Performs a bitwise OR between the bit field specified by StartBit
202 and EndBit in Operand and the value specified by OrData. All other bits in
203 Operand are preserved. The new 8-bit value is returned.
205 If 8-bit operations are not supported, then ASSERT().
206 If StartBit is greater than 7, then ASSERT().
207 If EndBit is greater than 7, then ASSERT().
208 If EndBit is less than StartBit, then ASSERT().
209 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
211 @param Operand Operand on which to perform the bitfield operation.
212 @param StartBit The ordinal of the least significant bit in the bit field.
214 @param EndBit The ordinal of the most significant bit in the bit field.
216 @param OrData The value to OR with the read value from the value.
218 @return The new 8-bit value.
231 ASSERT (StartBit
<= EndBit
);
232 return (UINT8
)InternalBaseLibBitFieldOrUint (Operand
, StartBit
, EndBit
, OrData
);
236 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
239 Performs a bitwise AND between the bit field specified by StartBit and EndBit
240 in Operand and the value specified by AndData. All other bits in Operand are
241 preserved. The new 8-bit value is returned.
243 If 8-bit operations are not supported, then ASSERT().
244 If StartBit is greater than 7, then ASSERT().
245 If EndBit is greater than 7, then ASSERT().
246 If EndBit is less than StartBit, then ASSERT().
247 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
249 @param Operand Operand on which to perform the bitfield operation.
250 @param StartBit The ordinal of the least significant bit in the bit field.
252 @param EndBit The ordinal of the most significant bit in the bit field.
254 @param AndData The value to AND with the read value from the value.
256 @return The new 8-bit value.
269 ASSERT (StartBit
<= EndBit
);
270 return (UINT8
)InternalBaseLibBitFieldAndUint (Operand
, StartBit
, EndBit
, AndData
);
274 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
275 bitwise OR, and returns the result.
277 Performs a bitwise AND between the bit field specified by StartBit and EndBit
278 in Operand and the value specified by AndData, followed by a bitwise
279 OR with value specified by OrData. All other bits in Operand are
280 preserved. The new 8-bit value is returned.
282 If 8-bit operations are not supported, then ASSERT().
283 If StartBit is greater than 7, then ASSERT().
284 If EndBit is greater than 7, then ASSERT().
285 If EndBit is less than StartBit, then ASSERT().
286 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
287 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
289 @param Operand Operand on which to perform the bitfield operation.
290 @param StartBit The ordinal of the least significant bit in the bit field.
292 @param EndBit The ordinal of the most significant bit in the bit field.
294 @param AndData The value to AND with the read value from the value.
295 @param OrData The value to OR with the result of the AND operation.
297 @return The new 8-bit value.
311 ASSERT (StartBit
<= EndBit
);
313 BitFieldAnd8 (Operand
, StartBit
, EndBit
, AndData
),
321 Returns a bit field from a 16-bit value.
323 Returns the bitfield specified by the StartBit and the EndBit from Operand.
325 If 16-bit operations are not supported, then ASSERT().
326 If StartBit is greater than 15, then ASSERT().
327 If EndBit is greater than 15, then ASSERT().
328 If EndBit is less than StartBit, then ASSERT().
330 @param Operand Operand on which to perform the bitfield operation.
331 @param StartBit The ordinal of the least significant bit in the bit field.
333 @param EndBit The ordinal of the most significant bit in the bit field.
336 @return The bit field read.
347 ASSERT (EndBit
< 16);
348 ASSERT (StartBit
<= EndBit
);
349 return (UINT16
)InternalBaseLibBitFieldReadUint (Operand
, StartBit
, EndBit
);
353 Writes a bit field to a 16-bit value, and returns the result.
355 Writes Value to the bit field specified by the StartBit and the EndBit in
356 Operand. All other bits in Operand are preserved. The new 16-bit value is
359 If 16-bit operations are not supported, then ASSERT().
360 If StartBit is greater than 15, then ASSERT().
361 If EndBit is greater than 15, then ASSERT().
362 If EndBit is less than StartBit, then ASSERT().
363 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
365 @param Operand Operand on which to perform the bitfield operation.
366 @param StartBit The ordinal of the least significant bit in the bit field.
368 @param EndBit The ordinal of the most significant bit in the bit field.
370 @param Value The new value of the bit field.
372 @return The new 16-bit value.
384 ASSERT (EndBit
< 16);
385 ASSERT (StartBit
<= EndBit
);
386 return BitFieldAndThenOr16 (Operand
, StartBit
, EndBit
, 0, Value
);
390 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
393 Performs a bitwise OR between the bit field specified by StartBit
394 and EndBit in Operand and the value specified by OrData. All other bits in
395 Operand are preserved. The new 16-bit value is returned.
397 If 16-bit operations are not supported, then ASSERT().
398 If StartBit is greater than 15, then ASSERT().
399 If EndBit is greater than 15, then ASSERT().
400 If EndBit is less than StartBit, then ASSERT().
401 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
403 @param Operand Operand on which to perform the bitfield operation.
404 @param StartBit The ordinal of the least significant bit in the bit field.
406 @param EndBit The ordinal of the most significant bit in the bit field.
408 @param OrData The value to OR with the read value from the value.
410 @return The new 16-bit value.
422 ASSERT (EndBit
< 16);
423 ASSERT (StartBit
<= EndBit
);
424 return (UINT16
)InternalBaseLibBitFieldOrUint (Operand
, StartBit
, EndBit
, OrData
);
428 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
431 Performs a bitwise AND between the bit field specified by StartBit and EndBit
432 in Operand and the value specified by AndData. All other bits in Operand are
433 preserved. The new 16-bit value is returned.
435 If 16-bit operations are not supported, then ASSERT().
436 If StartBit is greater than 15, then ASSERT().
437 If EndBit is greater than 15, then ASSERT().
438 If EndBit is less than StartBit, then ASSERT().
439 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
441 @param Operand Operand on which to perform the bitfield operation.
442 @param StartBit The ordinal of the least significant bit in the bit field.
444 @param EndBit The ordinal of the most significant bit in the bit field.
446 @param AndData The value to AND with the read value from the value.
448 @return The new 16-bit value.
460 ASSERT (EndBit
< 16);
461 ASSERT (StartBit
<= EndBit
);
462 return (UINT16
)InternalBaseLibBitFieldAndUint (Operand
, StartBit
, EndBit
, AndData
);
466 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
467 bitwise OR, and returns the result.
469 Performs a bitwise AND between the bit field specified by StartBit and EndBit
470 in Operand and the value specified by AndData, followed by a bitwise
471 OR with value specified by OrData. All other bits in Operand are
472 preserved. The new 16-bit value is returned.
474 If 16-bit operations are not supported, then ASSERT().
475 If StartBit is greater than 15, then ASSERT().
476 If EndBit is greater than 15, then ASSERT().
477 If EndBit is less than StartBit, then ASSERT().
478 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
479 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
481 @param Operand Operand on which to perform the bitfield operation.
482 @param StartBit The ordinal of the least significant bit in the bit field.
484 @param EndBit The ordinal of the most significant bit in the bit field.
486 @param AndData The value to AND with the read value from the value.
487 @param OrData The value to OR with the result of the AND operation.
489 @return The new 16-bit value.
494 BitFieldAndThenOr16 (
502 ASSERT (EndBit
< 16);
503 ASSERT (StartBit
<= EndBit
);
504 return BitFieldOr16 (
505 BitFieldAnd16 (Operand
, StartBit
, EndBit
, AndData
),
513 Returns a bit field from a 32-bit value.
515 Returns the bitfield specified by the StartBit and the EndBit from Operand.
517 If 32-bit operations are not supported, then ASSERT().
518 If StartBit is greater than 31, then ASSERT().
519 If EndBit is greater than 31, then ASSERT().
520 If EndBit is less than StartBit, then ASSERT().
522 @param Operand Operand on which to perform the bitfield operation.
523 @param StartBit The ordinal of the least significant bit in the bit field.
525 @param EndBit The ordinal of the most significant bit in the bit field.
528 @return The bit field read.
539 ASSERT (EndBit
< 32);
540 ASSERT (StartBit
<= EndBit
);
541 return (UINT32
)InternalBaseLibBitFieldReadUint (Operand
, StartBit
, EndBit
);
545 Writes a bit field to a 32-bit value, and returns the result.
547 Writes Value to the bit field specified by the StartBit and the EndBit in
548 Operand. All other bits in Operand are preserved. The new 32-bit value is
551 If 32-bit operations are not supported, then ASSERT().
552 If StartBit is greater than 31, then ASSERT().
553 If EndBit is greater than 31, then ASSERT().
554 If EndBit is less than StartBit, then ASSERT().
555 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
557 @param Operand Operand on which to perform the bitfield operation.
558 @param StartBit The ordinal of the least significant bit in the bit field.
560 @param EndBit The ordinal of the most significant bit in the bit field.
562 @param Value The new value of the bit field.
564 @return The new 32-bit value.
576 ASSERT (EndBit
< 32);
577 ASSERT (StartBit
<= EndBit
);
578 return BitFieldAndThenOr32 (Operand
, StartBit
, EndBit
, 0, Value
);
582 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
585 Performs a bitwise OR between the bit field specified by StartBit
586 and EndBit in Operand and the value specified by OrData. All other bits in
587 Operand are preserved. The new 32-bit value is returned.
589 If 32-bit operations are not supported, then ASSERT().
590 If StartBit is greater than 31, then ASSERT().
591 If EndBit is greater than 31, then ASSERT().
592 If EndBit is less than StartBit, then ASSERT().
593 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
595 @param Operand Operand on which to perform the bitfield operation.
596 @param StartBit The ordinal of the least significant bit in the bit field.
598 @param EndBit The ordinal of the most significant bit in the bit field.
600 @param OrData The value to OR with the read value from the value.
602 @return The new 32-bit value.
614 ASSERT (EndBit
< 32);
615 ASSERT (StartBit
<= EndBit
);
616 return (UINT32
)InternalBaseLibBitFieldOrUint (Operand
, StartBit
, EndBit
, OrData
);
620 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
623 Performs a bitwise AND between the bit field specified by StartBit and EndBit
624 in Operand and the value specified by AndData. All other bits in Operand are
625 preserved. The new 32-bit value is returned.
627 If 32-bit operations are not supported, then ASSERT().
628 If StartBit is greater than 31, then ASSERT().
629 If EndBit is greater than 31, then ASSERT().
630 If EndBit is less than StartBit, then ASSERT().
631 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
633 @param Operand Operand on which to perform the bitfield operation.
634 @param StartBit The ordinal of the least significant bit in the bit field.
636 @param EndBit The ordinal of the most significant bit in the bit field.
638 @param AndData The value to AND with the read value from the value.
640 @return The new 32-bit value.
652 ASSERT (EndBit
< 32);
653 ASSERT (StartBit
<= EndBit
);
654 return (UINT32
)InternalBaseLibBitFieldAndUint (Operand
, StartBit
, EndBit
, AndData
);
658 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
659 bitwise OR, and returns the result.
661 Performs a bitwise AND between the bit field specified by StartBit and EndBit
662 in Operand and the value specified by AndData, followed by a bitwise
663 OR with value specified by OrData. All other bits in Operand are
664 preserved. The new 32-bit value is returned.
666 If 32-bit operations are not supported, then ASSERT().
667 If StartBit is greater than 31, then ASSERT().
668 If EndBit is greater than 31, then ASSERT().
669 If EndBit is less than StartBit, then ASSERT().
670 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
671 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
673 @param Operand Operand on which to perform the bitfield operation.
674 @param StartBit The ordinal of the least significant bit in the bit field.
676 @param EndBit The ordinal of the most significant bit in the bit field.
678 @param AndData The value to AND with the read value from the value.
679 @param OrData The value to OR with the result of the AND operation.
681 @return The new 32-bit value.
686 BitFieldAndThenOr32 (
694 ASSERT (EndBit
< 32);
695 ASSERT (StartBit
<= EndBit
);
696 return BitFieldOr32 (
697 BitFieldAnd32 (Operand
, StartBit
, EndBit
, AndData
),
705 Returns a bit field from a 64-bit value.
707 Returns the bitfield specified by the StartBit and the EndBit from Operand.
709 If 64-bit operations are not supported, then ASSERT().
710 If StartBit is greater than 63, then ASSERT().
711 If EndBit is greater than 63, then ASSERT().
712 If EndBit is less than StartBit, then ASSERT().
714 @param Operand Operand on which to perform the bitfield operation.
715 @param StartBit The ordinal of the least significant bit in the bit field.
717 @param EndBit The ordinal of the most significant bit in the bit field.
720 @return The bit field read.
731 ASSERT (EndBit
< 64);
732 ASSERT (StartBit
<= EndBit
);
733 return RShiftU64 (Operand
& ~LShiftU64 ((UINT64
)-2, EndBit
), StartBit
);
737 Writes a bit field to a 64-bit value, and returns the result.
739 Writes Value to the bit field specified by the StartBit and the EndBit in
740 Operand. All other bits in Operand are preserved. The new 64-bit value is
743 If 64-bit operations are not supported, then ASSERT().
744 If StartBit is greater than 63, then ASSERT().
745 If EndBit is greater than 63, then ASSERT().
746 If EndBit is less than StartBit, then ASSERT().
747 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
749 @param Operand Operand on which to perform the bitfield operation.
750 @param StartBit The ordinal of the least significant bit in the bit field.
752 @param EndBit The ordinal of the most significant bit in the bit field.
754 @param Value The new value of the bit field.
756 @return The new 64-bit value.
768 ASSERT (EndBit
< 64);
769 ASSERT (StartBit
<= EndBit
);
770 return BitFieldAndThenOr64 (Operand
, StartBit
, EndBit
, 0, Value
);
774 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
777 Performs a bitwise OR between the bit field specified by StartBit
778 and EndBit in Operand and the value specified by OrData. All other bits in
779 Operand are preserved. The new 64-bit value is returned.
781 If 64-bit operations are not supported, then ASSERT().
782 If StartBit is greater than 63, then ASSERT().
783 If EndBit is greater than 63, then ASSERT().
784 If EndBit is less than StartBit, then ASSERT().
785 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
787 @param Operand Operand on which to perform the bitfield operation.
788 @param StartBit The ordinal of the least significant bit in the bit field.
790 @param EndBit The ordinal of the most significant bit in the bit field.
792 @param OrData The value to OR with the read value from the value
794 @return The new 64-bit value.
809 ASSERT (EndBit
< 64);
810 ASSERT (StartBit
<= EndBit
);
812 // Higher bits in OrData those are not used must be zero.
814 // EndBit - StartBit + 1 might be 64 while the result right shifting 64 on RShiftU64() API is invalid,
815 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
817 ASSERT (RShiftU64 (OrData
, EndBit
- StartBit
) == (RShiftU64 (OrData
, EndBit
- StartBit
) & 1));
819 Value1
= LShiftU64 (OrData
, StartBit
);
820 Value2
= LShiftU64 ((UINT64
) - 2, EndBit
);
822 return Operand
| (Value1
& ~Value2
);
826 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
829 Performs a bitwise AND between the bit field specified by StartBit and EndBit
830 in Operand and the value specified by AndData. All other bits in Operand are
831 preserved. The new 64-bit value is returned.
833 If 64-bit operations are not supported, then ASSERT().
834 If StartBit is greater than 63, then ASSERT().
835 If EndBit is greater than 63, then ASSERT().
836 If EndBit is less than StartBit, then ASSERT().
837 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
839 @param Operand Operand on which to perform the bitfield operation.
840 @param StartBit The ordinal of the least significant bit in the bit field.
842 @param EndBit The ordinal of the most significant bit in the bit field.
844 @param AndData The value to AND with the read value from the value.
846 @return The new 64-bit value.
861 ASSERT (EndBit
< 64);
862 ASSERT (StartBit
<= EndBit
);
864 // Higher bits in AndData those are not used must be zero.
866 // EndBit - StartBit + 1 might be 64 while the right shifting 64 on RShiftU64() API is invalid,
867 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
869 ASSERT (RShiftU64 (AndData
, EndBit
- StartBit
) == (RShiftU64 (AndData
, EndBit
- StartBit
) & 1));
871 Value1
= LShiftU64 (~AndData
, StartBit
);
872 Value2
= LShiftU64 ((UINT64
)-2, EndBit
);
874 return Operand
& ~(Value1
& ~Value2
);
878 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
879 bitwise OR, and returns the result.
881 Performs a bitwise AND between the bit field specified by StartBit and EndBit
882 in Operand and the value specified by AndData, followed by a bitwise
883 OR with value specified by OrData. All other bits in Operand are
884 preserved. The new 64-bit value is returned.
886 If 64-bit operations are not supported, then ASSERT().
887 If StartBit is greater than 63, then ASSERT().
888 If EndBit is greater than 63, then ASSERT().
889 If EndBit is less than StartBit, then ASSERT().
890 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
891 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
893 @param Operand Operand on which to perform the bitfield operation.
894 @param StartBit The ordinal of the least significant bit in the bit field.
896 @param EndBit The ordinal of the most significant bit in the bit field.
898 @param AndData The value to AND with the read value from the value.
899 @param OrData The value to OR with the result of the AND operation.
901 @return The new 64-bit value.
906 BitFieldAndThenOr64 (
914 ASSERT (EndBit
< 64);
915 ASSERT (StartBit
<= EndBit
);
916 return BitFieldOr64 (
917 BitFieldAnd64 (Operand
, StartBit
, EndBit
, AndData
),
925 Reads a bit field from a 32-bit value, counts and returns
926 the number of set bits.
928 Counts the number of set bits in the bit field specified by
929 StartBit and EndBit in Operand. The count is returned.
931 If StartBit is greater than 31, then ASSERT().
932 If EndBit is greater than 31, then ASSERT().
933 If EndBit is less than StartBit, then ASSERT().
935 @param Operand Operand on which to perform the bitfield operation.
936 @param StartBit The ordinal of the least significant bit in the bit field.
938 @param EndBit The ordinal of the most significant bit in the bit field.
941 @return The number of bits set between StartBit and EndBit.
946 BitFieldCountOnes32 (
954 ASSERT (EndBit
< 32);
955 ASSERT (StartBit
<= EndBit
);
957 Count
= BitFieldRead32 (Operand
, StartBit
, EndBit
);
958 Count
-= ((Count
>> 1) & 0x55555555);
959 Count
= (Count
& 0x33333333) + ((Count
>> 2) & 0x33333333);
963 Count
+= Count
>> 16;
965 return (UINT8
) Count
& 0x3F;
969 Reads a bit field from a 64-bit value, counts and returns
970 the number of set bits.
972 Counts the number of set bits in the bit field specified by
973 StartBit and EndBit in Operand. The count is returned.
975 If StartBit is greater than 63, then ASSERT().
976 If EndBit is greater than 63, then ASSERT().
977 If EndBit is less than StartBit, then ASSERT().
979 @param Operand Operand on which to perform the bitfield operation.
980 @param StartBit The ordinal of the least significant bit in the bit field.
982 @param EndBit The ordinal of the most significant bit in the bit field.
985 @return The number of bits set between StartBit and EndBit.
990 BitFieldCountOnes64 (
999 ASSERT (EndBit
< 64);
1000 ASSERT (StartBit
<= EndBit
);
1002 BitField
= BitFieldRead64 (Operand
, StartBit
, EndBit
);
1003 Count
= BitFieldCountOnes32 ((UINT32
) BitField
, 0, 31);
1004 Count
+= BitFieldCountOnes32 ((UINT32
) RShiftU64(BitField
, 32), 0, 31);