From patchwork Sun Jul 8 19:22:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 169663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 14F5E2C0217 for ; Mon, 9 Jul 2012 05:23:07 +1000 (EST) Received: from localhost ([::1]:45787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Snx4S-0002uA-Rg for incoming@patchwork.ozlabs.org; Sun, 08 Jul 2012 15:23:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Snx3h-000176-Ob for qemu-devel@nongnu.org; Sun, 08 Jul 2012 15:22:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Snx3f-0003dC-GS for qemu-devel@nongnu.org; Sun, 08 Jul 2012 15:22:17 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:51877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Snx3f-0003ci-4V for qemu-devel@nongnu.org; Sun, 08 Jul 2012 15:22:15 -0400 Received: by eaak12 with SMTP id k12so5466916eaa.4 for ; Sun, 08 Jul 2012 12:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references; bh=5v/FbfdqA0OACwmYRJQum0uZYm25qX0dU7G6MBPxcCg=; b=m/r9gkd96sKoKYaN3PBpOYzcs165LD4CAAM23Z6EYnQX6SiJAiF+NxKXTga/FoASMy RlJ7fNdko3K2QpjhC9dtgiupYZP3AMy4iz0TZ6KXey3HRGtscO86dKuCa0dCKxKqGnlg vohzF9CdrNbuOtL2g7MM1KbjAfNG+kzSim1My0ytI8PY/T1RXQYvbQwnOU2eDwy2S0v+ NDRtegU2B/Q4m0M8AzFBsfneOW6tSEllpLgjYHOvDpvmPMgufNTjO+mc448Nr7yGP7Gw lTV2s4/gJKTA0/Hm49HKIbLdck6iDCAnCdq+rC2b8LAARruVPQCM6pj5Yl2aOD+ZLvU1 +d0g== Received: by 10.14.37.69 with SMTP id x45mr9048418eea.48.1341775333108; Sun, 08 Jul 2012 12:22:13 -0700 (PDT) Received: from localhost.localdomain (blueswirl.broker.freenet6.net. [2001:5c0:1400:b::d5a3]) by mx.google.com with ESMTPS id x52sm87679565eea.11.2012.07.08.12.22.11 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 08 Jul 2012 12:22:12 -0700 (PDT) From: blauwirbel@gmail.com To: qemu-devel@nongnu.org Date: Sun, 8 Jul 2012 19:22:31 +0000 Message-Id: X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.215.173 Cc: blueswirl@gmail.com Subject: [Qemu-devel] [PATCH v2 1/3] bitops: fix types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Blue Swirl Use 'unsigned int' for bit numbers instead of 'unsigned long' or 'int'. Adjust asserts. Signed-off-by: Blue Swirl --- bitops.h | 46 ++++++++++++++++++++++++++-------------------- 1 files changed, 26 insertions(+), 20 deletions(-) diff --git a/bitops.h b/bitops.h index b967ef3..f6ac721 100644 --- a/bitops.h +++ b/bitops.h @@ -28,7 +28,7 @@ * * Undefined if no bit exists, so code should check against 0 first. */ -static unsigned long bitops_ffsl(unsigned long word) +static unsigned int bitops_ffsl(unsigned long word) { int num = 0; @@ -66,7 +66,7 @@ static unsigned long bitops_ffsl(unsigned long word) * * Undefined if no set bit exists, so code should check against 0 first. */ -static inline unsigned long bitops_flsl(unsigned long word) +static inline unsigned int bitops_flsl(unsigned long word) { int num = BITS_PER_LONG - 1; @@ -104,7 +104,7 @@ static inline unsigned long bitops_flsl(unsigned long word) * * Undefined if no zero exists, so code should check against ~0UL first. */ -static inline unsigned long ffz(unsigned long word) +static inline unsigned int ffz(unsigned long word) { return bitops_ffsl(~word); } @@ -114,7 +114,7 @@ static inline unsigned long ffz(unsigned long word) * @nr: the bit to set * @addr: the address to start counting from */ -static inline void set_bit(int nr, volatile unsigned long *addr) +static inline void set_bit(unsigned int nr, volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); @@ -127,7 +127,7 @@ static inline void set_bit(int nr, volatile unsigned long *addr) * @nr: Bit to clear * @addr: Address to start counting from */ -static inline void clear_bit(int nr, volatile unsigned long *addr) +static inline void clear_bit(unsigned int nr, volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); @@ -140,7 +140,7 @@ static inline void clear_bit(int nr, volatile unsigned long *addr) * @nr: Bit to change * @addr: Address to start counting from */ -static inline void change_bit(int nr, volatile unsigned long *addr) +static inline void change_bit(unsigned int nr, volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); @@ -153,7 +153,8 @@ static inline void change_bit(int nr, volatile unsigned long *addr) * @nr: Bit to set * @addr: Address to count from */ -static inline int test_and_set_bit(int nr, volatile unsigned long *addr) +static inline int test_and_set_bit(unsigned int nr, + volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); @@ -168,7 +169,8 @@ static inline int test_and_set_bit(int nr, volatile unsigned long *addr) * @nr: Bit to clear * @addr: Address to count from */ -static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) +static inline int test_and_clear_bit(unsigned int nr, + volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); @@ -183,7 +185,8 @@ static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) * @nr: Bit to change * @addr: Address to count from */ -static inline int test_and_change_bit(int nr, volatile unsigned long *addr) +static inline int test_and_change_bit(unsigned int nr, + volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); @@ -198,7 +201,8 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr) * @nr: bit number to test * @addr: Address to start counting from */ -static inline int test_bit(int nr, const volatile unsigned long *addr) +static inline int test_bit(unsigned int nr, + const volatile unsigned long *addr) { return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); } @@ -282,9 +286,10 @@ static inline unsigned long hweight_long(unsigned long w) * * Returns: the value of the bit field extracted from the input value. */ -static inline uint32_t extract32(uint32_t value, int start, int length) +static inline uint32_t extract32(uint32_t value, unsigned int start, + unsigned int length) { - assert(start >= 0 && length > 0 && length <= 32 - start); + assert(start < 32 && length > 0 && length <= 32 && start + length <= 32); return (value >> start) & (~0U >> (32 - length)); } @@ -301,9 +306,10 @@ static inline uint32_t extract32(uint32_t value, int start, int length) * * Returns: the value of the bit field extracted from the input value. */ -static inline uint64_t extract64(uint64_t value, int start, int length) +static inline uint64_t extract64(uint64_t value, unsigned int start, + unsigned int length) { - assert(start >= 0 && length > 0 && length <= 64 - start); + assert(start < 64 && length > 0 && length <= 64 && start + length <= 64); return (value >> start) & (~0ULL >> (64 - length)); } @@ -324,11 +330,11 @@ static inline uint64_t extract64(uint64_t value, int start, int length) * * Returns: the modified @value. */ -static inline uint32_t deposit32(uint32_t value, int start, int length, - uint32_t fieldval) +static inline uint32_t deposit32(uint32_t value, unsigned int start, + unsigned int length, uint32_t fieldval) { uint32_t mask; - assert(start >= 0 && length > 0 && length <= 32 - start); + assert(start < 32 && length > 0 && length <= 32 && start + length <= 32); mask = (~0U >> (32 - length)) << start; return (value & ~mask) | ((fieldval << start) & mask); } @@ -350,11 +356,11 @@ static inline uint32_t deposit32(uint32_t value, int start, int length, * * Returns: the modified @value. */ -static inline uint64_t deposit64(uint64_t value, int start, int length, - uint64_t fieldval) +static inline uint64_t deposit64(uint64_t value, unsigned int start, + unsigned int length, uint64_t fieldval) { uint64_t mask; - assert(start >= 0 && length > 0 && length <= 64 - start); + assert(start < 64 && length > 0 && length <= 64 && start + length <= 64); mask = (~0ULL >> (64 - length)) << start; return (value & ~mask) | ((fieldval << start) & mask); }