Skip to contentSkip to conversation

arm: implement find_next_zero_bit function

PATCH New Vitaly Andrianov 2 participants 7 messages Feb 5, 2015 – Apr 16, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---

 arch/arm/include/asm/bitops.h | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)
arch/arm/include/asm/bitops.h +40 -3
index 597dafb..9b78043 100644
@@ -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
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 arm: implement find_next_zero_bit function

Hello Vitaly,

Quoted 4 lines · Vitaly Andrianov

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?

Quoted 1 line

Amicalement,

Signature · 1 line
Albert.
#2 lore raw

PATCH 1/1 arm: implement find_next_zero_bit function

Quoted 10 lines · Albert ARIBAUD

Hello Vitaly,

Quoted 4 lines · Vitaly Andrianov

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

Quoted 5 lines
Quoted 2 lines

Amicalement,

-Vitaly

#3 lore raw

PATCH 1/1 arm: implement find_next_zero_bit function

Hello Vitaly,

Quoted 7 lines · Vitaly Andrianov
Quoted 4 lines · Albert ARIBAUD

Hello Vitaly,

On Thu, 5 Feb 2015 11:24:46 -0500, Vitaly Andrianov <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

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?

Quoted 1 line

-Vitaly

Amicalement,

Signature · 1 line
Albert.
#4 lore raw

PATCH 1/1 arm: implement find_next_zero_bit function

Hello Albert,

Quoted 16 lines · Albert ARIBAUD

Hello Vitaly,

Quoted 12 lines · Vitaly Andrianov
Quoted 9 lines · Albert ARIBAUD

Hello Vitaly,

Quoted 4 lines · Vitaly Andrianov

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.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 4 lines
Quoted 1 line

-Vitaly

Amicalement,

#5 lore raw

PATCH 1/1 arm: implement find_next_zero_bit function

Hello Vitaly,

Quoted 21 lines · Vitaly Andrianov

Hello Albert,

Quoted 18 lines · Albert ARIBAUD

Hello Vitaly,

Quoted 14 lines · Vitaly Andrianov
Quoted 10 lines · Albert ARIBAUD

Hello Vitaly,

Quoted 4 lines · Vitaly Andrianov

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?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

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.

Quoted 1 line

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,

Signature · 1 line
Albert.
#6 lore raw

PATCH 1/1 arm: implement find_next_zero_bit function

In reply to Vitaly Andrianov

Hello Vitaly,

Quoted 82 lines · Vitaly Andrianov

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.

---

 arch/arm/include/asm/bitops.h | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)
arch/arm/include/asm/bitops.h +40 -3
index 597dafb..9b78043 100644
@@ -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
Signature · 1 line
1.9.1

Applied to u-boot-arm/master, thanks!

Amicalement,

Signature · 1 line
Albert.