From patchwork Tue Mar 1 22:34:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8471091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 603F2C0553 for ; Tue, 1 Mar 2016 22:35:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5DBC32034A for ; Tue, 1 Mar 2016 22:35:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB5632034E for ; Tue, 1 Mar 2016 22:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751726AbcCAWfO (ORCPT ); Tue, 1 Mar 2016 17:35:14 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:33096 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750862AbcCAWfM (ORCPT ); Tue, 1 Mar 2016 17:35:12 -0500 Received: by mail-pa0-f44.google.com with SMTP id fl4so119914899pad.0 for ; Tue, 01 Mar 2016 14:35:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r5ZiScDopmTOueNLeFgJuPldHsQu3esrGGGlRQlkkTs=; b=ApA1w35Gwn5lOudrxXiyRbZyBHKylwgP2xJNhGlt9glIwL0GbnzzhhdA1hXU/wqwCR c0WcR/8nXbyhtHu4wLEx9xRwrMb7yBN+6ZpSFtp4W+XU/+7X9Z/I9HfGn3qPXyJs2xTW k2OysfTymRQP99Fnf2URGc0Rj717CL42AH5Qmb4X0wuB+1pX+lh81AM1zZRljd3u0AZR uZdnYy9ckzQequVp1MfhaXzU1QwD60qDG/SBFvQg/aFKxDgcB6PjZ89Cnea3itFMvIf8 PmGKnj1+pdQqX1TTiYQ1DYmXqJANx6RCdhayce0+3SzMoG3ddXhRXObA6EvbIuZdRbSt rZsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r5ZiScDopmTOueNLeFgJuPldHsQu3esrGGGlRQlkkTs=; b=BSQRqMX6hYWzPE4dqNAlx05m9/lH0SQJR2YnuQ7GxPKFY5XA9UOC8XjAt67JJ18R6S fvIEW7W/rEbernM8NkRl2eLmgFi7N43DhbVHssItBWargNFPCjmR6GBbSsedufoqxc7b /d9aZ8OVq//cCAs22Dv+6X0ttgxZeL76zWnvXhewr2jtBG9BAIiXIfyvH8MIvlYaCPSm 8n/CYLftOSOVTdZZWP1gNt5RhCGtX80rfvexlJZT2pMNp1GkoEJZTXNW9/Jp702QWRLV DcY/JJGaPeWn+6qgAY9A+9cFgAOLPaXmot2jiHpJ/+8RuND0UfCxWGx+s1d9VtvXxqCp s/xg== X-Gm-Message-State: AD7BkJIht/WszJ8oYSVFdvG/re1iUXmPiRBowy/+80+uLuO1omJP6fmTv9uj8rfO1RtskaNR X-Received: by 10.66.155.232 with SMTP id vz8mr33916493pab.53.1456871711526; Tue, 01 Mar 2016 14:35:11 -0800 (PST) Received: from localhost ([2620:0:1009:3:b1e9:1d95:1ce5:e70c]) by smtp.gmail.com with ESMTPSA id a25sm6888466pfj.40.2016.03.01.14.35.10 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 14:35:11 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, jan.kiszka@siemens.com, drjones@redhat.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests v2 2/6] lib: generic bitops.h Date: Tue, 1 Mar 2016 14:34:50 -0800 Message-Id: <1456871694-23042-3-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456871694-23042-1-git-send-email-pfeiner@google.com> References: <1456860622-31251-1-git-send-email-pfeiner@google.com> <1456871694-23042-1-git-send-email-pfeiner@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Factored out common bitops stuff, just like Linux's include/linux/bitops.h. Signed-off-by: Peter Feiner --- lib/arm/asm/bitops.h | 8 ++++---- lib/arm/asm/cpumask.h | 2 +- lib/arm/bitops.c | 2 +- lib/arm64/asm/bitops.h | 8 ++++---- lib/bitops.h | 35 +++++++++++++++++++++++++++++++++++ lib/ppc64/asm/bitops.h | 10 ++++++++++ lib/x86/asm/bitops.h | 14 ++++++++++++++ 7 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 lib/bitops.h create mode 100644 lib/ppc64/asm/bitops.h create mode 100644 lib/x86/asm/bitops.h diff --git a/lib/arm/asm/bitops.h b/lib/arm/asm/bitops.h index 8049634..d46cc5d 100644 --- a/lib/arm/asm/bitops.h +++ b/lib/arm/asm/bitops.h @@ -2,7 +2,6 @@ #define _ASMARM_BITOPS_H_ /* * Adapated from - * include/linux/bitops.h * arch/arm/lib/bitops.h * * Copyright (C) 2015, Red Hat Inc, Andrew Jones @@ -10,10 +9,11 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + #define BITS_PER_LONG 32 -#define BIT(nr) (1UL << (nr)) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define ATOMIC_BITOP(insn, mask, word) \ ({ \ diff --git a/lib/arm/asm/cpumask.h b/lib/arm/asm/cpumask.h index 85b8e4b..6683bb6 100644 --- a/lib/arm/asm/cpumask.h +++ b/lib/arm/asm/cpumask.h @@ -8,7 +8,7 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ #include -#include +#include #define CPUMASK_NR_LONGS ((NR_CPUS + BITS_PER_LONG - 1) / BITS_PER_LONG) diff --git a/lib/arm/bitops.c b/lib/arm/bitops.c index 9ad1121..1f1db93 100644 --- a/lib/arm/bitops.c +++ b/lib/arm/bitops.c @@ -6,7 +6,7 @@ * * This work is licensed under the terms of the GNU LGPL, version 2. */ -#include +#include #include #include diff --git a/lib/arm64/asm/bitops.h b/lib/arm64/asm/bitops.h index 3371c60..618468c 100644 --- a/lib/arm64/asm/bitops.h +++ b/lib/arm64/asm/bitops.h @@ -2,7 +2,6 @@ #define _ASMARM64_BITOPS_H_ /* * Adapated from - * include/linux/bitops.h * arch/arm64/lib/bitops.S * * Copyright (C) 2015, Red Hat Inc, Andrew Jones @@ -10,10 +9,11 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + #define BITS_PER_LONG 64 -#define BIT(nr) (1UL << (nr)) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define ATOMIC_BITOP(insn, mask, word) \ ({ \ diff --git a/lib/bitops.h b/lib/bitops.h new file mode 100644 index 0000000..c550eba --- /dev/null +++ b/lib/bitops.h @@ -0,0 +1,35 @@ +#ifndef _BITOPS_H_ +#define _BITOPS_H_ + +/* + * Adapated from + * include/linux/bitops.h + * + * Copyright (C) 2015, Red Hat Inc, Andrew Jones + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +#define BIT(nr) (1UL << (nr)) +#define BIT_ULL(nr) (1ULL << (nr)) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG)) +#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG) +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) + +#include + +/* + * Create a contiguous bitmask starting at bit position @l and ending at + * position @h. For example + * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. + */ +#define GENMASK(h, l) \ + (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + +#define GENMASK_ULL(h, l) \ + (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) + +#endif diff --git a/lib/ppc64/asm/bitops.h b/lib/ppc64/asm/bitops.h new file mode 100644 index 0000000..34624b4 --- /dev/null +++ b/lib/ppc64/asm/bitops.h @@ -0,0 +1,10 @@ +#ifndef _ASMPPC64_BITOPS_H_ +#define _ASMPPC64_BITOPS_H_ + +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + +#define BITS_PER_LONG 64 + +#endif diff --git a/lib/x86/asm/bitops.h b/lib/x86/asm/bitops.h new file mode 100644 index 0000000..eb4aaa9 --- /dev/null +++ b/lib/x86/asm/bitops.h @@ -0,0 +1,14 @@ +#ifndef _ASMX86_BITOPS_H_ +#define _ASMX86_BITOPS_H_ + +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + +#ifdef __x86_64__ +#define BITS_PER_LONG 64 +#else +#define BITS_PER_LONG 32 +#endif + +#endif