qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] bitops.h: Add field32() and field64() functi


From: Andreas Färber
Subject: Re: [Qemu-devel] [PATCH v2] bitops.h: Add field32() and field64() functions to extract bitfields
Date: Wed, 27 Jun 2012 13:29:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0

Am 27.06.2012 12:29, schrieb Peter Maydell:
> 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>
> ---
> v1->v2: added missing brackets to field32() to bring it in to line
>         with field64()
> (Still using 'int' rather than 'unsigned' for bit numbers as per
> rationale in previous discussion.)

Reviewed-by: Andreas Färber <address@hidden>

Do you have followup patches that make use of this? Might illustrate
what variables and types are being passed in.

/-F

> 
>  bitops.h |   28 ++++++++++++++++++++++++++++
>  1 files changed, 28 insertions(+), 0 deletions(-)
> 
> diff --git a/bitops.h b/bitops.h
> index 07d1a06..ffbb387 100644
> --- a/bitops.h
> +++ b/bitops.h
> @@ -269,4 +269,32 @@ static inline unsigned long hweight_long(unsigned long w)
>      return count;
>  }
>  
> +/**
> + * field64 - return a specified bit field from a uint64_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 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

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]