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