Received: from eggs.gnu.org ([208.118.235.92]:54050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnoDH-0004Fu-5S for qemu-devel@nongnu.org; Sun, 08 Jul 2012 05:55:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SnoDF-0003tk-El for qemu-devel@nongnu.org; Sun, 08 Jul 2012 05:55:34 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:42935 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnoDF-0003s7-4F for qemu-devel@nongnu.org; Sun, 08 Jul 2012 05:55:33 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <1341586080-24117-1-git-send-email-peter.maydell@linaro.org> Date: Sun, 08 Jul 2012 12:55:25 +0300 In-Reply-To: <1341586080-24117-1-git-send-email-peter.maydell@linaro.org> (Peter Maydell's message of "Fri, 6 Jul 2012 15:48:00 +0100") Message-ID: <87mx3ak25u.fsf@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v4] bitops.h: Add functions to extract and deposit bitfields List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Jia Liu , patches@linaro.org, qemu-devel@nongnu.org, Blue Swirl , Avi Kivity , Eric Blake , Andreas =?utf-8?Q?F=C3=A4rber?= 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