[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions
From: |
malc |
Subject: |
Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields |
Date: |
Tue, 26 Jun 2012 00:26:27 +0400 (MSK) |
User-agent: |
Alpine 2.00 (LNX 1167 2008-08-23) |
On Mon, 25 Jun 2012, Peter Maydell wrote:
> Add field32() and field64() functions which extract a particular
> bit field from a word and return it. Based on an idea by Jia Liu.
>
> Suggested-by: Jia Liu <address@hidden>
> Signed-off-by: Peter Maydell <address@hidden>
> ---
[..snip..]
> +static inline uint64_t field64(uint64_t value, int start, int length)
> +{
> + assert(start >= 0 && start <= 63 && length > 0 && start + length <= 64);
> + return (value >> start) & (~0ULL >> (64 - length));
> +}
> +
> +/**
> + * field32 - return a specified bit field from a uint32_t value
> + * @value: The value to extract the bit field from
> + * @start: The lowest bit in the bit field (numbered from 0)
> + * @length: The length of the bit field
> + *
> + * Returns the value of the bit field extracted from the input value.
> + */
> +static inline uint32_t field32(uint32_t value, int start, int length)
> +{
> + assert(start >= 0 && start <= 31 && length > 0 && start + length <= 32);
> + return (value >> start) & ~0U >> (32 - length);
> +}
> +
> #endif
>
The field32 and field64 are inconsistent w.r.t. grouping, while both are
correct, one has to go through precedence list mentally in the latter
case.
--
mailto:address@hidden
- [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Peter Maydell, 2012/06/25
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields,
malc <=
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Blue Swirl, 2012/06/26
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Peter Maydell, 2012/06/26
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Blue Swirl, 2012/06/26
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Peter Maydell, 2012/06/26
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Blue Swirl, 2012/06/26
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Markus Armbruster, 2012/06/27
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Blue Swirl, 2012/06/27
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Markus Armbruster, 2012/06/28
- Re: [Qemu-devel] [PATCH] bitops.h: Add field32() and field64() functions to extract bitfields, Blue Swirl, 2012/06/28