Message ID | 1456938657-20850-3-git-send-email-pfeiner@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Mar 02, 2016 at 09:10:53AM -0800, Peter Feiner wrote: > Factored out common bitops stuff, just like Linux's > include/linux/bitops.h. > > Signed-off-by: Peter Feiner <pfeiner@google.com> Reviewed-by: Andrew Jones <drjones@redhat.com> > --- > 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 | 36 ++++++++++++++++++++++++++++++++++++ > lib/ppc64/asm/bitops.h | 10 ++++++++++ > lib/x86/asm/bitops.h | 14 ++++++++++++++ > 7 files changed, 70 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 <drjones@redhat.com> > @@ -10,10 +9,11 @@ > * This work is licensed under the terms of the GNU LGPL, version 2. > */ > > +#ifndef _BITOPS_H_ > +#error only <bitops.h> 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 <asm/setup.h> > -#include <asm/bitops.h> > +#include <bitops.h> > > #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 <asm/bitops.h> > +#include <bitops.h> > #include <asm/barrier.h> > #include <asm/mmu.h> > > 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 <drjones@redhat.com> > @@ -10,10 +9,11 @@ > * This work is licensed under the terms of the GNU LGPL, version 2. > */ > > +#ifndef _BITOPS_H_ > +#error only <bitops.h> 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..9aa847e > --- /dev/null > +++ b/lib/bitops.h > @@ -0,0 +1,36 @@ > +#ifndef _BITOPS_H_ > +#define _BITOPS_H_ > + > +/* > + * Adapated from > + * include/linux/bitops.h > + * > + * Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com> > + * > + * This work is licensed under the terms of the GNU LGPL, version 2. > + */ > + > +#define BITS_PER_LONG_LONG 64 > +#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 <asm/bitops.h> > + > +/* > + * 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 <bitops.h> 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 <bitops.h> can be included directly > +#endif > + > +#ifdef __x86_64__ > +#define BITS_PER_LONG 64 > +#else > +#define BITS_PER_LONG 32 > +#endif > + > +#endif > -- > 2.7.0.rc3.207.g0ac5344 > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 <drjones@redhat.com> @@ -10,10 +9,11 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#ifndef _BITOPS_H_ +#error only <bitops.h> 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 <asm/setup.h> -#include <asm/bitops.h> +#include <bitops.h> #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 <asm/bitops.h> +#include <bitops.h> #include <asm/barrier.h> #include <asm/mmu.h> 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 <drjones@redhat.com> @@ -10,10 +9,11 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#ifndef _BITOPS_H_ +#error only <bitops.h> 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..9aa847e --- /dev/null +++ b/lib/bitops.h @@ -0,0 +1,36 @@ +#ifndef _BITOPS_H_ +#define _BITOPS_H_ + +/* + * Adapated from + * include/linux/bitops.h + * + * Copyright (C) 2015, Red Hat Inc, Andrew Jones <drjones@redhat.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +#define BITS_PER_LONG_LONG 64 +#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 <asm/bitops.h> + +/* + * 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 <bitops.h> 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 <bitops.h> can be included directly +#endif + +#ifdef __x86_64__ +#define BITS_PER_LONG 64 +#else +#define BITS_PER_LONG 32 +#endif + +#endif
Factored out common bitops stuff, just like Linux's include/linux/bitops.h. Signed-off-by: Peter Feiner <pfeiner@google.com> --- 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 | 36 ++++++++++++++++++++++++++++++++++++ lib/ppc64/asm/bitops.h | 10 ++++++++++ lib/x86/asm/bitops.h | 14 ++++++++++++++ 7 files changed, 70 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