Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
On Fri, Oct 23, 2015 at 06:36:27AM +0200, Wolfgang Denk wrote: > Dear Tom, > > In message <2015102627.GO23893@bill-the-cat> you wrote: > > > > We don't have a hard rule here as we know the kernel will not adopt SPDX > > tags currently. For rare sync ups like this probably is, switching to a > > tag might make sense, for stuff we'll resync every few kernel releases, > > it's just resync noise possibly so I'll leave that to the people doing > > the sync. > > In any case the SPDX tag must be added. Well, it comes down to how much of a PITA that makes re-syncing. The tags make life easier but the end goal is the reports. This reminds me that I need to go ping some people about the SPDX tooling, there's some funny things to re-sync and some files to tag. -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
Hi Tom, On Mon, Oct 19, 2015 at 9:06 PM, Tom Riniwrote: > On Fri, Oct 16, 2015 at 05:41:12PM -0300, Fabio Estevam wrote: > >> From: Fabio Estevam >> >> Use the log2 and fls64 header files directly from the kernel. >> >> Signed-off-by: Fabio Estevam > > Please update based on > http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign > to note which kernel hash this comes from. Similar for the other parts > as needed. The need to state the kernel hash or version is clear. My question is: if we import a file from the kernel should we keep the license text intact or should it be adapted to the SPDX-License-Identifier style? ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
On Thu, Oct 22, 2015 at 07:30:21PM -0200, Fabio Estevam wrote: > Hi Tom, > > On Mon, Oct 19, 2015 at 9:06 PM, Tom Riniwrote: > > On Fri, Oct 16, 2015 at 05:41:12PM -0300, Fabio Estevam wrote: > > > >> From: Fabio Estevam > >> > >> Use the log2 and fls64 header files directly from the kernel. > >> > >> Signed-off-by: Fabio Estevam > > > > Please update based on > > http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign > > to note which kernel hash this comes from. Similar for the other parts > > as needed. > > The need to state the kernel hash or version is clear. > > My question is: if we import a file from the kernel should we keep the > license text intact or should it be adapted to the > SPDX-License-Identifier style? We don't have a hard rule here as we know the kernel will not adopt SPDX tags currently. For rare sync ups like this probably is, switching to a tag might make sense, for stuff we'll resync every few kernel releases, it's just resync noise possibly so I'll leave that to the people doing the sync. -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
Dear Tom, In message <2015102627.GO23893@bill-the-cat> you wrote: > > We don't have a hard rule here as we know the kernel will not adopt SPDX > tags currently. For rare sync ups like this probably is, switching to a > tag might make sense, for stuff we'll resync every few kernel releases, > it's just resync noise possibly so I'll leave that to the people doing > the sync. In any case the SPDX tag must be added. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de Being schizophrenic is better than living alone. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
Dear Fabio, In message
Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
On 17 October 2015 at 02:11, Fabio Estevamwrote: > From: Fabio Estevam > > Use the log2 and fls64 header files directly from the kernel. > > Signed-off-by: Fabio Estevam > --- > Changes since v7: > - None > > include/asm-generic/bitops/fls64.h | 36 +++ > include/linux/bitops.h | 9 ++ > include/linux/log2.h | 208 > + > 3 files changed, 253 insertions(+) > create mode 100644 include/asm-generic/bitops/fls64.h > create mode 100644 include/linux/log2.h > > diff --git a/include/asm-generic/bitops/fls64.h > b/include/asm-generic/bitops/fls64.h > new file mode 100644 > index 000..86d403f > --- /dev/null > +++ b/include/asm-generic/bitops/fls64.h > @@ -0,0 +1,36 @@ > +#ifndef _ASM_GENERIC_BITOPS_FLS64_H_ > +#define _ASM_GENERIC_BITOPS_FLS64_H_ > + > +#include > + > +/** > + * fls64 - find last set bit in a 64-bit word > + * @x: the word to search > + * > + * This is defined in a similar way as the libc and compiler builtin > + * ffsll, but returns the position of the most significant set bit. > + * > + * fls64(value) returns 0 if value is 0 or the position of the last > + * set bit if value is nonzero. The last (most significant) bit is > + * at position 64. > + */ > +#if BITS_PER_LONG == 32 > +static inline int fls64(__u64 x) > +{ > + __u32 h = x >> 32; > + if (h) > + return fls(h) + 32; > + return fls(x); > +} > +#elif BITS_PER_LONG == 64 > +static inline int fls64(__u64 x) > +{ > + if (x == 0) > + return 0; > + return __fls(x) + 1; > +} > +#else > +#error BITS_PER_LONG not 32 or 64 > +#endif > + > +#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */ > diff --git a/include/linux/bitops.h b/include/linux/bitops.h > index 7d30ace..647733f 100644 > --- a/include/linux/bitops.h > +++ b/include/linux/bitops.h > @@ -129,6 +129,15 @@ static inline unsigned int generic_hweight8(unsigned int > w) > # define fls generic_fls > #endif > > +#include Please check this include, we can't assume to use generic one in common header file there is one more fls64 from powerpc? > + > +static inline unsigned fls_long(unsigned long l) > +{ > + if (sizeof(l) == 4) > + return fls(l); > + return fls64(l); > +} > + > /** > * __set_bit - Set a bit in memory > * @nr: the bit to set > diff --git a/include/linux/log2.h b/include/linux/log2.h > new file mode 100644 > index 000..fd7ff3d > --- /dev/null > +++ b/include/linux/log2.h > @@ -0,0 +1,208 @@ > +/* Integer base 2 logarithm calculation > + * > + * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. > + * Written by David Howells (dhowe...@redhat.com) > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version > + * 2 of the License, or (at your option) any later version. > + */ Wolfgang Denk/Tom, This file is copied from Linux, will this license notes will also be same or any changes? > + > +#ifndef _LINUX_LOG2_H > +#define _LINUX_LOG2_H > + > +#include > +#include > + > +/* > + * deal with unrepresentable constant logarithms > + */ > +extern __attribute__((const, noreturn)) > +int ilog2_NaN(void); > + > +/* > + * non-constant log of base 2 calculators > + * - the arch may override these in asm/bitops.h if they can be implemented > + * more efficiently than using fls() and fls64() > + * - the arch is not required to handle n==0 if implementing the fallback > + */ > +#ifndef CONFIG_ARCH_HAS_ILOG2_U32 > +static inline __attribute__((const)) > +int __ilog2_u32(u32 n) > +{ > + return fls(n) - 1; > +} > +#endif > + > +#ifndef CONFIG_ARCH_HAS_ILOG2_U64 > +static inline __attribute__((const)) > +int __ilog2_u64(u64 n) > +{ > + return fls64(n) - 1; > +} > +#endif > + > +/* > + * Determine whether some value is a power of two, where zero is > + * *not* considered a power of two. > + */ > + > +static inline __attribute__((const)) > +bool is_power_of_2(unsigned long n) > +{ > + return (n != 0 && ((n & (n - 1)) == 0)); > +} > + > +/* > + * round up to nearest power of two > + */ > +static inline __attribute__((const)) > +unsigned long __roundup_pow_of_two(unsigned long n) > +{ > + return 1UL << fls_long(n - 1); > +} > + > +/* > + * round down to nearest power of two > + */ > +static inline __attribute__((const)) > +unsigned long __rounddown_pow_of_two(unsigned long n) > +{ > + return 1UL << (fls_long(n) - 1); > +} > + > +/** > + * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value > + * @n - parameter > + * > + * constant-capable log of base 2 calculation > + * - this can be used to initialise global variables from constant data, > hence > + * the massive ternary operator construction > + * > + * selects the appropriately-sized optimised version
Re: [U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
On Fri, Oct 16, 2015 at 05:41:12PM -0300, Fabio Estevam wrote: > From: Fabio Estevam> > Use the log2 and fls64 header files directly from the kernel. > > Signed-off-by: Fabio Estevam Please update based on http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign to note which kernel hash this comes from. Similar for the other parts as needed. -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH v8 1/4] include: Add log2 and fls64 header fi
From: Fabio EstevamUse the log2 and fls64 header files directly from the kernel. Signed-off-by: Fabio Estevam --- Changes since v7: - None include/asm-generic/bitops/fls64.h | 36 +++ include/linux/bitops.h | 9 ++ include/linux/log2.h | 208 + 3 files changed, 253 insertions(+) create mode 100644 include/asm-generic/bitops/fls64.h create mode 100644 include/linux/log2.h diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h new file mode 100644 index 000..86d403f --- /dev/null +++ b/include/asm-generic/bitops/fls64.h @@ -0,0 +1,36 @@ +#ifndef _ASM_GENERIC_BITOPS_FLS64_H_ +#define _ASM_GENERIC_BITOPS_FLS64_H_ + +#include + +/** + * fls64 - find last set bit in a 64-bit word + * @x: the word to search + * + * This is defined in a similar way as the libc and compiler builtin + * ffsll, but returns the position of the most significant set bit. + * + * fls64(value) returns 0 if value is 0 or the position of the last + * set bit if value is nonzero. The last (most significant) bit is + * at position 64. + */ +#if BITS_PER_LONG == 32 +static inline int fls64(__u64 x) +{ + __u32 h = x >> 32; + if (h) + return fls(h) + 32; + return fls(x); +} +#elif BITS_PER_LONG == 64 +static inline int fls64(__u64 x) +{ + if (x == 0) + return 0; + return __fls(x) + 1; +} +#else +#error BITS_PER_LONG not 32 or 64 +#endif + +#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 7d30ace..647733f 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -129,6 +129,15 @@ static inline unsigned int generic_hweight8(unsigned int w) # define fls generic_fls #endif +#include + +static inline unsigned fls_long(unsigned long l) +{ + if (sizeof(l) == 4) + return fls(l); + return fls64(l); +} + /** * __set_bit - Set a bit in memory * @nr: the bit to set diff --git a/include/linux/log2.h b/include/linux/log2.h new file mode 100644 index 000..fd7ff3d --- /dev/null +++ b/include/linux/log2.h @@ -0,0 +1,208 @@ +/* Integer base 2 logarithm calculation + * + * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowe...@redhat.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#ifndef _LINUX_LOG2_H +#define _LINUX_LOG2_H + +#include +#include + +/* + * deal with unrepresentable constant logarithms + */ +extern __attribute__((const, noreturn)) +int ilog2_NaN(void); + +/* + * non-constant log of base 2 calculators + * - the arch may override these in asm/bitops.h if they can be implemented + * more efficiently than using fls() and fls64() + * - the arch is not required to handle n==0 if implementing the fallback + */ +#ifndef CONFIG_ARCH_HAS_ILOG2_U32 +static inline __attribute__((const)) +int __ilog2_u32(u32 n) +{ + return fls(n) - 1; +} +#endif + +#ifndef CONFIG_ARCH_HAS_ILOG2_U64 +static inline __attribute__((const)) +int __ilog2_u64(u64 n) +{ + return fls64(n) - 1; +} +#endif + +/* + * Determine whether some value is a power of two, where zero is + * *not* considered a power of two. + */ + +static inline __attribute__((const)) +bool is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + +/* + * round up to nearest power of two + */ +static inline __attribute__((const)) +unsigned long __roundup_pow_of_two(unsigned long n) +{ + return 1UL << fls_long(n - 1); +} + +/* + * round down to nearest power of two + */ +static inline __attribute__((const)) +unsigned long __rounddown_pow_of_two(unsigned long n) +{ + return 1UL << (fls_long(n) - 1); +} + +/** + * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value + * @n - parameter + * + * constant-capable log of base 2 calculation + * - this can be used to initialise global variables from constant data, hence + * the massive ternary operator construction + * + * selects the appropriately-sized optimised version depending on sizeof(n) + */ +#define ilog2(n) \ +( \ + __builtin_constant_p(n) ? ( \ + (n) < 1 ? ilog2_NaN() : \ + (n) & (1ULL << 63) ? 63 : \ + (n) & (1ULL << 62) ? 62 : \ + (n) & (1ULL << 61) ? 61 : \ + (n) & (1ULL << 60) ? 60 : \ + (n) & (1ULL << 59) ? 59 : \ + (n) & (1ULL << 58) ? 58 : \ + (n) & (1ULL << 57) ? 57 : \ + (n) & (1ULL << 56) ? 56 : \ + (n) &