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