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