リビジョン | de5b40cb8ebe1e60b9908dab7d64cc5b0657e09a (tree) |
---|---|
日時 | 2019-06-16 22:31:41 |
作者 | Yoshinori Sato <ysato@user...> |
コミッター | Yoshinori Sato |
qemu/bitops.h: Add extract8 and extract16
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20190607091116.49044-10-ysato@users.sourceforge.jp>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
@@ -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 extract32(value, start, 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(uint16_t value, int start, int length) | |
336 | +{ | |
337 | + assert(start >= 0 && length > 0 && length <= 16 - start); | |
338 | + return extract32(value, start, 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) |