From patchwork Thu Feb 9 02:18:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Thierry X-Patchwork-Id: 9563891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E7A560236 for ; Thu, 9 Feb 2017 02:18:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C42A284BA for ; Thu, 9 Feb 2017 02:18:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 512BF28512; Thu, 9 Feb 2017 02:18:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E7F6A28517 for ; Thu, 9 Feb 2017 02:18:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 35C776E9FB; Thu, 9 Feb 2017 02:18:30 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id A63D16E9F6 for ; Thu, 9 Feb 2017 02:18:29 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP; 08 Feb 2017 18:18:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,349,1484035200"; d="scan'208";a="56764872" Received: from relo-linux-11.sc.intel.com ([10.3.160.214]) by orsmga004.jf.intel.com with ESMTP; 08 Feb 2017 18:18:28 -0800 From: Michel Thierry To: intel-gfx@lists.freedesktop.org Date: Wed, 8 Feb 2017 18:18:23 -0800 Message-Id: <20170209021828.22813-4-michel.thierry@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170209021828.22813-1-michel.thierry@intel.com> References: <20170209021828.22813-1-michel.thierry@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 3/8] lib: Define a common bit operations library X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Bring the test/set/clear bit functions we have into a single place. Signed-off-by: Michel Thierry Reviewed-by: Joonas Lahtinen --- lib/igt.h | 1 + lib/igt_bitops.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_primes.c | 25 +------------------- 3 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 lib/igt_bitops.h diff --git a/lib/igt.h b/lib/igt.h index 4f54698d..7a8942aa 100644 --- a/lib/igt.h +++ b/lib/igt.h @@ -28,6 +28,7 @@ #include "i915_3d.h" #include "i915_pciids.h" #include "igt_aux.h" +#include "igt_bitops.h" #include "igt_core.h" #include "igt_debugfs.h" #include "igt_draw.h" diff --git a/lib/igt_bitops.h b/lib/igt_bitops.h new file mode 100644 index 00000000..11e0d8b5 --- /dev/null +++ b/lib/igt_bitops.h @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Intel Corporation + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef _I915_BITOPS_H +#define _I915_BITOPS_H + +#include + +#define BIT(nr) (1UL << (nr)) +#define BIT_ULL(nr) (1ULL << (nr)) +#define BITS_PER_CHAR 8 +#define BITS_PER_LONG (sizeof(long)*BITS_PER_CHAR) + +static inline unsigned long __bit__(unsigned long nr) +{ + return 1UL << (nr % BITS_PER_LONG); +} + +static inline void set_bit(unsigned long nr, unsigned long *addr) +{ + addr[nr / BITS_PER_LONG] |= __bit__(nr); +} + +static inline void clear_bit(unsigned long nr, unsigned long *addr) +{ + addr[nr / BITS_PER_LONG] &= ~__bit__(nr); +} + +static inline bool test_bit(unsigned long nr, const unsigned long *addr) +{ + return addr[nr / BITS_PER_LONG] & __bit__(nr); +} + +static inline bool test_and_set_bit(unsigned long nr, unsigned long *addr) +{ + bool ret = test_bit(nr, addr); + set_bit(nr, addr); + return ret; +} + +static inline bool test_and_clear_bit(unsigned long nr, unsigned long *addr) +{ + bool ret = test_bit(nr, addr); + clear_bit(nr, addr); + return ret; +} + +#endif /* _I915_BITOPS_H */ diff --git a/lib/igt_primes.c b/lib/igt_primes.c index d5232e54..30caafdb 100644 --- a/lib/igt_primes.c +++ b/lib/igt_primes.c @@ -21,16 +21,13 @@ * IN THE SOFTWARE. */ +#include "igt_bitops.h" #include "igt_primes.h" #include -#include #include #include -#define BITS_PER_CHAR 8 -#define BITS_PER_LONG (sizeof(long)*BITS_PER_CHAR) - #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) @@ -52,26 +49,6 @@ _max1 > _max2 ? _max1 : _max2; \ }) -static inline unsigned long __bit__(unsigned long nr) -{ - return 1UL << (nr % BITS_PER_LONG); -} - -static inline void set_bit(unsigned long nr, unsigned long *addr) -{ - addr[nr / BITS_PER_LONG] |= __bit__(nr); -} - -static inline void clear_bit(unsigned long nr, unsigned long *addr) -{ - addr[nr / BITS_PER_LONG] &= ~__bit__(nr); -} - -static inline bool test_bit(unsigned long nr, const unsigned long *addr) -{ - return addr[nr / BITS_PER_LONG] & __bit__(nr); -} - static unsigned long __find_next_bit(const unsigned long *addr, unsigned long nbits, unsigned long start,