[U-Boot] [PATCH] arm: implement find_next_zero_bit function

This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Signed-off-by: Vitaly Andrianov vitalya@ti.com ---
arch/arm/include/asm/bitops.h | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/arch/arm/include/asm/bitops.h b/arch/arm/include/asm/bitops.h index 597dafb..9b78043 100644 --- a/arch/arm/include/asm/bitops.h +++ b/arch/arm/include/asm/bitops.h @@ -95,9 +95,6 @@ static inline int __test_and_change_bit(int nr, volatile void *addr) return (old & mask) != 0; }
-extern int find_first_zero_bit(void * addr, unsigned size); -extern int find_next_zero_bit(void * addr, int size, int offset); - /* * This routine doesn't need to be atomic. */ @@ -129,6 +126,43 @@ static inline unsigned long ffz(unsigned long word) return k; }
+static inline int find_next_zero_bit(void *addr, int size, int offset) +{ + unsigned long *p = ((unsigned long *)addr) + (offset >> 5); + unsigned long result = offset & ~31UL; + unsigned long tmp; + + if (offset >= size) + return size; + size -= result; + offset &= 31UL; + if (offset) { + tmp = *(p++); + tmp |= ~0UL >> (32-offset); + if (size < 32) + goto found_first; + if (~tmp) + goto found_middle; + size -= 32; + result += 32; + } + while (size & ~31UL) { + tmp = *(p++); + if (~tmp) + goto found_middle; + result += 32; + size -= 32; + } + if (!size) + return result; + tmp = *p; + +found_first: + tmp |= ~0UL >> size; +found_middle: + return result + ffz(tmp); +} + /* * hweightN: returns the hamming weight (i.e. the number * of bits set) of a N-bit word @@ -138,6 +172,9 @@ static inline unsigned long ffz(unsigned long word) #define hweight16(x) generic_hweight16(x) #define hweight8(x) generic_hweight8(x)
+#define find_first_zero_bit(addr, size) \ + find_next_zero_bit((addr), (size), 0) + #define ext2_set_bit test_and_set_bit #define ext2_clear_bit test_and_clear_bit #define ext2_test_bit test_bit

Hello Vitaly,
On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov vitalya@ti.com wrote:
This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Which mainline board needs this?
Signed-off-by: Vitaly Andrianov vitalya@ti.com
Amicalement,

On 02/05/2015 12:52 PM, Albert ARIBAUD wrote:
Hello Vitaly,
On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov vitalya@ti.com wrote:
This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Which mainline board needs this?
TI Keystone2 EVMs
Signed-off-by: Vitaly Andrianov vitalya@ti.com
Amicalement,
-Vitaly

Hello Vitaly,
On Wed, 11 Feb 2015 14:11:12 -0500, Vitaly Andrianov vitalya@ti.com wrote:
On 02/05/2015 12:52 PM, Albert ARIBAUD wrote:
Hello Vitaly,
On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov vitalya@ti.com wrote:
This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Which mainline board needs this?
TI Keystone2 EVMs
Just to make sure: this is actually replacing a 'normal' function with an inline one. So the function /was/ available before this patch, right?
-Vitaly
Amicalement,

Hello Albert,
On 03/27/2015 11:54 AM, Albert ARIBAUD wrote:
Hello Vitaly,
On Wed, 11 Feb 2015 14:11:12 -0500, Vitaly Andrianov vitalya@ti.com wrote:
On 02/05/2015 12:52 PM, Albert ARIBAUD wrote:
Hello Vitaly,
On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov vitalya@ti.com wrote:
This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Which mainline board needs this?
TI Keystone2 EVMs
Just to make sure: this is actually replacing a 'normal' function with an inline one. So the function /was/ available before this patch, right?
What inline function are you talking about? I couldn't find this function for ARM. That is why I copied it from MIPS.
-Vitaly
Amicalement,

Hello Vitaly,
On Fri, 27 Mar 2015 15:06:15 -0400, Vitaly Andrianov vitalya@ti.com wrote:
Hello Albert,
On 03/27/2015 11:54 AM, Albert ARIBAUD wrote:
Hello Vitaly,
On Wed, 11 Feb 2015 14:11:12 -0500, Vitaly Andrianov vitalya@ti.com wrote:
On 02/05/2015 12:52 PM, Albert ARIBAUD wrote:
Hello Vitaly,
On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov vitalya@ti.com wrote:
This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Which mainline board needs this?
TI Keystone2 EVMs
Just to make sure: this is actually replacing a 'normal' function with an inline one. So the function /was/ available before this patch, right?
What inline function are you talking about?
The one you are adding with this patch.
I couldn't find this function for ARM. That is why I copied it from MIPS.
Thanks -- I had noticed that you were removing extern declarations for find_first_zero_bit() and find_next_zero_bit() and I was surprised that this removal was not explained in the commit message, and I had not realized that the corresponding function definitions did not exist.
I'll apply your patch and add a note in the commit message explaining the removal.
Amicalement,

Hello Vitaly,
On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov vitalya@ti.com wrote:
This commit copies implementation of the find_next_zero_bit() from git://git.denx.de/u-boot.git/arch/mips/include/asm/bitops.h. v2014.07
The function is required to enable MCAST_TFTP support for ARM platforms.
Signed-off-by: Vitaly Andrianov vitalya@ti.com
arch/arm/include/asm/bitops.h | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/arch/arm/include/asm/bitops.h b/arch/arm/include/asm/bitops.h index 597dafb..9b78043 100644 --- a/arch/arm/include/asm/bitops.h +++ b/arch/arm/include/asm/bitops.h @@ -95,9 +95,6 @@ static inline int __test_and_change_bit(int nr, volatile void *addr) return (old & mask) != 0; }
-extern int find_first_zero_bit(void * addr, unsigned size); -extern int find_next_zero_bit(void * addr, int size, int offset);
/*
- This routine doesn't need to be atomic.
*/ @@ -129,6 +126,43 @@ static inline unsigned long ffz(unsigned long word) return k; }
+static inline int find_next_zero_bit(void *addr, int size, int offset) +{
- unsigned long *p = ((unsigned long *)addr) + (offset >> 5);
- unsigned long result = offset & ~31UL;
- unsigned long tmp;
- if (offset >= size)
return size;
- size -= result;
- offset &= 31UL;
- if (offset) {
tmp = *(p++);
tmp |= ~0UL >> (32-offset);
if (size < 32)
goto found_first;
if (~tmp)
goto found_middle;
size -= 32;
result += 32;
- }
- while (size & ~31UL) {
tmp = *(p++);arm: implement find_next_zero_bit function
if (~tmp)
goto found_middle;
result += 32;
size -= 32;
- }
- if (!size)
return result;
- tmp = *p;
+found_first:
- tmp |= ~0UL >> size;
+found_middle:
- return result + ffz(tmp);
+}
/*
- hweightN: returns the hamming weight (i.e. the number
- of bits set) of a N-bit word
@@ -138,6 +172,9 @@ static inline unsigned long ffz(unsigned long word) #define hweight16(x) generic_hweight16(x) #define hweight8(x) generic_hweight8(x)
+#define find_first_zero_bit(addr, size) \
- find_next_zero_bit((addr), (size), 0)
#define ext2_set_bit test_and_set_bit #define ext2_clear_bit test_and_clear_bit
#define ext2_test_bit test_bit
1.9.1
Applied to u-boot-arm/master, thanks!
Amicalement,
participants (2)
-
Albert ARIBAUD
-
Vitaly Andrianov