[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4] bitops.h: Add functions to extract and depos
From: |
Lluís Vilanova |
Subject: |
Re: [Qemu-devel] [PATCH v4] bitops.h: Add functions to extract and deposit bitfields |
Date: |
Sun, 08 Jul 2012 12:55:25 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
Peter Maydell writes:
[...]
> +/**
> + * extract32:
> + * @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
> + *
> + * Extract from the 32 bit input @value the bit field specified by the
> + * @start and @length parameters, and return it. The bit field must
> + * lie entirely within the 32 bit word. It is valid to request that
> + * all 32 bits are returned (ie @length 32 and @start 0).
> + *
> + * Returns: the value of the bit field extracted from the input value.
> + */
> +static inline uint32_t extract32(uint32_t value, int start, int length)
> +{
> + assert(start >= 0 && length > 0 && length <= 32 - start);
> + return (value >> start) & (~0U >> (32 - length));
> +}
[...]
Wouldn't it be better to use "unsigned int" instead on all the "start" and
"length" arguments?
Lluis
--
"And it's much the same thing with knowledge, for whenever you learn
something new, the whole world becomes that much richer."
-- The Princess of Pure Reason, as told by Norton Juster in The Phantom
Tollbooth