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