]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/BitField.c
2 Bit field functions of BaseLib.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "BaseLibInternals.h"
12 Worker function that returns a bit field from Operand.
14 Returns the bitfield specified by the StartBit and the EndBit from Operand.
16 @param Operand Operand on which to perform the bitfield operation.
17 @param StartBit The ordinal of the least significant bit in the bit field.
18 @param EndBit The ordinal of the most significant bit in the bit field.
20 @return The bit field read.
25 InternalBaseLibBitFieldReadUint (
32 // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
33 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
35 return (Operand
& ~((UINTN
)-2 << EndBit
)) >> StartBit
;
39 Worker function that reads a bit field from Operand, performs a bitwise OR,
40 and returns the result.
42 Performs a bitwise OR between the bit field specified by StartBit and EndBit
43 in Operand and the value specified by AndData. All other bits in Operand are
44 preserved. The new value is returned.
46 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
48 @param Operand Operand on which to perform the bitfield operation.
49 @param StartBit The ordinal of the least significant bit in the bit field.
50 @param EndBit The ordinal of the most significant bit in the bit field.
51 @param OrData The value to OR with the read value from the value.
53 @return The new value.
58 InternalBaseLibBitFieldOrUint (
66 // Higher bits in OrData those are not used must be zero.
68 // EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,
69 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
71 ASSERT ((OrData
>> (EndBit
- StartBit
)) == ((OrData
>> (EndBit
- StartBit
)) & 1));
74 // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
75 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
77 return Operand
| ((OrData
<< StartBit
) & ~((UINTN
) -2 << EndBit
));
81 Worker function that reads a bit field from Operand, performs a bitwise AND,
82 and returns the result.
84 Performs a bitwise AND between the bit field specified by StartBit and EndBit
85 in Operand and the value specified by AndData. All other bits in Operand are
86 preserved. The new value is returned.
88 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
90 @param Operand Operand on which to perform the bitfield operation.
91 @param StartBit The ordinal of the least significant bit in the bit field.
92 @param EndBit The ordinal of the most significant bit in the bit field.
93 @param AndData The value to And with the read value from the value.
95 @return The new value.
100 InternalBaseLibBitFieldAndUint (
108 // Higher bits in AndData those are not used must be zero.
110 // EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,
111 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
113 ASSERT ((AndData
>> (EndBit
- StartBit
)) == ((AndData
>> (EndBit
- StartBit
)) & 1));
116 // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
117 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
119 return Operand
& ~((~AndData
<< StartBit
) & ~((UINTN
)-2 << EndBit
));
123 Returns a bit field from an 8-bit value.
125 Returns the bitfield specified by the StartBit and the EndBit from Operand.
127 If 8-bit operations are not supported, then ASSERT().
128 If StartBit is greater than 7, then ASSERT().
129 If EndBit is greater than 7, then ASSERT().
130 If EndBit is less than StartBit, then ASSERT().
132 @param Operand Operand on which to perform the bitfield operation.
133 @param StartBit The ordinal of the least significant bit in the bit field.
135 @param EndBit The ordinal of the most significant bit in the bit field.
138 @return The bit field read.
150 ASSERT (StartBit
<= EndBit
);
151 return (UINT8
)InternalBaseLibBitFieldReadUint (Operand
, StartBit
, EndBit
);
155 Writes a bit field to an 8-bit value, and returns the result.
157 Writes Value to the bit field specified by the StartBit and the EndBit in
158 Operand. All other bits in Operand are preserved. The new 8-bit value is
161 If 8-bit operations are not supported, then ASSERT().
162 If StartBit is greater than 7, then ASSERT().
163 If EndBit is greater than 7, then ASSERT().
164 If EndBit is less than StartBit, then ASSERT().
165 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
167 @param Operand Operand on which to perform the bitfield operation.
168 @param StartBit The ordinal of the least significant bit in the bit field.
170 @param EndBit The ordinal of the most significant bit in the bit field.
172 @param Value The new value of the bit field.
174 @return The new 8-bit value.
187 ASSERT (StartBit
<= EndBit
);
188 return BitFieldAndThenOr8 (Operand
, StartBit
, EndBit
, 0, Value
);
192 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
195 Performs a bitwise OR between the bit field specified by StartBit
196 and EndBit in Operand and the value specified by OrData. All other bits in
197 Operand are preserved. The new 8-bit value is returned.
199 If 8-bit operations are not supported, then ASSERT().
200 If StartBit is greater than 7, then ASSERT().
201 If EndBit is greater than 7, then ASSERT().
202 If EndBit is less than StartBit, then ASSERT().
203 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
205 @param Operand Operand on which to perform the bitfield operation.
206 @param StartBit The ordinal of the least significant bit in the bit field.
208 @param EndBit The ordinal of the most significant bit in the bit field.
210 @param OrData The value to OR with the read value from the value.
212 @return The new 8-bit value.
225 ASSERT (StartBit
<= EndBit
);
226 return (UINT8
)InternalBaseLibBitFieldOrUint (Operand
, StartBit
, EndBit
, OrData
);
230 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
233 Performs a bitwise AND between the bit field specified by StartBit and EndBit
234 in Operand and the value specified by AndData. All other bits in Operand are
235 preserved. The new 8-bit value is returned.
237 If 8-bit operations are not supported, then ASSERT().
238 If StartBit is greater than 7, then ASSERT().
239 If EndBit is greater than 7, then ASSERT().
240 If EndBit is less than StartBit, then ASSERT().
241 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
243 @param Operand Operand on which to perform the bitfield operation.
244 @param StartBit The ordinal of the least significant bit in the bit field.
246 @param EndBit The ordinal of the most significant bit in the bit field.
248 @param AndData The value to AND with the read value from the value.
250 @return The new 8-bit value.
263 ASSERT (StartBit
<= EndBit
);
264 return (UINT8
)InternalBaseLibBitFieldAndUint (Operand
, StartBit
, EndBit
, AndData
);
268 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
269 bitwise OR, and returns the result.
271 Performs a bitwise AND between the bit field specified by StartBit and EndBit
272 in Operand and the value specified by AndData, followed by a bitwise
273 OR with value specified by OrData. All other bits in Operand are
274 preserved. The new 8-bit value is returned.
276 If 8-bit operations are not supported, then ASSERT().
277 If StartBit is greater than 7, then ASSERT().
278 If EndBit is greater than 7, then ASSERT().
279 If EndBit is less than StartBit, then ASSERT().
280 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
281 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
283 @param Operand Operand on which to perform the bitfield operation.
284 @param StartBit The ordinal of the least significant bit in the bit field.
286 @param EndBit The ordinal of the most significant bit in the bit field.
288 @param AndData The value to AND with the read value from the value.
289 @param OrData The value to OR with the result of the AND operation.
291 @return The new 8-bit value.
305 ASSERT (StartBit
<= EndBit
);
307 BitFieldAnd8 (Operand
, StartBit
, EndBit
, AndData
),
315 Returns a bit field from a 16-bit value.
317 Returns the bitfield specified by the StartBit and the EndBit from Operand.
319 If 16-bit operations are not supported, then ASSERT().
320 If StartBit is greater than 15, then ASSERT().
321 If EndBit is greater than 15, then ASSERT().
322 If EndBit is less than StartBit, then ASSERT().
324 @param Operand Operand on which to perform the bitfield operation.
325 @param StartBit The ordinal of the least significant bit in the bit field.
327 @param EndBit The ordinal of the most significant bit in the bit field.
330 @return The bit field read.
341 ASSERT (EndBit
< 16);
342 ASSERT (StartBit
<= EndBit
);
343 return (UINT16
)InternalBaseLibBitFieldReadUint (Operand
, StartBit
, EndBit
);
347 Writes a bit field to a 16-bit value, and returns the result.
349 Writes Value to the bit field specified by the StartBit and the EndBit in
350 Operand. All other bits in Operand are preserved. The new 16-bit value is
353 If 16-bit operations are not supported, then ASSERT().
354 If StartBit is greater than 15, then ASSERT().
355 If EndBit is greater than 15, then ASSERT().
356 If EndBit is less than StartBit, then ASSERT().
357 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
359 @param Operand Operand on which to perform the bitfield operation.
360 @param StartBit The ordinal of the least significant bit in the bit field.
362 @param EndBit The ordinal of the most significant bit in the bit field.
364 @param Value The new value of the bit field.
366 @return The new 16-bit value.
378 ASSERT (EndBit
< 16);
379 ASSERT (StartBit
<= EndBit
);
380 return BitFieldAndThenOr16 (Operand
, StartBit
, EndBit
, 0, Value
);
384 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
387 Performs a bitwise OR between the bit field specified by StartBit
388 and EndBit in Operand and the value specified by OrData. All other bits in
389 Operand are preserved. The new 16-bit value is returned.
391 If 16-bit operations are not supported, then ASSERT().
392 If StartBit is greater than 15, then ASSERT().
393 If EndBit is greater than 15, then ASSERT().
394 If EndBit is less than StartBit, then ASSERT().
395 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
397 @param Operand Operand on which to perform the bitfield operation.
398 @param StartBit The ordinal of the least significant bit in the bit field.
400 @param EndBit The ordinal of the most significant bit in the bit field.
402 @param OrData The value to OR with the read value from the value.
404 @return The new 16-bit value.
416 ASSERT (EndBit
< 16);
417 ASSERT (StartBit
<= EndBit
);
418 return (UINT16
)InternalBaseLibBitFieldOrUint (Operand
, StartBit
, EndBit
, OrData
);
422 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
425 Performs a bitwise AND between the bit field specified by StartBit and EndBit
426 in Operand and the value specified by AndData. All other bits in Operand are
427 preserved. The new 16-bit value is returned.
429 If 16-bit operations are not supported, then ASSERT().
430 If StartBit is greater than 15, then ASSERT().
431 If EndBit is greater than 15, then ASSERT().
432 If EndBit is less than StartBit, then ASSERT().
433 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
435 @param Operand Operand on which to perform the bitfield operation.
436 @param StartBit The ordinal of the least significant bit in the bit field.
438 @param EndBit The ordinal of the most significant bit in the bit field.
440 @param AndData The value to AND with the read value from the value.
442 @return The new 16-bit value.
454 ASSERT (EndBit
< 16);
455 ASSERT (StartBit
<= EndBit
);
456 return (UINT16
)InternalBaseLibBitFieldAndUint (Operand
, StartBit
, EndBit
, AndData
);
460 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
461 bitwise OR, and returns the result.
463 Performs a bitwise AND between the bit field specified by StartBit and EndBit
464 in Operand and the value specified by AndData, followed by a bitwise
465 OR with value specified by OrData. All other bits in Operand are
466 preserved. The new 16-bit value is returned.
468 If 16-bit operations are not supported, then ASSERT().
469 If StartBit is greater than 15, then ASSERT().
470 If EndBit is greater than 15, then ASSERT().
471 If EndBit is less than StartBit, then ASSERT().
472 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
473 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
475 @param Operand Operand on which to perform the bitfield operation.
476 @param StartBit The ordinal of the least significant bit in the bit field.
478 @param EndBit The ordinal of the most significant bit in the bit field.
480 @param AndData The value to AND with the read value from the value.
481 @param OrData The value to OR with the result of the AND operation.
483 @return The new 16-bit value.
488 BitFieldAndThenOr16 (
496 ASSERT (EndBit
< 16);
497 ASSERT (StartBit
<= EndBit
);
498 return BitFieldOr16 (
499 BitFieldAnd16 (Operand
, StartBit
, EndBit
, AndData
),
507 Returns a bit field from a 32-bit value.
509 Returns the bitfield specified by the StartBit and the EndBit from Operand.
511 If 32-bit operations are not supported, then ASSERT().
512 If StartBit is greater than 31, then ASSERT().
513 If EndBit is greater than 31, then ASSERT().
514 If EndBit is less than StartBit, then ASSERT().
516 @param Operand Operand on which to perform the bitfield operation.
517 @param StartBit The ordinal of the least significant bit in the bit field.
519 @param EndBit The ordinal of the most significant bit in the bit field.
522 @return The bit field read.
533 ASSERT (EndBit
< 32);
534 ASSERT (StartBit
<= EndBit
);
535 return (UINT32
)InternalBaseLibBitFieldReadUint (Operand
, StartBit
, EndBit
);
539 Writes a bit field to a 32-bit value, and returns the result.
541 Writes Value to the bit field specified by the StartBit and the EndBit in
542 Operand. All other bits in Operand are preserved. The new 32-bit value is
545 If 32-bit operations are not supported, then ASSERT().
546 If StartBit is greater than 31, then ASSERT().
547 If EndBit is greater than 31, then ASSERT().
548 If EndBit is less than StartBit, then ASSERT().
549 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
551 @param Operand Operand on which to perform the bitfield operation.
552 @param StartBit The ordinal of the least significant bit in the bit field.
554 @param EndBit The ordinal of the most significant bit in the bit field.
556 @param Value The new value of the bit field.
558 @return The new 32-bit value.
570 ASSERT (EndBit
< 32);
571 ASSERT (StartBit
<= EndBit
);
572 return BitFieldAndThenOr32 (Operand
, StartBit
, EndBit
, 0, Value
);
576 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
579 Performs a bitwise OR between the bit field specified by StartBit
580 and EndBit in Operand and the value specified by OrData. All other bits in
581 Operand are preserved. The new 32-bit value is returned.
583 If 32-bit operations are not supported, then ASSERT().
584 If StartBit is greater than 31, then ASSERT().
585 If EndBit is greater than 31, then ASSERT().
586 If EndBit is less than StartBit, then ASSERT().
587 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
589 @param Operand Operand on which to perform the bitfield operation.
590 @param StartBit The ordinal of the least significant bit in the bit field.
592 @param EndBit The ordinal of the most significant bit in the bit field.
594 @param OrData The value to OR with the read value from the value.
596 @return The new 32-bit value.
608 ASSERT (EndBit
< 32);
609 ASSERT (StartBit
<= EndBit
);
610 return (UINT32
)InternalBaseLibBitFieldOrUint (Operand
, StartBit
, EndBit
, OrData
);
614 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
617 Performs a bitwise AND between the bit field specified by StartBit and EndBit
618 in Operand and the value specified by AndData. All other bits in Operand are
619 preserved. The new 32-bit value is returned.
621 If 32-bit operations are not supported, then ASSERT().
622 If StartBit is greater than 31, then ASSERT().
623 If EndBit is greater than 31, then ASSERT().
624 If EndBit is less than StartBit, then ASSERT().
625 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
627 @param Operand Operand on which to perform the bitfield operation.
628 @param StartBit The ordinal of the least significant bit in the bit field.
630 @param EndBit The ordinal of the most significant bit in the bit field.
632 @param AndData The value to AND with the read value from the value.
634 @return The new 32-bit value.
646 ASSERT (EndBit
< 32);
647 ASSERT (StartBit
<= EndBit
);
648 return (UINT32
)InternalBaseLibBitFieldAndUint (Operand
, StartBit
, EndBit
, AndData
);
652 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
653 bitwise OR, and returns the result.
655 Performs a bitwise AND between the bit field specified by StartBit and EndBit
656 in Operand and the value specified by AndData, followed by a bitwise
657 OR with value specified by OrData. All other bits in Operand are
658 preserved. The new 32-bit value is returned.
660 If 32-bit operations are not supported, then ASSERT().
661 If StartBit is greater than 31, then ASSERT().
662 If EndBit is greater than 31, then ASSERT().
663 If EndBit is less than StartBit, then ASSERT().
664 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
665 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
667 @param Operand Operand on which to perform the bitfield operation.
668 @param StartBit The ordinal of the least significant bit in the bit field.
670 @param EndBit The ordinal of the most significant bit in the bit field.
672 @param AndData The value to AND with the read value from the value.
673 @param OrData The value to OR with the result of the AND operation.
675 @return The new 32-bit value.
680 BitFieldAndThenOr32 (
688 ASSERT (EndBit
< 32);
689 ASSERT (StartBit
<= EndBit
);
690 return BitFieldOr32 (
691 BitFieldAnd32 (Operand
, StartBit
, EndBit
, AndData
),
699 Returns a bit field from a 64-bit value.
701 Returns the bitfield specified by the StartBit and the EndBit from Operand.
703 If 64-bit operations are not supported, then ASSERT().
704 If StartBit is greater than 63, then ASSERT().
705 If EndBit is greater than 63, then ASSERT().
706 If EndBit is less than StartBit, then ASSERT().
708 @param Operand Operand on which to perform the bitfield operation.
709 @param StartBit The ordinal of the least significant bit in the bit field.
711 @param EndBit The ordinal of the most significant bit in the bit field.
714 @return The bit field read.
725 ASSERT (EndBit
< 64);
726 ASSERT (StartBit
<= EndBit
);
727 return RShiftU64 (Operand
& ~LShiftU64 ((UINT64
)-2, EndBit
), StartBit
);
731 Writes a bit field to a 64-bit value, and returns the result.
733 Writes Value to the bit field specified by the StartBit and the EndBit in
734 Operand. All other bits in Operand are preserved. The new 64-bit value is
737 If 64-bit operations are not supported, then ASSERT().
738 If StartBit is greater than 63, then ASSERT().
739 If EndBit is greater than 63, then ASSERT().
740 If EndBit is less than StartBit, then ASSERT().
741 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
743 @param Operand Operand on which to perform the bitfield operation.
744 @param StartBit The ordinal of the least significant bit in the bit field.
746 @param EndBit The ordinal of the most significant bit in the bit field.
748 @param Value The new value of the bit field.
750 @return The new 64-bit value.
762 ASSERT (EndBit
< 64);
763 ASSERT (StartBit
<= EndBit
);
764 return BitFieldAndThenOr64 (Operand
, StartBit
, EndBit
, 0, Value
);
768 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
771 Performs a bitwise OR between the bit field specified by StartBit
772 and EndBit in Operand and the value specified by OrData. All other bits in
773 Operand are preserved. The new 64-bit value is returned.
775 If 64-bit operations are not supported, then ASSERT().
776 If StartBit is greater than 63, then ASSERT().
777 If EndBit is greater than 63, then ASSERT().
778 If EndBit is less than StartBit, then ASSERT().
779 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
781 @param Operand Operand on which to perform the bitfield operation.
782 @param StartBit The ordinal of the least significant bit in the bit field.
784 @param EndBit The ordinal of the most significant bit in the bit field.
786 @param OrData The value to OR with the read value from the value
788 @return The new 64-bit value.
803 ASSERT (EndBit
< 64);
804 ASSERT (StartBit
<= EndBit
);
806 // Higher bits in OrData those are not used must be zero.
808 // EndBit - StartBit + 1 might be 64 while the result right shifting 64 on RShiftU64() API is invalid,
809 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
811 ASSERT (RShiftU64 (OrData
, EndBit
- StartBit
) == (RShiftU64 (OrData
, EndBit
- StartBit
) & 1));
813 Value1
= LShiftU64 (OrData
, StartBit
);
814 Value2
= LShiftU64 ((UINT64
) - 2, EndBit
);
816 return Operand
| (Value1
& ~Value2
);
820 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
823 Performs a bitwise AND between the bit field specified by StartBit and EndBit
824 in Operand and the value specified by AndData. All other bits in Operand are
825 preserved. The new 64-bit value is returned.
827 If 64-bit operations are not supported, then ASSERT().
828 If StartBit is greater than 63, then ASSERT().
829 If EndBit is greater than 63, then ASSERT().
830 If EndBit is less than StartBit, then ASSERT().
831 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
833 @param Operand Operand on which to perform the bitfield operation.
834 @param StartBit The ordinal of the least significant bit in the bit field.
836 @param EndBit The ordinal of the most significant bit in the bit field.
838 @param AndData The value to AND with the read value from the value.
840 @return The new 64-bit value.
855 ASSERT (EndBit
< 64);
856 ASSERT (StartBit
<= EndBit
);
858 // Higher bits in AndData those are not used must be zero.
860 // EndBit - StartBit + 1 might be 64 while the right shifting 64 on RShiftU64() API is invalid,
861 // So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
863 ASSERT (RShiftU64 (AndData
, EndBit
- StartBit
) == (RShiftU64 (AndData
, EndBit
- StartBit
) & 1));
865 Value1
= LShiftU64 (~AndData
, StartBit
);
866 Value2
= LShiftU64 ((UINT64
)-2, EndBit
);
868 return Operand
& ~(Value1
& ~Value2
);
872 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
873 bitwise OR, and returns the result.
875 Performs a bitwise AND between the bit field specified by StartBit and EndBit
876 in Operand and the value specified by AndData, followed by a bitwise
877 OR with value specified by OrData. All other bits in Operand are
878 preserved. The new 64-bit value is returned.
880 If 64-bit operations are not supported, then ASSERT().
881 If StartBit is greater than 63, then ASSERT().
882 If EndBit is greater than 63, then ASSERT().
883 If EndBit is less than StartBit, then ASSERT().
884 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
885 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
887 @param Operand Operand on which to perform the bitfield operation.
888 @param StartBit The ordinal of the least significant bit in the bit field.
890 @param EndBit The ordinal of the most significant bit in the bit field.
892 @param AndData The value to AND with the read value from the value.
893 @param OrData The value to OR with the result of the AND operation.
895 @return The new 64-bit value.
900 BitFieldAndThenOr64 (
908 ASSERT (EndBit
< 64);
909 ASSERT (StartBit
<= EndBit
);
910 return BitFieldOr64 (
911 BitFieldAnd64 (Operand
, StartBit
, EndBit
, AndData
),
919 Reads a bit field from a 32-bit value, counts and returns
920 the number of set bits.
922 Counts the number of set bits in the bit field specified by
923 StartBit and EndBit in Operand. The count is returned.
925 If StartBit is greater than 31, then ASSERT().
926 If EndBit is greater than 31, then ASSERT().
927 If EndBit is less than StartBit, then ASSERT().
929 @param Operand Operand on which to perform the bitfield operation.
930 @param StartBit The ordinal of the least significant bit in the bit field.
932 @param EndBit The ordinal of the most significant bit in the bit field.
935 @return The number of bits set between StartBit and EndBit.
940 BitFieldCountOnes32 (
948 ASSERT (EndBit
< 32);
949 ASSERT (StartBit
<= EndBit
);
951 Count
= BitFieldRead32 (Operand
, StartBit
, EndBit
);
952 Count
-= ((Count
>> 1) & 0x55555555);
953 Count
= (Count
& 0x33333333) + ((Count
>> 2) & 0x33333333);
957 Count
+= Count
>> 16;
959 return (UINT8
) Count
& 0x3F;
963 Reads a bit field from a 64-bit value, counts and returns
964 the number of set bits.
966 Counts the number of set bits in the bit field specified by
967 StartBit and EndBit in Operand. The count is returned.
969 If StartBit is greater than 63, then ASSERT().
970 If EndBit is greater than 63, then ASSERT().
971 If EndBit is less than StartBit, then ASSERT().
973 @param Operand Operand on which to perform the bitfield operation.
974 @param StartBit The ordinal of the least significant bit in the bit field.
976 @param EndBit The ordinal of the most significant bit in the bit field.
979 @return The number of bits set between StartBit and EndBit.
984 BitFieldCountOnes64 (
993 ASSERT (EndBit
< 64);
994 ASSERT (StartBit
<= EndBit
);
996 BitField
= BitFieldRead64 (Operand
, StartBit
, EndBit
);
997 Count
= BitFieldCountOnes32 ((UINT32
) BitField
, 0, 31);
998 Count
+= BitFieldCountOnes32 ((UINT32
) RShiftU64(BitField
, 32), 0, 31);