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