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