Revision | afe2a9d47840e884707d8b4035ea6d553b4f4536 (tree) |
---|---|
Time | 2019-05-05 23:54:00 |
Author | Yoshinori Sato <ysato@user...> |
Commiter | Yoshinori Sato |
qemu/bitops.h: Add extract8 and extract16
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
@@ -301,6 +301,44 @@ static inline uint32_t extract32(uint32_t value, int start, int length) | ||
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | + * extract8: | |
305 | + * @value: the value to extract the bit field from | |
306 | + * @start: the lowest bit in the bit field (numbered from 0) | |
307 | + * @length: the length of the bit field | |
308 | + * | |
309 | + * Extract from the 8 bit input @value the bit field specified by the | |
310 | + * @start and @length parameters, and return it. The bit field must | |
311 | + * lie entirely within the 8 bit word. It is valid to request that | |
312 | + * all 8 bits are returned (ie @length 8 and @start 0). | |
313 | + * | |
314 | + * Returns: the value of the bit field extracted from the input value. | |
315 | + */ | |
316 | +static inline uint8_t extract8(uint8_t value, int start, int length) | |
317 | +{ | |
318 | + assert(start >= 0 && length > 0 && length <= 8 - start); | |
319 | + return (value >> start) & (~0U >> (32 - length)); | |
320 | +} | |
321 | + | |
322 | +/** | |
323 | + * extract16: | |
324 | + * @value: the value to extract the bit field from | |
325 | + * @start: the lowest bit in the bit field (numbered from 0) | |
326 | + * @length: the length of the bit field | |
327 | + * | |
328 | + * Extract from the 16 bit input @value the bit field specified by the | |
329 | + * @start and @length parameters, and return it. The bit field must | |
330 | + * lie entirely within the 16 bit word. It is valid to request that | |
331 | + * all 16 bits are returned (ie @length 16 and @start 0). | |
332 | + * | |
333 | + * Returns: the value of the bit field extracted from the input value. | |
334 | + */ | |
335 | +static inline uint16_t extract16(uint32_t value, int start, int length) | |
336 | +{ | |
337 | + assert(start >= 0 && length > 0 && length <= 16 - start); | |
338 | + return (value >> start) & (~0U >> (32 - length)); | |
339 | +} | |
340 | + | |
341 | +/** | |
304 | 342 | * extract64: |
305 | 343 | * @value: the value to extract the bit field from |
306 | 344 | * @start: the lowest bit in the bit field (numbered from 0) |