]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/BitField.c
Added BuildTarget with enumerated data type (DEBUG|RELEASE|BOTH) to the PlatformHeade...
[mirror_edk2.git] / MdePkg / Library / BaseLib / BitField.c
1 /** @file
2 Bit field functions of BaseLib.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. 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
9
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.
12
13 Module Name: BitField.c
14
15 **/
16
17 unsigned int
18 EFIAPI
19 BitFieldReadUint (
20 IN unsigned int Operand,
21 IN UINTN StartBit,
22 IN UINTN EndBit
23 )
24 {
25 //
26 // ~((unsigned int)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
27 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
28 //
29 return (Operand & ~((unsigned int)-2 << EndBit)) >> StartBit;
30 }
31
32 unsigned int
33 EFIAPI
34 BitFieldOrUint (
35 IN unsigned int Operand,
36 IN UINTN StartBit,
37 IN UINTN EndBit,
38 IN unsigned int OrData
39 )
40 {
41 //
42 // ~((unsigned int)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
43 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
44 //
45 return Operand | ((OrData << StartBit) & ~((unsigned int)-2 << EndBit));
46 }
47
48 unsigned int
49 EFIAPI
50 BitFieldAndUint (
51 IN unsigned int Operand,
52 IN UINTN StartBit,
53 IN UINTN EndBit,
54 IN unsigned int AndData
55 )
56 {
57 //
58 // ~((unsigned int)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
59 // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
60 //
61 return Operand & ~((~AndData << StartBit) & ~((unsigned int)-2 << EndBit));
62 }
63
64 /**
65 Returns a bit field from an 8-bit value.
66
67 Returns the bitfield specified by the StartBit and the EndBit from Operand.
68
69 If 8-bit operations are not supported, then ASSERT().
70 If StartBit is greater than 7, then ASSERT().
71 If EndBit is greater than 7, then ASSERT().
72 If EndBit is less than or equal to StartBit, then ASSERT().
73
74 @param Operand Operand on which to perform the bitfield operation.
75 @param StartBit The ordinal of the least significant bit in the bit field.
76 Range 0..7.
77 @param EndBit The ordinal of the most significant bit in the bit field.
78 Range 0..7.
79
80 @return The bit field read.
81
82 **/
83 UINT8
84 EFIAPI
85 BitFieldRead8 (
86 IN UINT8 Operand,
87 IN UINTN StartBit,
88 IN UINTN EndBit
89 )
90 {
91 ASSERT (EndBit < sizeof (Operand) * 8);
92 ASSERT (StartBit <= EndBit);
93 return (UINT8)BitFieldReadUint (Operand, StartBit, EndBit);
94 }
95
96 /**
97 Writes a bit field to an 8-bit value, and returns the result.
98
99 Writes Value to the bit field specified by the StartBit and the EndBit in
100 Operand. All other bits in Operand are preserved. The new 8-bit value is
101 returned.
102
103 If 8-bit operations are not supported, then ASSERT().
104 If StartBit is greater than 7, then ASSERT().
105 If EndBit is greater than 7, then ASSERT().
106 If EndBit is less than or equal to StartBit, then ASSERT().
107
108 @param Operand Operand on which to perform the bitfield operation.
109 @param StartBit The ordinal of the least significant bit in the bit field.
110 Range 0..7.
111 @param EndBit The ordinal of the most significant bit in the bit field.
112 Range 0..7.
113 @param Value New value of the bit field.
114
115 @return The new 8-bit value.
116
117 **/
118 UINT8
119 EFIAPI
120 BitFieldWrite8 (
121 IN UINT8 Operand,
122 IN UINTN StartBit,
123 IN UINTN EndBit,
124 IN UINT8 Value
125 )
126 {
127 ASSERT (EndBit < sizeof (Operand) * 8);
128 ASSERT (StartBit <= EndBit);
129 return BitFieldAndThenOr8 (Operand, StartBit, EndBit, 0, Value);
130 }
131
132 /**
133 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
134 result.
135
136 Performs a bitwise inclusive OR between the bit field specified by StartBit
137 and EndBit in Operand and the value specified by OrData. All other bits in
138 Operand are preserved. The new 8-bit value is returned.
139
140 If 8-bit operations are not supported, then ASSERT().
141 If StartBit is greater than 7, then ASSERT().
142 If EndBit is greater than 7, then ASSERT().
143 If EndBit is less than or equal to StartBit, then ASSERT().
144
145 @param Operand Operand on which to perform the bitfield operation.
146 @param StartBit The ordinal of the least significant bit in the bit field.
147 Range 0..7.
148 @param EndBit The ordinal of the most significant bit in the bit field.
149 Range 0..7.
150 @param OrData The value to OR with the read value from the value
151
152 @return The new 8-bit value.
153
154 **/
155 UINT8
156 EFIAPI
157 BitFieldOr8 (
158 IN UINT8 Operand,
159 IN UINTN StartBit,
160 IN UINTN EndBit,
161 IN UINT8 OrData
162 )
163 {
164 ASSERT (EndBit < sizeof (Operand) * 8);
165 ASSERT (StartBit <= EndBit);
166 return (UINT8)BitFieldOrUint (Operand, StartBit, EndBit, OrData);
167 }
168
169 /**
170 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
171 the result.
172
173 Performs a bitwise AND between the bit field specified by StartBit and EndBit
174 in Operand and the value specified by AndData. All other bits in Operand are
175 preserved. The new 8-bit value is returned.
176
177 If 8-bit operations are not supported, then ASSERT().
178 If StartBit is greater than 7, then ASSERT().
179 If EndBit is greater than 7, then ASSERT().
180 If EndBit is less than or equal to StartBit, then ASSERT().
181
182 @param Operand Operand on which to perform the bitfield operation.
183 @param StartBit The ordinal of the least significant bit in the bit field.
184 Range 0..7.
185 @param EndBit The ordinal of the most significant bit in the bit field.
186 Range 0..7.
187 @param AndData The value to AND with the read value from the value.
188
189 @return The new 8-bit value.
190
191 **/
192 UINT8
193 EFIAPI
194 BitFieldAnd8 (
195 IN UINT8 Operand,
196 IN UINTN StartBit,
197 IN UINTN EndBit,
198 IN UINT8 AndData
199 )
200 {
201 ASSERT (EndBit < sizeof (Operand) * 8);
202 ASSERT (StartBit <= EndBit);
203 return (UINT8)BitFieldAndUint (Operand, StartBit, EndBit, AndData);
204 }
205
206 /**
207 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
208 bitwise OR, and returns the result.
209
210 Performs a bitwise AND between the bit field specified by StartBit and EndBit
211 in Operand and the value specified by AndData, followed by a bitwise
212 inclusive OR with value specified by OrData. All other bits in Operand are
213 preserved. The new 8-bit value is returned.
214
215 If 8-bit operations are not supported, then ASSERT().
216 If StartBit is greater than 7, then ASSERT().
217 If EndBit is greater than 7, then ASSERT().
218 If EndBit is less than or equal to StartBit, then ASSERT().
219
220 @param Operand Operand on which to perform the bitfield operation.
221 @param StartBit The ordinal of the least significant bit in the bit field.
222 Range 0..7.
223 @param EndBit The ordinal of the most significant bit in the bit field.
224 Range 0..7.
225 @param AndData The value to AND with the read value from the value.
226 @param OrData The value to OR with the result of the AND operation.
227
228 @return The new 8-bit value.
229
230 **/
231 UINT8
232 EFIAPI
233 BitFieldAndThenOr8 (
234 IN UINT8 Operand,
235 IN UINTN StartBit,
236 IN UINTN EndBit,
237 IN UINT8 AndData,
238 IN UINT8 OrData
239 )
240 {
241 ASSERT (EndBit < sizeof (Operand) * 8);
242 ASSERT (StartBit <= EndBit);
243 return BitFieldOr8 (
244 BitFieldAnd8 (Operand, StartBit, EndBit, AndData),
245 StartBit,
246 EndBit,
247 OrData
248 );
249 }
250
251 /**
252 Returns a bit field from a 16-bit value.
253
254 Returns the bitfield specified by the StartBit and the EndBit from Operand.
255
256 If 16-bit operations are not supported, then ASSERT().
257 If StartBit is greater than 15, then ASSERT().
258 If EndBit is greater than 15, then ASSERT().
259 If EndBit is less than or equal to StartBit, then ASSERT().
260
261 @param Operand Operand on which to perform the bitfield operation.
262 @param StartBit The ordinal of the least significant bit in the bit field.
263 Range 0..15.
264 @param EndBit The ordinal of the most significant bit in the bit field.
265 Range 0..15.
266
267 @return The bit field read.
268
269 **/
270 UINT16
271 EFIAPI
272 BitFieldRead16 (
273 IN UINT16 Operand,
274 IN UINTN StartBit,
275 IN UINTN EndBit
276 )
277 {
278 ASSERT (EndBit < sizeof (Operand) * 8);
279 ASSERT (StartBit <= EndBit);
280 return (UINT16)BitFieldReadUint (Operand, StartBit, EndBit);
281 }
282
283 /**
284 Writes a bit field to a 16-bit value, and returns the result.
285
286 Writes Value to the bit field specified by the StartBit and the EndBit in
287 Operand. All other bits in Operand are preserved. The new 16-bit value is
288 returned.
289
290 If 16-bit operations are not supported, then ASSERT().
291 If StartBit is greater than 15, then ASSERT().
292 If EndBit is greater than 15, then ASSERT().
293 If EndBit is less than or equal to StartBit, then ASSERT().
294
295 @param Operand Operand on which to perform the bitfield operation.
296 @param StartBit The ordinal of the least significant bit in the bit field.
297 Range 0..15.
298 @param EndBit The ordinal of the most significant bit in the bit field.
299 Range 0..15.
300 @param Value New value of the bit field.
301
302 @return The new 16-bit value.
303
304 **/
305 UINT16
306 EFIAPI
307 BitFieldWrite16 (
308 IN UINT16 Operand,
309 IN UINTN StartBit,
310 IN UINTN EndBit,
311 IN UINT16 Value
312 )
313 {
314 ASSERT (EndBit < sizeof (Operand) * 8);
315 ASSERT (StartBit <= EndBit);
316 return BitFieldAndThenOr16 (Operand, StartBit, EndBit, 0, Value);
317 }
318
319 /**
320 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
321 result.
322
323 Performs a bitwise inclusive OR between the bit field specified by StartBit
324 and EndBit in Operand and the value specified by OrData. All other bits in
325 Operand are preserved. The new 16-bit value is returned.
326
327 If 16-bit operations are not supported, then ASSERT().
328 If StartBit is greater than 15, then ASSERT().
329 If EndBit is greater than 15, then ASSERT().
330 If EndBit is less than or equal to StartBit, then ASSERT().
331
332 @param Operand Operand on which to perform the bitfield operation.
333 @param StartBit The ordinal of the least significant bit in the bit field.
334 Range 0..15.
335 @param EndBit The ordinal of the most significant bit in the bit field.
336 Range 0..15.
337 @param OrData The value to OR with the read value from the value
338
339 @return The new 16-bit value.
340
341 **/
342 UINT16
343 EFIAPI
344 BitFieldOr16 (
345 IN UINT16 Operand,
346 IN UINTN StartBit,
347 IN UINTN EndBit,
348 IN UINT16 OrData
349 )
350 {
351 ASSERT (EndBit < sizeof (Operand) * 8);
352 ASSERT (StartBit <= EndBit);
353 return (UINT16)BitFieldOrUint (Operand, StartBit, EndBit, OrData);
354 }
355
356 /**
357 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
358 the result.
359
360 Performs a bitwise AND between the bit field specified by StartBit and EndBit
361 in Operand and the value specified by AndData. All other bits in Operand are
362 preserved. The new 16-bit value is returned.
363
364 If 16-bit operations are not supported, then ASSERT().
365 If StartBit is greater than 15, then ASSERT().
366 If EndBit is greater than 15, then ASSERT().
367 If EndBit is less than or equal to StartBit, then ASSERT().
368
369 @param Operand Operand on which to perform the bitfield operation.
370 @param StartBit The ordinal of the least significant bit in the bit field.
371 Range 0..15.
372 @param EndBit The ordinal of the most significant bit in the bit field.
373 Range 0..15.
374 @param AndData The value to AND with the read value from the value
375
376 @return The new 16-bit value.
377
378 **/
379 UINT16
380 EFIAPI
381 BitFieldAnd16 (
382 IN UINT16 Operand,
383 IN UINTN StartBit,
384 IN UINTN EndBit,
385 IN UINT16 AndData
386 )
387 {
388 ASSERT (EndBit < sizeof (Operand) * 8);
389 ASSERT (StartBit <= EndBit);
390 return (UINT16)BitFieldAndUint (Operand, StartBit, EndBit, AndData);
391 }
392
393 /**
394 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
395 bitwise OR, and returns the result.
396
397 Performs a bitwise AND between the bit field specified by StartBit and EndBit
398 in Operand and the value specified by AndData, followed by a bitwise
399 inclusive OR with value specified by OrData. All other bits in Operand are
400 preserved. The new 16-bit value is returned.
401
402 If 16-bit operations are not supported, then ASSERT().
403 If StartBit is greater than 15, then ASSERT().
404 If EndBit is greater than 15, then ASSERT().
405 If EndBit is less than or equal to StartBit, then ASSERT().
406
407 @param Operand Operand on which to perform the bitfield operation.
408 @param StartBit The ordinal of the least significant bit in the bit field.
409 Range 0..15.
410 @param EndBit The ordinal of the most significant bit in the bit field.
411 Range 0..15.
412 @param AndData The value to AND with the read value from the value.
413 @param OrData The value to OR with the result of the AND operation.
414
415 @return The new 16-bit value.
416
417 **/
418 UINT16
419 EFIAPI
420 BitFieldAndThenOr16 (
421 IN UINT16 Operand,
422 IN UINTN StartBit,
423 IN UINTN EndBit,
424 IN UINT16 AndData,
425 IN UINT16 OrData
426 )
427 {
428 ASSERT (EndBit < sizeof (Operand) * 8);
429 ASSERT (StartBit <= EndBit);
430 return BitFieldOr16 (
431 BitFieldAnd16 (Operand, StartBit, EndBit, AndData),
432 StartBit,
433 EndBit,
434 OrData
435 );
436 }
437
438 /**
439 Returns a bit field from a 32-bit value.
440
441 Returns the bitfield specified by the StartBit and the EndBit from Operand.
442
443 If 32-bit operations are not supported, then ASSERT().
444 If StartBit is greater than 31, then ASSERT().
445 If EndBit is greater than 31, then ASSERT().
446 If EndBit is less than or equal to StartBit, then ASSERT().
447
448 @param Operand Operand on which to perform the bitfield operation.
449 @param StartBit The ordinal of the least significant bit in the bit field.
450 Range 0..31.
451 @param EndBit The ordinal of the most significant bit in the bit field.
452 Range 0..31.
453
454 @return The bit field read.
455
456 **/
457 UINT32
458 EFIAPI
459 BitFieldRead32 (
460 IN UINT32 Operand,
461 IN UINTN StartBit,
462 IN UINTN EndBit
463 )
464 {
465 ASSERT (EndBit < sizeof (Operand) * 8);
466 ASSERT (StartBit <= EndBit);
467 return (UINT32)BitFieldReadUint (Operand, StartBit, EndBit);
468 }
469
470 /**
471 Writes a bit field to a 32-bit value, and returns the result.
472
473 Writes Value to the bit field specified by the StartBit and the EndBit in
474 Operand. All other bits in Operand are preserved. The new 32-bit value is
475 returned.
476
477 If 32-bit operations are not supported, then ASSERT().
478 If StartBit is greater than 31, then ASSERT().
479 If EndBit is greater than 31, then ASSERT().
480 If EndBit is less than or equal to StartBit, then ASSERT().
481
482 @param Operand Operand on which to perform the bitfield operation.
483 @param StartBit The ordinal of the least significant bit in the bit field.
484 Range 0..31.
485 @param EndBit The ordinal of the most significant bit in the bit field.
486 Range 0..31.
487 @param Value New value of the bit field.
488
489 @return The new 32-bit value.
490
491 **/
492 UINT32
493 EFIAPI
494 BitFieldWrite32 (
495 IN UINT32 Operand,
496 IN UINTN StartBit,
497 IN UINTN EndBit,
498 IN UINT32 Value
499 )
500 {
501 ASSERT (EndBit < sizeof (Operand) * 8);
502 ASSERT (StartBit <= EndBit);
503 return BitFieldAndThenOr32 (Operand, StartBit, EndBit, 0, Value);
504 }
505
506 /**
507 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
508 result.
509
510 Performs a bitwise inclusive OR between the bit field specified by StartBit
511 and EndBit in Operand and the value specified by OrData. All other bits in
512 Operand are preserved. The new 32-bit value is returned.
513
514 If 32-bit operations are not supported, then ASSERT().
515 If StartBit is greater than 31, then ASSERT().
516 If EndBit is greater than 31, then ASSERT().
517 If EndBit is less than or equal to StartBit, then ASSERT().
518
519 @param Operand Operand on which to perform the bitfield operation.
520 @param StartBit The ordinal of the least significant bit in the bit field.
521 Range 0..31.
522 @param EndBit The ordinal of the most significant bit in the bit field.
523 Range 0..31.
524 @param OrData The value to OR with the read value from the value
525
526 @return The new 32-bit value.
527
528 **/
529 UINT32
530 EFIAPI
531 BitFieldOr32 (
532 IN UINT32 Operand,
533 IN UINTN StartBit,
534 IN UINTN EndBit,
535 IN UINT32 OrData
536 )
537 {
538 ASSERT (EndBit < sizeof (Operand) * 8);
539 ASSERT (StartBit <= EndBit);
540 return (UINT32)BitFieldOrUint (Operand, StartBit, EndBit, OrData);
541 }
542
543 /**
544 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
545 the result.
546
547 Performs a bitwise AND between the bit field specified by StartBit and EndBit
548 in Operand and the value specified by AndData. All other bits in Operand are
549 preserved. The new 32-bit value is returned.
550
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 or equal to StartBit, then ASSERT().
555
556 @param Operand Operand on which to perform the bitfield operation.
557 @param StartBit The ordinal of the least significant bit in the bit field.
558 Range 0..31.
559 @param EndBit The ordinal of the most significant bit in the bit field.
560 Range 0..31.
561 @param AndData The value to AND with the read value from the value
562
563 @return The new 32-bit value.
564
565 **/
566 UINT32
567 EFIAPI
568 BitFieldAnd32 (
569 IN UINT32 Operand,
570 IN UINTN StartBit,
571 IN UINTN EndBit,
572 IN UINT32 AndData
573 )
574 {
575 ASSERT (EndBit < sizeof (Operand) * 8);
576 ASSERT (StartBit <= EndBit);
577 return (UINT32)BitFieldAndUint (Operand, StartBit, EndBit, AndData);
578 }
579
580 /**
581 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
582 bitwise OR, and returns the result.
583
584 Performs a bitwise AND between the bit field specified by StartBit and EndBit
585 in Operand and the value specified by AndData, followed by a bitwise
586 inclusive OR with value specified by OrData. All other bits in Operand are
587 preserved. The new 32-bit value is returned.
588
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 or equal to StartBit, then ASSERT().
593
594 @param Operand Operand on which to perform the bitfield operation.
595 @param StartBit The ordinal of the least significant bit in the bit field.
596 Range 0..31.
597 @param EndBit The ordinal of the most significant bit in the bit field.
598 Range 0..31.
599 @param AndData The value to AND with the read value from the value.
600 @param OrData The value to OR with the result of the AND operation.
601
602 @return The new 32-bit value.
603
604 **/
605 UINT32
606 EFIAPI
607 BitFieldAndThenOr32 (
608 IN UINT32 Operand,
609 IN UINTN StartBit,
610 IN UINTN EndBit,
611 IN UINT32 AndData,
612 IN UINT32 OrData
613 )
614 {
615 ASSERT (EndBit < sizeof (Operand) * 8);
616 ASSERT (StartBit <= EndBit);
617 return BitFieldOr32 (
618 BitFieldAnd32 (Operand, StartBit, EndBit, AndData),
619 StartBit,
620 EndBit,
621 OrData
622 );
623 }
624
625 /**
626 Returns a bit field from a 64-bit value.
627
628 Returns the bitfield specified by the StartBit and the EndBit from Operand.
629
630 If 64-bit operations are not supported, then ASSERT().
631 If StartBit is greater than 63, then ASSERT().
632 If EndBit is greater than 63, then ASSERT().
633 If EndBit is less than or equal to StartBit, then ASSERT().
634
635 @param Operand Operand on which to perform the bitfield operation.
636 @param StartBit The ordinal of the least significant bit in the bit field.
637 Range 0..63.
638 @param EndBit The ordinal of the most significant bit in the bit field.
639 Range 0..63.
640
641 @return The bit field read.
642
643 **/
644 UINT64
645 EFIAPI
646 BitFieldRead64 (
647 IN UINT64 Operand,
648 IN UINTN StartBit,
649 IN UINTN EndBit
650 )
651 {
652 ASSERT (EndBit < sizeof (Operand) * 8);
653 ASSERT (StartBit <= EndBit);
654 return RShiftU64 (Operand & ~LShiftU64 ((UINT64)-2, EndBit), StartBit);
655 }
656
657 /**
658 Writes a bit field to a 64-bit value, and returns the result.
659
660 Writes Value to the bit field specified by the StartBit and the EndBit in
661 Operand. All other bits in Operand are preserved. The new 64-bit value is
662 returned.
663
664 If 64-bit operations are not supported, then ASSERT().
665 If StartBit is greater than 63, then ASSERT().
666 If EndBit is greater than 63, then ASSERT().
667 If EndBit is less than or equal to StartBit, then ASSERT().
668
669 @param Operand Operand on which to perform the bitfield operation.
670 @param StartBit The ordinal of the least significant bit in the bit field.
671 Range 0..63.
672 @param EndBit The ordinal of the most significant bit in the bit field.
673 Range 0..63.
674 @param Value New value of the bit field.
675
676 @return The new 64-bit value.
677
678 **/
679 UINT64
680 EFIAPI
681 BitFieldWrite64 (
682 IN UINT64 Operand,
683 IN UINTN StartBit,
684 IN UINTN EndBit,
685 IN UINT64 Value
686 )
687 {
688 ASSERT (EndBit < sizeof (Operand) * 8);
689 ASSERT (StartBit <= EndBit);
690 return BitFieldAndThenOr64 (Operand, StartBit, EndBit, 0, Value);
691 }
692
693 /**
694 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
695 result.
696
697 Performs a bitwise inclusive OR between the bit field specified by StartBit
698 and EndBit in Operand and the value specified by OrData. All other bits in
699 Operand are preserved. The new 64-bit value is returned.
700
701 If 64-bit operations are not supported, then ASSERT().
702 If StartBit is greater than 63, then ASSERT().
703 If EndBit is greater than 63, then ASSERT().
704 If EndBit is less than or equal to StartBit, then ASSERT().
705
706 @param Operand Operand on which to perform the bitfield operation.
707 @param StartBit The ordinal of the least significant bit in the bit field.
708 Range 0..63.
709 @param EndBit The ordinal of the most significant bit in the bit field.
710 Range 0..63.
711 @param OrData The value to OR with the read value from the value
712
713 @return The new 64-bit value.
714
715 **/
716 UINT64
717 EFIAPI
718 BitFieldOr64 (
719 IN UINT64 Operand,
720 IN UINTN StartBit,
721 IN UINTN EndBit,
722 IN UINT64 OrData
723 )
724 {
725 ASSERT (EndBit < sizeof (Operand) * 8);
726 ASSERT (StartBit <= EndBit);
727 return Operand |
728 (LShiftU64 (OrData, StartBit) & ~LShiftU64 ((UINT64)-2, EndBit));
729 }
730
731 /**
732 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
733 the result.
734
735 Performs a bitwise AND between the bit field specified by StartBit and EndBit
736 in Operand and the value specified by AndData. All other bits in Operand are
737 preserved. The new 64-bit value is returned.
738
739 If 64-bit operations are not supported, then ASSERT().
740 If StartBit is greater than 63, then ASSERT().
741 If EndBit is greater than 63, then ASSERT().
742 If EndBit is less than or equal to StartBit, then ASSERT().
743
744 @param Operand Operand on which to perform the bitfield operation.
745 @param StartBit The ordinal of the least significant bit in the bit field.
746 Range 0..63.
747 @param EndBit The ordinal of the most significant bit in the bit field.
748 Range 0..63.
749 @param AndData The value to AND with the read value from the value
750
751 @return The new 64-bit value.
752
753 **/
754 UINT64
755 EFIAPI
756 BitFieldAnd64 (
757 IN UINT64 Operand,
758 IN UINTN StartBit,
759 IN UINTN EndBit,
760 IN UINT64 AndData
761 )
762 {
763 ASSERT (EndBit < sizeof (Operand) * 8);
764 ASSERT (StartBit <= EndBit);
765 return Operand &
766 ~(LShiftU64 (~AndData, StartBit) & ~LShiftU64 ((UINT64)-2, EndBit));
767 }
768
769 /**
770 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
771 bitwise OR, and returns the result.
772
773 Performs a bitwise AND between the bit field specified by StartBit and EndBit
774 in Operand and the value specified by AndData, followed by a bitwise
775 inclusive OR with value specified by OrData. All other bits in Operand are
776 preserved. The new 64-bit value is returned.
777
778 If 64-bit operations are not supported, then ASSERT().
779 If StartBit is greater than 63, then ASSERT().
780 If EndBit is greater than 63, then ASSERT().
781 If EndBit is less than or equal to StartBit, then ASSERT().
782
783 @param Operand Operand on which to perform the bitfield operation.
784 @param StartBit The ordinal of the least significant bit in the bit field.
785 Range 0..63.
786 @param EndBit The ordinal of the most significant bit in the bit field.
787 Range 0..63.
788 @param AndData The value to AND with the read value from the value.
789 @param OrData The value to OR with the result of the AND operation.
790
791 @return The new 64-bit value.
792
793 **/
794 UINT64
795 EFIAPI
796 BitFieldAndThenOr64 (
797 IN UINT64 Operand,
798 IN UINTN StartBit,
799 IN UINTN EndBit,
800 IN UINT64 AndData,
801 IN UINT64 OrData
802 )
803 {
804 ASSERT (EndBit < sizeof (Operand) * 8);
805 ASSERT (StartBit <= EndBit);
806 return BitFieldOr64 (
807 BitFieldAnd64 (Operand, StartBit, EndBit, AndData),
808 StartBit,
809 EndBit,
810 OrData
811 );
812 }