* [patch 04/44] use non atomic operations for minix_*_bit() and ext2_*_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 06/44] generic __{,test_and_}{set,clear,change}_bit() and test_bit() Akinobu Mita
` (11 subsequent siblings)
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: dev-etrax, David Howells, Yoshinori Sato, linux-ia64,
Hirokazu Takata, linux-m68k, Greg Ungerer, linux-mips, linux390,
linuxsh-dev, linuxsh-shmedia-dev, sparclinux, ultralinux,
Miles Bader, Chris Zankel, Akinobu Mita
Bitmap functions for the minix filesystem and the ext2 filesystem do not
require the atomic guarantees except ext2_set_bit_atomic() and
ext2_clear_bit_atomic().
But these are defined by using atomic bit operations on several architectures.
(cris, frv, h8300, ia64, m32r, m68k, m68knommu, mips, s390, sh, sh64, sparc,
sparc64, v850, and xtensa)
This patch switches to non atomic bit operation.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-cris/bitops.h | 8 ++++----
include/asm-frv/bitops.h | 14 +++++++-------
include/asm-h8300/bitops.h | 6 +++---
include/asm-ia64/bitops.h | 10 +++++-----
include/asm-m32r/bitops.h | 2 +-
include/asm-m68k/bitops.h | 10 +++++-----
include/asm-m68knommu/bitops.h | 6 +++---
include/asm-mips/bitops.h | 6 +++---
include/asm-s390/bitops.h | 10 +++++-----
include/asm-sh/bitops.h | 16 +++++-----------
include/asm-sh64/bitops.h | 16 +++++-----------
include/asm-sparc/bitops.h | 6 +++---
include/asm-sparc64/bitops.h | 6 +++---
include/asm-v850/bitops.h | 10 +++++-----
include/asm-xtensa/bitops.h | 6 +++---
15 files changed, 60 insertions(+), 72 deletions(-)
Index: 2.6-git/include/asm-h8300/bitops.h
=================================--- 2.6-git.orig/include/asm-h8300/bitops.h
+++ 2.6-git/include/asm-h8300/bitops.h
@@ -397,9 +397,9 @@ found_middle:
}
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-ia64/bitops.h
=================================--- 2.6-git.orig/include/asm-ia64/bitops.h
+++ 2.6-git/include/asm-ia64/bitops.h
@@ -394,18 +394,18 @@ extern int __find_next_bit(const void *a
#define __clear_bit(nr, addr) clear_bit(nr, addr)
-#define ext2_set_bit test_and_set_bit
+#define ext2_set_bit __test_and_set_bit
#define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a)
-#define ext2_clear_bit test_and_clear_bit
+#define ext2_clear_bit __test_and_clear_bit
#define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)
#define ext2_test_bit test_bit
#define ext2_find_first_zero_bit find_first_zero_bit
#define ext2_find_next_zero_bit find_next_zero_bit
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-mips/bitops.h
=================================--- 2.6-git.orig/include/asm-mips/bitops.h
+++ 2.6-git/include/asm-mips/bitops.h
@@ -956,9 +956,9 @@ found_middle:
* FIXME: These assume that Minix uses the native byte/bitorder.
* This limits the Minix filesystem's value for data exchange very much.
*/
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-s390/bitops.h
=================================--- 2.6-git.orig/include/asm-s390/bitops.h
+++ 2.6-git/include/asm-s390/bitops.h
@@ -871,11 +871,11 @@ static inline int sched_find_first_bit(u
*/
#define ext2_set_bit(nr, addr) \
- test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
+ __test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
#define ext2_set_bit_atomic(lock, nr, addr) \
test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
#define ext2_clear_bit(nr, addr) \
- test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
+ __test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
#define ext2_clear_bit_atomic(lock, nr, addr) \
test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
#define ext2_test_bit(nr, addr) \
@@ -1014,11 +1014,11 @@ ext2_find_next_zero_bit(void *vaddr, uns
/* Bitmap functions for the minix filesystem. */
/* FIXME !!! */
#define minix_test_and_set_bit(nr,addr) \
- test_and_set_bit(nr,(unsigned long *)addr)
+ __test_and_set_bit(nr,(unsigned long *)addr)
#define minix_set_bit(nr,addr) \
- set_bit(nr,(unsigned long *)addr)
+ __set_bit(nr,(unsigned long *)addr)
#define minix_test_and_clear_bit(nr,addr) \
- test_and_clear_bit(nr,(unsigned long *)addr)
+ __test_and_clear_bit(nr,(unsigned long *)addr)
#define minix_test_bit(nr,addr) \
test_bit(nr,(unsigned long *)addr)
#define minix_find_first_zero_bit(addr,size) \
Index: 2.6-git/include/asm-sh/bitops.h
=================================--- 2.6-git.orig/include/asm-sh/bitops.h
+++ 2.6-git/include/asm-sh/bitops.h
@@ -339,8 +339,8 @@ static inline int sched_find_first_bit(c
}
#ifdef __LITTLE_ENDIAN__
-#define ext2_set_bit(nr, addr) test_and_set_bit((nr), (addr))
-#define ext2_clear_bit(nr, addr) test_and_clear_bit((nr), (addr))
+#define ext2_set_bit(nr, addr) __test_and_set_bit((nr), (addr))
+#define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr), (addr))
#define ext2_test_bit(nr, addr) test_bit((nr), (addr))
#define ext2_find_first_zero_bit(addr, size) find_first_zero_bit((addr), (size))
#define ext2_find_next_zero_bit(addr, size, offset) \
@@ -349,30 +349,24 @@ static inline int sched_find_first_bit(c
static __inline__ int ext2_set_bit(int nr, volatile void * addr)
{
int mask, retval;
- unsigned long flags;
volatile unsigned char *ADDR = (unsigned char *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
- local_irq_save(flags);
retval = (mask & *ADDR) != 0;
*ADDR |= mask;
- local_irq_restore(flags);
return retval;
}
static __inline__ int ext2_clear_bit(int nr, volatile void * addr)
{
int mask, retval;
- unsigned long flags;
volatile unsigned char *ADDR = (unsigned char *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
- local_irq_save(flags);
retval = (mask & *ADDR) != 0;
*ADDR &= ~mask;
- local_irq_restore(flags);
return retval;
}
@@ -459,9 +453,9 @@ found_middle:
})
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-sh64/bitops.h
=================================--- 2.6-git.orig/include/asm-sh64/bitops.h
+++ 2.6-git/include/asm-sh64/bitops.h
@@ -382,8 +382,8 @@ static inline int sched_find_first_bit(u
#define hweight8(x) generic_hweight8(x)
#ifdef __LITTLE_ENDIAN__
-#define ext2_set_bit(nr, addr) test_and_set_bit((nr), (addr))
-#define ext2_clear_bit(nr, addr) test_and_clear_bit((nr), (addr))
+#define ext2_set_bit(nr, addr) __test_and_set_bit((nr), (addr))
+#define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr), (addr))
#define ext2_test_bit(nr, addr) test_bit((nr), (addr))
#define ext2_find_first_zero_bit(addr, size) find_first_zero_bit((addr), (size))
#define ext2_find_next_zero_bit(addr, size, offset) \
@@ -392,30 +392,24 @@ static inline int sched_find_first_bit(u
static __inline__ int ext2_set_bit(int nr, volatile void * addr)
{
int mask, retval;
- unsigned long flags;
volatile unsigned char *ADDR = (unsigned char *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
- local_irq_save(flags);
retval = (mask & *ADDR) != 0;
*ADDR |= mask;
- local_irq_restore(flags);
return retval;
}
static __inline__ int ext2_clear_bit(int nr, volatile void * addr)
{
int mask, retval;
- unsigned long flags;
volatile unsigned char *ADDR = (unsigned char *) addr;
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
- local_irq_save(flags);
retval = (mask & *ADDR) != 0;
*ADDR &= ~mask;
- local_irq_restore(flags);
return retval;
}
@@ -502,9 +496,9 @@ found_middle:
})
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-sparc/bitops.h
=================================--- 2.6-git.orig/include/asm-sparc/bitops.h
+++ 2.6-git/include/asm-sparc/bitops.h
@@ -523,11 +523,11 @@ found_middle:
/* Bitmap functions for the minix filesystem. */
#define minix_test_and_set_bit(nr,addr) \
- test_and_set_bit((nr),(unsigned long *)(addr))
+ __test_and_set_bit((nr),(unsigned long *)(addr))
#define minix_set_bit(nr,addr) \
- set_bit((nr),(unsigned long *)(addr))
+ __set_bit((nr),(unsigned long *)(addr))
#define minix_test_and_clear_bit(nr,addr) \
- test_and_clear_bit((nr),(unsigned long *)(addr))
+ __test_and_clear_bit((nr),(unsigned long *)(addr))
#define minix_test_bit(nr,addr) \
test_bit((nr),(unsigned long *)(addr))
#define minix_find_first_zero_bit(addr,size) \
Index: 2.6-git/include/asm-sparc64/bitops.h
=================================--- 2.6-git.orig/include/asm-sparc64/bitops.h
+++ 2.6-git/include/asm-sparc64/bitops.h
@@ -280,11 +280,11 @@ extern unsigned long find_next_zero_le_b
/* Bitmap functions for the minix filesystem. */
#define minix_test_and_set_bit(nr,addr) \
- test_and_set_bit((nr),(unsigned long *)(addr))
+ __test_and_set_bit((nr),(unsigned long *)(addr))
#define minix_set_bit(nr,addr) \
- set_bit((nr),(unsigned long *)(addr))
+ __set_bit((nr),(unsigned long *)(addr))
#define minix_test_and_clear_bit(nr,addr) \
- test_and_clear_bit((nr),(unsigned long *)(addr))
+ __test_and_clear_bit((nr),(unsigned long *)(addr))
#define minix_test_bit(nr,addr) \
test_bit((nr),(unsigned long *)(addr))
#define minix_find_first_zero_bit(addr,size) \
Index: 2.6-git/include/asm-v850/bitops.h
=================================--- 2.6-git.orig/include/asm-v850/bitops.h
+++ 2.6-git/include/asm-v850/bitops.h
@@ -336,18 +336,18 @@ static inline int sched_find_first_bit(u
#define hweight16(x) generic_hweight16 (x)
#define hweight8(x) generic_hweight8 (x)
-#define ext2_set_bit test_and_set_bit
+#define ext2_set_bit __test_and_set_bit
#define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a)
-#define ext2_clear_bit test_and_clear_bit
+#define ext2_clear_bit __test_and_clear_bit
#define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)
#define ext2_test_bit test_bit
#define ext2_find_first_zero_bit find_first_zero_bit
#define ext2_find_next_zero_bit find_next_zero_bit
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit test_and_set_bit
-#define minix_set_bit set_bit
-#define minix_test_and_clear_bit test_and_clear_bit
+#define minix_test_and_set_bit __test_and_set_bit
+#define minix_set_bit __set_bit
+#define minix_test_and_clear_bit __test_and_clear_bit
#define minix_test_bit test_bit
#define minix_find_first_zero_bit find_first_zero_bit
Index: 2.6-git/include/asm-xtensa/bitops.h
=================================--- 2.6-git.orig/include/asm-xtensa/bitops.h
+++ 2.6-git/include/asm-xtensa/bitops.h
@@ -436,9 +436,9 @@ static inline int sched_find_first_bit(c
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-m32r/bitops.h
=================================--- 2.6-git.orig/include/asm-m32r/bitops.h
+++ 2.6-git/include/asm-m32r/bitops.h
@@ -575,7 +575,7 @@ found_middle:
*/
#ifdef __LITTLE_ENDIAN__
-#define ext2_set_bit test_and_set_bit
+#define ext2_set_bit __test_and_set_bit
#define ext2_clear_bit __test_and_clear_bit
#define ext2_test_bit test_bit
#define ext2_find_first_zero_bit find_first_zero_bit
Index: 2.6-git/include/asm-cris/bitops.h
=================================--- 2.6-git.orig/include/asm-cris/bitops.h
+++ 2.6-git/include/asm-cris/bitops.h
@@ -352,17 +352,17 @@ found_middle:
#define find_first_bit(addr, size) \
find_next_bit((addr), (size), 0)
-#define ext2_set_bit test_and_set_bit
+#define ext2_set_bit __test_and_set_bit
#define ext2_set_bit_atomic(l,n,a) test_and_set_bit(n,a)
-#define ext2_clear_bit test_and_clear_bit
+#define ext2_clear_bit __test_and_clear_bit
#define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)
#define ext2_test_bit test_bit
#define ext2_find_first_zero_bit find_first_zero_bit
#define ext2_find_next_zero_bit find_next_zero_bit
/* Bitmap functions for the minix filesystem. */
-#define minix_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-frv/bitops.h
=================================--- 2.6-git.orig/include/asm-frv/bitops.h
+++ 2.6-git/include/asm-frv/bitops.h
@@ -259,11 +259,11 @@ static inline int sched_find_first_bit(c
#define hweight16(x) generic_hweight16(x)
#define hweight8(x) generic_hweight8(x)
-#define ext2_set_bit(nr, addr) test_and_set_bit ((nr) ^ 0x18, (addr))
-#define ext2_clear_bit(nr, addr) test_and_clear_bit((nr) ^ 0x18, (addr))
+#define ext2_set_bit(nr, addr) __test_and_set_bit ((nr) ^ 0x18, (addr))
+#define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 0x18, (addr))
-#define ext2_set_bit_atomic(lock,nr,addr) ext2_set_bit((nr), addr)
-#define ext2_clear_bit_atomic(lock,nr,addr) ext2_clear_bit((nr), addr)
+#define ext2_set_bit_atomic(lock,nr,addr) test_and_set_bit ((nr) ^ 0x18, (addr))
+#define ext2_clear_bit_atomic(lock,nr,addr) test_and_clear_bit((nr) ^ 0x18, (addr))
static inline int ext2_test_bit(int nr, const volatile void * addr)
{
@@ -331,9 +331,9 @@ found_middle:
}
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) ext2_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) ext2_set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) ext2_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit ((nr) ^ 0x18, (addr))
+#define minix_set_bit(nr,addr) __set_bit((nr) ^ 0x18, (addr))
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit((nr) ^ 0x18, (addr))
#define minix_test_bit(nr,addr) ext2_test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) ext2_find_first_zero_bit(addr,size)
Index: 2.6-git/include/asm-m68k/bitops.h
=================================--- 2.6-git.orig/include/asm-m68k/bitops.h
+++ 2.6-git/include/asm-m68k/bitops.h
@@ -365,9 +365,9 @@ static inline int minix_find_first_zero_
return ((p - addr) << 4) + (res ^ 31);
}
-#define minix_test_and_set_bit(nr, addr) test_and_set_bit((nr) ^ 16, (unsigned long *)(addr))
-#define minix_set_bit(nr,addr) set_bit((nr) ^ 16, (unsigned long *)(addr))
-#define minix_test_and_clear_bit(nr, addr) test_and_clear_bit((nr) ^ 16, (unsigned long *)(addr))
+#define minix_test_and_set_bit(nr, addr) __test_and_set_bit((nr) ^ 16, (unsigned long *)(addr))
+#define minix_set_bit(nr,addr) __set_bit((nr) ^ 16, (unsigned long *)(addr))
+#define minix_test_and_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 16, (unsigned long *)(addr))
static inline int minix_test_bit(int nr, const void *vaddr)
{
@@ -377,9 +377,9 @@ static inline int minix_test_bit(int nr,
/* Bitmap functions for the ext2 filesystem. */
-#define ext2_set_bit(nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
+#define ext2_set_bit(nr, addr) __test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
#define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
-#define ext2_clear_bit(nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
+#define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
#define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
static inline int ext2_test_bit(int nr, const void *vaddr)
Index: 2.6-git/include/asm-m68knommu/bitops.h
=================================--- 2.6-git.orig/include/asm-m68knommu/bitops.h
+++ 2.6-git/include/asm-m68knommu/bitops.h
@@ -476,9 +476,9 @@ found_middle:
}
/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) test_and_set_bit(nr,addr)
-#define minix_set_bit(nr,addr) set_bit(nr,addr)
-#define minix_test_and_clear_bit(nr,addr) test_and_clear_bit(nr,addr)
+#define minix_test_and_set_bit(nr,addr) __test_and_set_bit(nr,addr)
+#define minix_set_bit(nr,addr) __set_bit(nr,addr)
+#define minix_test_and_clear_bit(nr,addr) __test_and_clear_bit(nr,addr)
#define minix_test_bit(nr,addr) test_bit(nr,addr)
#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 06/44] generic __{,test_and_}{set,clear,change}_bit() and test_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
2006-02-01 9:02 ` [patch 04/44] use non atomic operations for minix_*_bit() and ext2_*_bit() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 07/44] generic __ffs() Akinobu Mita
` (10 subsequent siblings)
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, Russell King, Ian Molton,
dev-etrax, linux-ia64, Hirokazu Takata, linux-mips, parisc-linux,
linuxppc-dev, linuxsh-dev, linuxsh-shmedia-dev, sparclinux,
ultralinux, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalents of the functions below:
void __set_bit(int nr, volatile unsigned long *addr);
void __clear_bit(int nr, volatile unsigned long *addr);
void __change_bit(int nr, volatile unsigned long *addr);
int __test_and_set_bit(int nr, volatile unsigned long *addr);
int __test_and_clear_bit(int nr, volatile unsigned long *addr);
int __test_and_change_bit(int nr, volatile unsigned long *addr);
int test_bit(int nr, const volatile unsigned long *addr);
In include/asm-generic/bitops/non-atomic.h
This code largely copied from:
asm-powerpc/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/non-atomic.h | 111 ++++++++++++++++++++++++++++++++
1 files changed, 111 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/non-atomic.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/non-atomic.h
@@ -0,0 +1,111 @@
+#ifndef _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
+#define _ASM_GENERIC_BITOPS_NON_ATOMIC_H_
+
+#include <asm/types.h>
+
+#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
+#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
+
+/**
+ * __set_bit - Set a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * Unlike set_bit(), this function is non-atomic and may be reordered.
+ * If it's called on the same region of memory simultaneously, the effect
+ * may be that only one operation succeeds.
+ */
+static __inline__ void __set_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BITOP_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
+
+ *p |= mask;
+}
+
+static __inline__ void __clear_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BITOP_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
+
+ *p &= ~mask;
+}
+
+/**
+ * __change_bit - Toggle a bit in memory
+ * @nr: the bit to change
+ * @addr: the address to start counting from
+ *
+ * Unlike change_bit(), this function is non-atomic and may be reordered.
+ * If it's called on the same region of memory simultaneously, the effect
+ * may be that only one operation succeeds.
+ */
+static __inline__ void __change_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BITOP_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
+
+ *p ^= mask;
+}
+
+/**
+ * __test_and_set_bit - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is non-atomic and can be reordered.
+ * If two examples of this operation race, one can appear to succeed
+ * but actually fail. You must protect multiple accesses with a lock.
+ */
+static __inline__ int __test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BITOP_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
+ unsigned long old = *p;
+
+ *p = old | mask;
+ return (old & mask) != 0;
+}
+
+/**
+ * __test_and_clear_bit - Clear a bit and return its old value
+ * @nr: Bit to clear
+ * @addr: Address to count from
+ *
+ * This operation is non-atomic and can be reordered.
+ * If two examples of this operation race, one can appear to succeed
+ * but actually fail. You must protect multiple accesses with a lock.
+ */
+static __inline__ int __test_and_clear_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BITOP_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
+ unsigned long old = *p;
+
+ *p = old & ~mask;
+ return (old & mask) != 0;
+}
+
+/* WARNING: non atomic and it can be reordered! */
+static __inline__ int __test_and_change_bit(int nr,
+ volatile unsigned long *addr)
+{
+ unsigned long mask = BITOP_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
+ unsigned long old = *p;
+
+ *p = old ^ mask;
+ return (old & mask) != 0;
+}
+
+/**
+ * test_bit - Determine whether a bit is set
+ * @nr: bit number to test
+ * @addr: Address to start counting from
+ */
+static __inline__ int test_bit(int nr, __const__ volatile unsigned long *addr)
+{
+ return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
+}
+
+#endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 07/44] generic __ffs()
[not found] <20060201090224.536581000@localhost.localdomain>
2006-02-01 9:02 ` [patch 04/44] use non atomic operations for minix_*_bit() and ext2_*_bit() Akinobu Mita
2006-02-01 9:02 ` [patch 06/44] generic __{,test_and_}{set,clear,change}_bit() and test_bit() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 08/44] generic ffz() Akinobu Mita
` (9 subsequent siblings)
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Russell King, Ian Molton, David Howells, Hirokazu Takata,
Greg Ungerer, linux-mips, linuxsh-dev, linuxsh-shmedia-dev,
sparclinux, ultralinux, Miles Bader, Akinobu Mita
This patch introduces the C-language equivalent of the function:
unsigned long __ffs(unsigned long word);
In include/asm-generic/bitops/__ffs.h
This code largely copied from:
include/asm-sparc/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/__ffs.h | 43 +++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/__ffs.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/__ffs.h
@@ -0,0 +1,43 @@
+#ifndef _ASM_GENERIC_BITOPS___FFS_H_
+#define _ASM_GENERIC_BITOPS___FFS_H_
+
+#include <asm/types.h>
+
+/**
+ * __ffs - find first bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+ int num = 0;
+
+#if BITS_PER_LONG = 64
+ if ((word & 0xffffffff) = 0) {
+ num += 32;
+ word >>= 32;
+ }
+#endif
+ if ((word & 0xffff) = 0) {
+ num += 16;
+ word >>= 16;
+ }
+ if ((word & 0xff) = 0) {
+ num += 8;
+ word >>= 8;
+ }
+ if ((word & 0xf) = 0) {
+ num += 4;
+ word >>= 4;
+ }
+ if ((word & 0x3) = 0) {
+ num += 2;
+ word >>= 2;
+ }
+ if ((word & 0x1) = 0)
+ num += 1;
+ return num;
+}
+
+#endif /* _ASM_GENERIC_BITOPS___FFS_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 08/44] generic ffz()
[not found] <20060201090224.536581000@localhost.localdomain>
` (2 preceding siblings ...)
2006-02-01 9:02 ` [patch 07/44] generic __ffs() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 09/44] generic fls() Akinobu Mita
` (8 subsequent siblings)
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Russell King, Ian Molton, David Howells, Hirokazu Takata,
Greg Ungerer, linux-mips, parisc-linux, sparclinux, ultralinux,
Miles Bader, Akinobu Mita
This patch introduces the C-language equivalent of the function:
unsigned long ffz(unsigned long word);
In include/asm-generic/bitops/ffz.h
This code largely copied from:
include/asm-parisc/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/ffz.h | 12 ++++++++++++
1 files changed, 12 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/ffz.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/ffz.h
@@ -0,0 +1,12 @@
+#ifndef _ASM_GENERIC_BITOPS_FFZ_H_
+#define _ASM_GENERIC_BITOPS_FFZ_H_
+
+/*
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+#define ffz(x) __ffs(~(x))
+
+#endif /* _ASM_GENERIC_BITOPS_FFZ_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 09/44] generic fls()
[not found] <20060201090224.536581000@localhost.localdomain>
` (3 preceding siblings ...)
2006-02-01 9:02 ` [patch 08/44] generic ffz() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 10/44] generic fls64() Akinobu Mita
` (7 subsequent siblings)
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, Russell King, Ian Molton,
dev-etrax, Yoshinori Sato, Hirokazu Takata, Greg Ungerer,
linux-mips, linux390, linuxsh-dev, linuxsh-shmedia-dev,
sparclinux, ultralinux, Miles Bader, Akinobu Mita
This patch introduces the C-language equivalent of the function:
int fls(int x);
In include/asm-generic/bitops/fls.h
This code largely copied from:
include/linux/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/fls.h | 41 +++++++++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/fls.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/fls.h
@@ -0,0 +1,41 @@
+#ifndef _ASM_GENERIC_BITOPS_FLS_H_
+#define _ASM_GENERIC_BITOPS_FLS_H_
+
+/**
+ * fls - find last (most-significant) bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
+ */
+
+static __inline__ int fls(int x)
+{
+ int r = 32;
+
+ if (!x)
+ return 0;
+ if (!(x & 0xffff0000u)) {
+ x <<= 16;
+ r -= 16;
+ }
+ if (!(x & 0xff000000u)) {
+ x <<= 8;
+ r -= 8;
+ }
+ if (!(x & 0xf0000000u)) {
+ x <<= 4;
+ r -= 4;
+ }
+ if (!(x & 0xc0000000u)) {
+ x <<= 2;
+ r -= 2;
+ }
+ if (!(x & 0x80000000u)) {
+ x <<= 1;
+ r -= 1;
+ }
+ return r;
+}
+
+#endif /* _ASM_GENERIC_BITOPS_FLS_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 10/44] generic fls64()
[not found] <20060201090224.536581000@localhost.localdomain>
` (4 preceding siblings ...)
2006-02-01 9:02 ` [patch 09/44] generic fls() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-02 15:05 ` Rune Torgersen
2006-02-01 9:02 ` [patch 11/44] generic find_{next,first}{,_zero}_bit() Akinobu Mita
` (6 subsequent siblings)
12 siblings, 1 reply; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, Russell King, Ian Molton,
dev-etrax, David Howells, Yoshinori Sato, Linus Torvalds,
linux-ia64, Hirokazu Takata, linux-m68k, Greg Ungerer, linux-mips,
parisc-linux, linuxppc-dev, linux390, linuxsh-dev,
linuxsh-shmedia-dev, sparclinux, ultralinux, Miles Bader,
Andi Kleen, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalent of the function:
int fls64(__u64 x);
In include/asm-generic/bitops/fls64.h
This code largely copied from:
include/linux/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/fls64.h | 12 ++++++++++++
1 files changed, 12 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/fls64.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/fls64.h
@@ -0,0 +1,12 @@
+#ifndef _ASM_GENERIC_BITOPS_FLS64_H_
+#define _ASM_GENERIC_BITOPS_FLS64_H_
+
+static inline int fls64(__u64 x)
+{
+ __u32 h = x >> 32;
+ if (h)
+ return fls(x) + 32;
+ return fls(x);
+}
+
+#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 11/44] generic find_{next,first}{,_zero}_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (5 preceding siblings ...)
2006-02-01 9:02 ` [patch 10/44] generic fls64() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-06 10:26 ` David Howells
2006-02-01 9:02 ` [patch 12/44] generic sched_find_first_bit() Akinobu Mita
` (5 subsequent siblings)
12 siblings, 1 reply; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, dev-etrax, David Howells,
Yoshinori Sato, linux-ia64, Hirokazu Takata, Greg Ungerer,
linux-mips, parisc-linux, linuxsh-dev, linuxsh-shmedia-dev,
sparclinux, ultralinux, Miles Bader, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalents of the functions below:
unsigned logn find_next_bit(const unsigned long *addr, unsigned long size,
unsigned long offset);
unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
unsigned long offset);
unsigned long find_first_zero_bit(const unsigned long *addr,
unsigned long size);
unsigned long find_first_bit(const unsigned long *addr, unsigned long size);
In include/asm-generic/bitops/find.h
This code largely copied from:
arch/powerpc/lib/bitops.c
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/find.h | 99 ++++++++++++++++++++++++++++++++++++++
1 files changed, 99 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/find.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/find.h
@@ -0,0 +1,99 @@
+#ifndef _ASM_GENERIC_BITOPS_FIND_H_
+#define _ASM_GENERIC_BITOPS_FIND_H_
+
+#include <asm/types.h>
+
+#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
+
+/**
+ * find_next_bit - find the next set bit in a memory region
+ * @addr: The address to base the search on
+ * @offset: The bitnumber to start searching at
+ * @size: The maximum size to search
+ */
+static inline unsigned long find_next_bit(const unsigned long *addr,
+ unsigned long size, unsigned long offset)
+{
+ const unsigned long *p = addr + BITOP_WORD(offset);
+ unsigned long result = offset & ~(BITS_PER_LONG-1);
+ unsigned long tmp;
+
+ if (offset >= size)
+ return size;
+ size -= result;
+ offset %= BITS_PER_LONG;
+ if (offset) {
+ tmp = *(p++);
+ tmp &= (~0UL << offset);
+ if (size < BITS_PER_LONG)
+ goto found_first;
+ if (tmp)
+ goto found_middle;
+ size -= BITS_PER_LONG;
+ result += BITS_PER_LONG;
+ }
+ while (size & ~(BITS_PER_LONG-1)) {
+ if ((tmp = *(p++)))
+ goto found_middle;
+ result += BITS_PER_LONG;
+ size -= BITS_PER_LONG;
+ }
+ if (!size)
+ return result;
+ tmp = *p;
+
+found_first:
+ tmp &= (~0UL >> (BITS_PER_LONG - size));
+ if (tmp = 0UL) /* Are any bits set? */
+ return result + size; /* Nope. */
+found_middle:
+ return result + __ffs(tmp);
+}
+
+/*
+ * This implementation of find_{first,next}_zero_bit was stolen from
+ * Linus' asm-alpha/bitops.h.
+ */
+static inline unsigned long find_next_zero_bit(const unsigned long *addr,
+ unsigned long size, unsigned long offset)
+{
+ const unsigned long *p = addr + BITOP_WORD(offset);
+ unsigned long result = offset & ~(BITS_PER_LONG-1);
+ unsigned long tmp;
+
+ if (offset >= size)
+ return size;
+ size -= result;
+ offset %= BITS_PER_LONG;
+ if (offset) {
+ tmp = *(p++);
+ tmp |= ~0UL >> (BITS_PER_LONG - offset);
+ if (size < BITS_PER_LONG)
+ goto found_first;
+ if (~tmp)
+ goto found_middle;
+ size -= BITS_PER_LONG;
+ result += BITS_PER_LONG;
+ }
+ while (size & ~(BITS_PER_LONG-1)) {
+ if (~(tmp = *(p++)))
+ goto found_middle;
+ result += BITS_PER_LONG;
+ size -= BITS_PER_LONG;
+ }
+ if (!size)
+ return result;
+ tmp = *p;
+
+found_first:
+ tmp |= ~0UL << size;
+ if (tmp = ~0UL) /* Are any bits zero? */
+ return result + size; /* Nope. */
+found_middle:
+ return result + ffz(tmp);
+}
+
+#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
+#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
+
+#endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 12/44] generic sched_find_first_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (6 preceding siblings ...)
2006-02-01 9:02 ` [patch 11/44] generic find_{next,first}{,_zero}_bit() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-03 3:58 ` [parisc-linux] " Grant Grundler
2006-02-01 9:02 ` [patch 13/44] generic ffs() Akinobu Mita
` (4 subsequent siblings)
12 siblings, 1 reply; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Russell King, Ian Molton, dev-etrax, David Howells,
Yoshinori Sato, Linus Torvalds, linux-ia64, Hirokazu Takata,
linux-m68k, Greg Ungerer, linux-mips, parisc-linux, linuxppc-dev,
linux390, linuxsh-dev, linuxsh-shmedia-dev, sparclinux,
ultralinux, Miles Bader, Andi Kleen, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalent of the function:
int sched_find_first_bit(const unsigned long *b);
In include/asm-generic/bitops/sched.h
This code largely copied from:
include/asm-powerpc/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/sched.h | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/sched.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/sched.h
@@ -0,0 +1,36 @@
+#ifndef _ASM_GENERIC_BITOPS_SCHED_H_
+#define _ASM_GENERIC_BITOPS_SCHED_H_
+
+#include <linux/compiler.h> /* unlikely() */
+#include <asm/types.h>
+
+/*
+ * Every architecture must define this function. It's the fastest
+ * way of searching a 140-bit bitmap where the first 100 bits are
+ * unlikely to be set. It's guaranteed that at least one of the 140
+ * bits is cleared.
+ */
+static inline int sched_find_first_bit(const unsigned long *b)
+{
+#if BITS_PER_LONG = 64
+ if (unlikely(b[0]))
+ return __ffs(b[0]);
+ if (unlikely(b[1]))
+ return __ffs(b[1]) + 64;
+ return __ffs(b[2]) + 128;
+#elif BITS_PER_LONG = 32
+ if (unlikely(b[0]))
+ return __ffs(b[0]);
+ if (unlikely(b[1]))
+ return __ffs(b[1]) + 32;
+ if (unlikely(b[2]))
+ return __ffs(b[2]) + 64;
+ if (b[3])
+ return __ffs(b[3]) + 96;
+ return __ffs(b[4]) + 128;
+#else
+#error BITS_PER_LONG not defined
+#endif
+}
+
+#endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 13/44] generic ffs()
[not found] <20060201090224.536581000@localhost.localdomain>
` (7 preceding siblings ...)
2006-02-01 9:02 ` [patch 12/44] generic sched_find_first_bit() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 14/44] generic hweight{64,32,16,8}() Akinobu Mita
` (3 subsequent siblings)
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Greg Ungerer, linux-mips, sparclinux, ultralinux, Akinobu Mita
This patch introduces the C-language equivalent of the function:
int ffs(int x);
In include/asm-generic/bitops/ffs.h
This code largely copied from:
include/linux/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/ffs.h | 41 +++++++++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/ffs.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/ffs.h
@@ -0,0 +1,41 @@
+#ifndef _ASM_GENERIC_BITOPS_FFS_H_
+#define _ASM_GENERIC_BITOPS_FFS_H_
+
+/**
+ * ffs - find first bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as
+ * the libc and compiler builtin ffs routines, therefore
+ * differs in spirit from the above ffz (man ffs).
+ */
+static inline int ffs(int x)
+{
+ int r = 1;
+
+ if (!x)
+ return 0;
+ if (!(x & 0xffff)) {
+ x >>= 16;
+ r += 16;
+ }
+ if (!(x & 0xff)) {
+ x >>= 8;
+ r += 8;
+ }
+ if (!(x & 0xf)) {
+ x >>= 4;
+ r += 4;
+ }
+ if (!(x & 3)) {
+ x >>= 2;
+ r += 2;
+ }
+ if (!(x & 1)) {
+ x >>= 1;
+ r += 1;
+ }
+ return r;
+}
+
+#endif /* _ASM_GENERIC_BITOPS_FFS_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 14/44] generic hweight{64,32,16,8}()
[not found] <20060201090224.536581000@localhost.localdomain>
` (8 preceding siblings ...)
2006-02-01 9:02 ` [patch 13/44] generic ffs() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:06 ` Andi Kleen
` (2 more replies)
2006-02-01 9:02 ` [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit() Akinobu Mita
` (2 subsequent siblings)
12 siblings, 3 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, Russell King, Ian Molton,
dev-etrax, David Howells, Yoshinori Sato, Linus Torvalds,
linux-ia64, Hirokazu Takata, linux-m68k, Greg Ungerer, linux-mips,
parisc-linux, linuxppc-dev, linux390, linuxsh-dev,
linuxsh-shmedia-dev, sparclinux, ultralinux, Miles Bader,
Andi Kleen, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalents of the functions below:
unsigned int hweight32(unsigned int w);
unsigned int hweight16(unsigned int w);
unsigned int hweight8(unsigned int w);
unsigned long hweight64(__u64 w);
In include/asm-generic/bitops/hweight.h
This code largely copied from:
include/linux/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/hweight.h | 54 +++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/hweight.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/hweight.h
@@ -0,0 +1,54 @@
+#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_
+#define _ASM_GENERIC_BITOPS_HWEIGHT_H_
+
+#include <asm/types.h>
+
+/**
+ * hweightN - returns the hamming weight of a N-bit word
+ * @x: the word to weigh
+ *
+ * The Hamming Weight of a number is the total number of bits set in it.
+ */
+
+static inline unsigned int hweight32(unsigned int w)
+{
+ unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
+ res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+ res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
+ res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
+ return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
+}
+
+static inline unsigned int hweight16(unsigned int w)
+{
+ unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
+ res = (res & 0x3333) + ((res >> 2) & 0x3333);
+ res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
+ return (res & 0x00FF) + ((res >> 8) & 0x00FF);
+}
+
+static inline unsigned int hweight8(unsigned int w)
+{
+ unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
+ res = (res & 0x33) + ((res >> 2) & 0x33);
+ return (res & 0x0F) + ((res >> 4) & 0x0F);
+}
+
+static inline unsigned long hweight64(__u64 w)
+{
+#if BITS_PER_LONG = 32
+ return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
+#elif BITS_PER_LONG = 64
+ u64 res;
+ res = (w & 0x5555555555555555ul) + ((w >> 1) & 0x5555555555555555ul);
+ res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
+ res = (res & 0x0F0F0F0F0F0F0F0Ful) + ((res >> 4) & 0x0F0F0F0F0F0F0F0Ful);
+ res = (res & 0x00FF00FF00FF00FFul) + ((res >> 8) & 0x00FF00FF00FF00FFul);
+ res = (res & 0x0000FFFF0000FFFFul) + ((res >> 16) & 0x0000FFFF0000FFFFul);
+ return (res & 0x00000000FFFFFFFFul) + ((res >> 32) & 0x00000000FFFFFFFFul);
+#else
+#error BITS_PER_LONG not defined
+#endif
+}
+
+#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (9 preceding siblings ...)
2006-02-01 9:02 ` [patch 14/44] generic hweight{64,32,16,8}() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 11:27 ` Roman Zippel
2006-02-01 9:02 ` [patch 17/44] generic minix_{test,set,test_and_clear,test,find_first_zero}_bit() Akinobu Mita
2006-02-01 9:03 ` [patch 36/44] sparc64: use generic bitops Akinobu Mita
12 siblings, 1 reply; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, dev-etrax, David Howells,
Yoshinori Sato, Linus Torvalds, linux-ia64, Hirokazu Takata,
linux-m68k, linux-mips, parisc-linux, linuxsh-dev,
linuxsh-shmedia-dev, sparclinux, ultralinux, Miles Bader,
Andi Kleen, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalents of the functions below:
int ext2_set_bit(int nr, volatile unsigned long *addr);
int ext2_clear_bit(int nr, volatile unsigned long *addr);
int ext2_test_bit(int nr, const volatile unsigned long *addr);
unsigned long ext2_find_first_zero_bit(const unsigned long *addr,
unsigned long size);
unsinged long ext2_find_next_zero_bit(const unsigned long *addr,
unsigned long size);
In include/asm-generic/bitops/ext2-non-atomic.h
This code largely copied from:
include/asm-powerpc/bitops.h
include/asm-parisc/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/ext2-non-atomic.h | 18 +++
include/asm-generic/bitops/le.h | 126 +++++++++++++++++++++++++++
2 files changed, 144 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/ext2-non-atomic.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/ext2-non-atomic.h
@@ -0,0 +1,18 @@
+#ifndef _ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_
+#define _ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_
+
+#include <asm-generic/bitops/le.h>
+
+#define ext2_set_bit(nr,addr) \
+ generic___test_and_set_le_bit((nr),(unsigned long *)(addr))
+#define ext2_clear_bit(nr,addr) \
+ generic___test_and_clear_le_bit((nr),(unsigned long *)(addr))
+
+#define ext2_test_bit(nr,addr) \
+ generic_test_le_bit((nr),(unsigned long *)(addr))
+#define ext2_find_first_zero_bit(addr, size) \
+ generic_find_first_zero_le_bit((unsigned long *)(addr), (size))
+#define ext2_find_next_zero_bit(addr, size, off) \
+ generic_find_next_zero_le_bit((unsigned long *)(addr), (size), (off))
+
+#endif /* _ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_ */
Index: 2.6-git/include/asm-generic/bitops/le.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/le.h
@@ -0,0 +1,126 @@
+#ifndef _ASM_GENERIC_BITOPS_LE_H_
+#define _ASM_GENERIC_BITOPS_LE_H_
+
+#include <asm/types.h>
+#include <asm/byteorder.h>
+
+#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
+#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
+
+#if defined(__LITTLE_ENDIAN)
+
+static __inline__ int generic_test_le_bit(unsigned long nr,
+ __const__ unsigned long *addr)
+{
+ __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
+ return (tmp[nr >> 3] >> (nr & 7)) & 1;
+}
+
+#define generic___set_le_bit(nr, addr) __set_bit(nr, addr)
+#define generic___clear_le_bit(nr, addr) __clear_bit(nr, addr)
+
+#define generic_test_and_set_le_bit(nr, addr) test_and_set_bit(nr, addr)
+#define generic_test_and_clear_le_bit(nr, addr) test_and_clear_bit(nr, addr)
+
+#define generic___test_and_set_le_bit(nr, addr) __test_and_set_bit(nr, addr)
+#define generic___test_and_clear_le_bit(nr, addr) __test_and_clear_bit(nr, addr)
+
+#define generic_find_next_zero_le_bit(addr, size, offset) find_next_zero_bit(addr, size, offset)
+
+#elif defined(__BIG_ENDIAN)
+
+static __inline__ int generic_test_le_bit(unsigned long nr,
+ __const__ unsigned long *addr)
+{
+ __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
+ return (tmp[nr >> 3] >> (nr & 7)) & 1;
+}
+
+#define generic___set_le_bit(nr, addr) \
+ __set_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
+#define generic___clear_le_bit(nr, addr) \
+ __clear_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
+
+#define generic_test_and_set_le_bit(nr, addr) \
+ test_and_set_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
+#define generic_test_and_clear_le_bit(nr, addr) \
+ test_and_clear_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
+
+#define generic___test_and_set_le_bit(nr, addr) \
+ __test_and_set_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
+#define generic___test_and_clear_le_bit(nr, addr) \
+ __test_and_clear_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
+
+/* include/linux/byteorder does not support "unsigned long" type */
+static inline unsigned long ext2_swabp(const unsigned long * x)
+{
+#if BITS_PER_LONG = 64
+ return (unsigned long) __swab64p((u64 *) x);
+#elif BITS_PER_LONG = 32
+ return (unsigned long) __swab32p((u32 *) x);
+#else
+#error BITS_PER_LONG not defined
+#endif
+}
+
+/* include/linux/byteorder doesn't support "unsigned long" type */
+static inline unsigned long ext2_swab(const unsigned long y)
+{
+#if BITS_PER_LONG = 64
+ return (unsigned long) __swab64((u64) y);
+#elif BITS_PER_LONG = 32
+ return (unsigned long) __swab32((u32) y);
+#else
+#error BITS_PER_LONG not defined
+#endif
+}
+
+static __inline__ unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
+ unsigned long size, unsigned long offset)
+{
+ const unsigned long *p = addr + BITOP_WORD(offset);
+ unsigned long result = offset & ~(BITS_PER_LONG - 1);
+ unsigned long tmp;
+
+ if (offset >= size)
+ return size;
+ size -= result;
+ offset &= (BITS_PER_LONG - 1UL);
+ if (offset) {
+ tmp = ext2_swabp(p++);
+ tmp |= (~0UL >> (BITS_PER_LONG - offset));
+ if (size < BITS_PER_LONG)
+ goto found_first;
+ if (~tmp)
+ goto found_middle;
+ size -= BITS_PER_LONG;
+ result += BITS_PER_LONG;
+ }
+
+ while (size & ~(BITS_PER_LONG - 1)) {
+ if (~(tmp = *(p++)))
+ goto found_middle_swap;
+ result += BITS_PER_LONG;
+ size -= BITS_PER_LONG;
+ }
+ if (!size)
+ return result;
+ tmp = ext2_swabp(p);
+found_first:
+ tmp |= ~0UL << size;
+ if (tmp = ~0UL) /* Are any bits zero? */
+ return result + size; /* Nope. Skip ffz */
+found_middle:
+ return result + ffz(tmp);
+
+found_middle_swap:
+ return result + ffz(ext2_swab(tmp));
+}
+#else
+#error "Please fix <asm/byteorder.h>"
+#endif
+
+#define generic_find_first_zero_le_bit(addr, size) \
+ generic_find_next_zero_le_bit((addr), (size), 0)
+
+#endif /* _ASM_GENERIC_BITOPS_LE_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 17/44] generic minix_{test,set,test_and_clear,test,find_first_zero}_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (10 preceding siblings ...)
2006-02-01 9:02 ` [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit() Akinobu Mita
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:03 ` [patch 36/44] sparc64: use generic bitops Akinobu Mita
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, dev-etrax, David Howells,
Yoshinori Sato, Linus Torvalds, linux-ia64, Hirokazu Takata,
Greg Ungerer, linux-mips, linux390, linuxsh-dev,
linuxsh-shmedia-dev, sparclinux, ultralinux, Miles Bader,
Andi Kleen, Chris Zankel, Akinobu Mita
This patch introduces the C-language equivalents of the functions below:
int minix_test_and_set_bit(int nr, volatile unsigned long *addr);
int minix_set_bit(int nr, volatile unsigned long *addr);
int minix_test_and_clear_bit(int nr, volatile unsigned long *addr);
int minix_test_bit(int nr, const volatile unsigned long *addr);
unsigned long minix_find_first_zero_bit(const unsigned long *addr,
unsigned long size);
In include/asm-generic/bitops/minix.h
and include/asm-generic/bitops/minix-le.h
This code largely copied from:
include/asm-sparc/bitops.h
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-generic/bitops/minix-le.h | 17 +++++++++++++++++
include/asm-generic/bitops/minix.h | 15 +++++++++++++++
2 files changed, 32 insertions(+)
Index: 2.6-git/include/asm-generic/bitops/minix.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/minix.h
@@ -0,0 +1,15 @@
+#ifndef _ASM_GENERIC_BITOPS_MINIX_H_
+#define _ASM_GENERIC_BITOPS_MINIX_H_
+
+#define minix_test_and_set_bit(nr,addr) \
+ __test_and_set_bit((nr),(unsigned long *)(addr))
+#define minix_set_bit(nr,addr) \
+ __set_bit((nr),(unsigned long *)(addr))
+#define minix_test_and_clear_bit(nr,addr) \
+ __test_and_clear_bit((nr),(unsigned long *)(addr))
+#define minix_test_bit(nr,addr) \
+ test_bit((nr),(unsigned long *)(addr))
+#define minix_find_first_zero_bit(addr,size) \
+ find_first_zero_bit((unsigned long *)(addr),(size))
+
+#endif /* _ASM_GENERIC_BITOPS_MINIX_H_ */
Index: 2.6-git/include/asm-generic/bitops/minix-le.h
=================================--- /dev/null
+++ 2.6-git/include/asm-generic/bitops/minix-le.h
@@ -0,0 +1,17 @@
+#ifndef _ASM_GENERIC_BITOPS_MINIX_LE_H_
+#define _ASM_GENERIC_BITOPS_MINIX_LE_H_
+
+#include <asm-generic/bitops/le.h>
+
+#define minix_test_and_set_bit(nr,addr) \
+ generic___test_and_set_le_bit((nr),(unsigned long *)(addr))
+#define minix_set_bit(nr,addr) \
+ generic___set_le_bit((nr),(unsigned long *)(addr))
+#define minix_test_and_clear_bit(nr,addr) \
+ generic___test_and_clear_le_bit((nr),(unsigned long *)(addr))
+#define minix_test_bit(nr,addr) \
+ generic_test_le_bit((nr),(unsigned long *)(addr))
+#define minix_find_first_zero_bit(addr,size) \
+ generic_find_first_zero_le_bit((unsigned long *)(addr),(size))
+
+#endif /* _ASM_GENERIC_BITOPS_MINIX_LE_H_ */
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* [patch 36/44] sparc64: use generic bitops
[not found] <20060201090224.536581000@localhost.localdomain>
` (11 preceding siblings ...)
2006-02-01 9:02 ` [patch 17/44] generic minix_{test,set,test_and_clear,test,find_first_zero}_bit() Akinobu Mita
@ 2006-02-01 9:03 ` Akinobu Mita
12 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:03 UTC (permalink / raw)
To: linux-kernel; +Cc: ultralinux, Akinobu Mita
- remove __{,test_and_}{set,clear,change}_bit() and test_bit()
- remove ffz()
- remove __ffs()
- remove generic_fls()
- remove generic_fls64()
- remove sched_find_first_bit()
- remove ffs()
- unless defined(ULTRA_HAS_POPULATION_COUNT)
- remove generic_hweight{64,32,16,8}()
- remove find_{next,first}{,_zero}_bit()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
arch/sparc64/kernel/sparc64_ksyms.c | 5
arch/sparc64/lib/Makefile | 2
arch/sparc64/lib/find_bit.c | 127 --------------------
include/asm-sparc64/bitops.h | 221 ++----------------------------------
4 files changed, 15 insertions(+), 340 deletions(-)
Index: 2.6-git/include/asm-sparc64/bitops.h
=================================--- 2.6-git.orig/include/asm-sparc64/bitops.h
+++ 2.6-git/include/asm-sparc64/bitops.h
@@ -18,58 +18,7 @@ extern void set_bit(unsigned long nr, vo
extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
extern void change_bit(unsigned long nr, volatile unsigned long *addr);
-/* "non-atomic" versions... */
-
-static inline void __set_bit(int nr, volatile unsigned long *addr)
-{
- unsigned long *m = ((unsigned long *)addr) + (nr >> 6);
-
- *m |= (1UL << (nr & 63));
-}
-
-static inline void __clear_bit(int nr, volatile unsigned long *addr)
-{
- unsigned long *m = ((unsigned long *)addr) + (nr >> 6);
-
- *m &= ~(1UL << (nr & 63));
-}
-
-static inline void __change_bit(int nr, volatile unsigned long *addr)
-{
- unsigned long *m = ((unsigned long *)addr) + (nr >> 6);
-
- *m ^= (1UL << (nr & 63));
-}
-
-static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
-{
- unsigned long *m = ((unsigned long *)addr) + (nr >> 6);
- unsigned long old = *m;
- unsigned long mask = (1UL << (nr & 63));
-
- *m = (old | mask);
- return ((old & mask) != 0);
-}
-
-static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
-{
- unsigned long *m = ((unsigned long *)addr) + (nr >> 6);
- unsigned long old = *m;
- unsigned long mask = (1UL << (nr & 63));
-
- *m = (old & ~mask);
- return ((old & mask) != 0);
-}
-
-static inline int __test_and_change_bit(int nr, volatile unsigned long *addr)
-{
- unsigned long *m = ((unsigned long *)addr) + (nr >> 6);
- unsigned long old = *m;
- unsigned long mask = (1UL << (nr & 63));
-
- *m = (old ^ mask);
- return ((old & mask) != 0);
-}
+#include <asm-generic/bitops/non-atomic.h>
#ifdef CONFIG_SMP
#define smp_mb__before_clear_bit() membar_storeload_loadload()
@@ -79,78 +28,15 @@ static inline int __test_and_change_bit(
#define smp_mb__after_clear_bit() barrier()
#endif
-static inline int test_bit(int nr, __const__ volatile unsigned long *addr)
-{
- return (1UL & (addr[nr >> 6] >> (nr & 63))) != 0UL;
-}
-
-/* The easy/cheese version for now. */
-static inline unsigned long ffz(unsigned long word)
-{
- unsigned long result;
-
- result = 0;
- while(word & 1) {
- result++;
- word >>= 1;
- }
- return result;
-}
-
-/**
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- */
-static inline unsigned long __ffs(unsigned long word)
-{
- unsigned long result = 0;
-
- while (!(word & 1UL)) {
- result++;
- word >>= 1;
- }
- return result;
-}
-
-/*
- * fls: find last bit set.
- */
-
-#define fls(x) generic_fls(x)
-#define fls64(x) generic_fls64(x)
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/fls64.h>
#ifdef __KERNEL__
-/*
- * Every architecture must define this function. It's the fastest
- * way of searching a 140-bit bitmap where the first 100 bits are
- * unlikely to be set. It's guaranteed that at least one of the 140
- * bits is cleared.
- */
-static inline int sched_find_first_bit(unsigned long *b)
-{
- if (unlikely(b[0]))
- return __ffs(b[0]);
- if (unlikely(((unsigned int)b[1])))
- return __ffs(b[1]) + 64;
- if (b[1] >> 32)
- return __ffs(b[1] >> 32) + 96;
- return __ffs(b[2]) + 128;
-}
-
-/*
- * ffs: find first bit set. This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-static inline int ffs(int x)
-{
- if (!x)
- return 0;
- return __ffs((unsigned long)x) + 1;
-}
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/ffs.h>
/*
* hweightN: returns the hamming weight (i.e. the number
@@ -193,102 +79,23 @@ static inline unsigned int hweight8(unsi
#else
-#define hweight64(x) generic_hweight64(x)
-#define hweight32(x) generic_hweight32(x)
-#define hweight16(x) generic_hweight16(x)
-#define hweight8(x) generic_hweight8(x)
+#include <asm-generic/bitops/hweight.h>
#endif
#endif /* __KERNEL__ */
-/**
- * find_next_bit - find the next set bit in a memory region
- * @addr: The address to base the search on
- * @offset: The bitnumber to start searching at
- * @size: The maximum size to search
- */
-extern unsigned long find_next_bit(const unsigned long *, unsigned long,
- unsigned long);
-
-/**
- * find_first_bit - find the first set bit in a memory region
- * @addr: The address to start the search at
- * @size: The maximum size to search
- *
- * Returns the bit-number of the first set bit, not the number of the byte
- * containing a bit.
- */
-#define find_first_bit(addr, size) \
- find_next_bit((addr), (size), 0)
-
-/* find_next_zero_bit() finds the first zero bit in a bit string of length
- * 'size' bits, starting the search at bit 'offset'. This is largely based
- * on Linus's ALPHA routines, which are pretty portable BTW.
- */
-
-extern unsigned long find_next_zero_bit(const unsigned long *,
- unsigned long, unsigned long);
-
-#define find_first_zero_bit(addr, size) \
- find_next_zero_bit((addr), (size), 0)
-
-#define test_and_set_le_bit(nr,addr) \
- test_and_set_bit((nr) ^ 0x38, (addr))
-#define test_and_clear_le_bit(nr,addr) \
- test_and_clear_bit((nr) ^ 0x38, (addr))
-
-static inline int test_le_bit(int nr, __const__ unsigned long * addr)
-{
- int mask;
- __const__ unsigned char *ADDR = (__const__ unsigned char *) addr;
-
- ADDR += nr >> 3;
- mask = 1 << (nr & 0x07);
- return ((mask & *ADDR) != 0);
-}
-
-#define find_first_zero_le_bit(addr, size) \
- find_next_zero_le_bit((addr), (size), 0)
-
-extern unsigned long find_next_zero_le_bit(unsigned long *, unsigned long, unsigned long);
+#include <asm-generic/bitops/find.h>
#ifdef __KERNEL__
-#define __set_le_bit(nr, addr) \
- __set_bit((nr) ^ 0x38, (addr))
-#define __clear_le_bit(nr, addr) \
- __clear_bit((nr) ^ 0x38, (addr))
-#define __test_and_clear_le_bit(nr, addr) \
- __test_and_clear_bit((nr) ^ 0x38, (addr))
-#define __test_and_set_le_bit(nr, addr) \
- __test_and_set_bit((nr) ^ 0x38, (addr))
+#include <asm-generic/bitops/ext2-non-atomic.h>
-#define ext2_set_bit(nr,addr) \
- __test_and_set_le_bit((nr),(unsigned long *)(addr))
#define ext2_set_bit_atomic(lock,nr,addr) \
- test_and_set_le_bit((nr),(unsigned long *)(addr))
-#define ext2_clear_bit(nr,addr) \
- __test_and_clear_le_bit((nr),(unsigned long *)(addr))
+ test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
#define ext2_clear_bit_atomic(lock,nr,addr) \
- test_and_clear_le_bit((nr),(unsigned long *)(addr))
-#define ext2_test_bit(nr,addr) \
- test_le_bit((nr),(unsigned long *)(addr))
-#define ext2_find_first_zero_bit(addr, size) \
- find_first_zero_le_bit((unsigned long *)(addr), (size))
-#define ext2_find_next_zero_bit(addr, size, off) \
- find_next_zero_le_bit((unsigned long *)(addr), (size), (off))
-
-/* Bitmap functions for the minix filesystem. */
-#define minix_test_and_set_bit(nr,addr) \
- __test_and_set_bit((nr),(unsigned long *)(addr))
-#define minix_set_bit(nr,addr) \
- __set_bit((nr),(unsigned long *)(addr))
-#define minix_test_and_clear_bit(nr,addr) \
- __test_and_clear_bit((nr),(unsigned long *)(addr))
-#define minix_test_bit(nr,addr) \
- test_bit((nr),(unsigned long *)(addr))
-#define minix_find_first_zero_bit(addr,size) \
- find_first_zero_bit((unsigned long *)(addr),(size))
+ test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
+
+#include <asm-generic/bitops/minix.h>
#endif /* __KERNEL__ */
Index: 2.6-git/arch/sparc64/kernel/sparc64_ksyms.c
=================================--- 2.6-git.orig/arch/sparc64/kernel/sparc64_ksyms.c
+++ 2.6-git/arch/sparc64/kernel/sparc64_ksyms.c
@@ -170,11 +170,6 @@ EXPORT_SYMBOL(set_bit);
EXPORT_SYMBOL(clear_bit);
EXPORT_SYMBOL(change_bit);
-/* Bit searching */
-EXPORT_SYMBOL(find_next_bit);
-EXPORT_SYMBOL(find_next_zero_bit);
-EXPORT_SYMBOL(find_next_zero_le_bit);
-
EXPORT_SYMBOL(ivector_table);
EXPORT_SYMBOL(enable_irq);
EXPORT_SYMBOL(disable_irq);
Index: 2.6-git/arch/sparc64/lib/Makefile
=================================--- 2.6-git.orig/arch/sparc64/lib/Makefile
+++ 2.6-git/arch/sparc64/lib/Makefile
@@ -12,6 +12,6 @@ lib-y := PeeCeeI.o copy_page.o clear_pag
U1memcpy.o U1copy_from_user.o U1copy_to_user.o \
U3memcpy.o U3copy_from_user.o U3copy_to_user.o U3patch.o \
copy_in_user.o user_fixup.o memmove.o \
- mcount.o ipcsum.o rwsem.o xor.o find_bit.o delay.o
+ mcount.o ipcsum.o rwsem.o xor.o delay.o
obj-y += iomap.o
Index: 2.6-git/arch/sparc64/lib/find_bit.c
=================================--- 2.6-git.orig/arch/sparc64/lib/find_bit.c
+++ /dev/null
@@ -1,127 +0,0 @@
-#include <linux/bitops.h>
-
-/**
- * find_next_bit - find the next set bit in a memory region
- * @addr: The address to base the search on
- * @offset: The bitnumber to start searching at
- * @size: The maximum size to search
- */
-unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
- unsigned long offset)
-{
- const unsigned long *p = addr + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if (offset) {
- tmp = *(p++);
- tmp &= (~0UL << offset);
- if (size < 64)
- goto found_first;
- if (tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while (size & ~63UL) {
- if ((tmp = *(p++)))
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if (!size)
- return result;
- tmp = *p;
-
-found_first:
- tmp &= (~0UL >> (64 - size));
- if (tmp = 0UL) /* Are any bits set? */
- return result + size; /* Nope. */
-found_middle:
- return result + __ffs(tmp);
-}
-
-/* find_next_zero_bit() finds the first zero bit in a bit string of length
- * 'size' bits, starting the search at bit 'offset'. This is largely based
- * on Linus's ALPHA routines, which are pretty portable BTW.
- */
-
-unsigned long find_next_zero_bit(const unsigned long *addr,
- unsigned long size, unsigned long offset)
-{
- const unsigned long *p = addr + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if (offset) {
- tmp = *(p++);
- tmp |= ~0UL >> (64-offset);
- if (size < 64)
- goto found_first;
- if (~tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while (size & ~63UL) {
- if (~(tmp = *(p++)))
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if (!size)
- return result;
- tmp = *p;
-
-found_first:
- tmp |= ~0UL << size;
- if (tmp = ~0UL) /* Are any bits zero? */
- return result + size; /* Nope. */
-found_middle:
- return result + ffz(tmp);
-}
-
-unsigned long find_next_zero_le_bit(unsigned long *addr, unsigned long size, unsigned long offset)
-{
- unsigned long *p = addr + (offset >> 6);
- unsigned long result = offset & ~63UL;
- unsigned long tmp;
-
- if (offset >= size)
- return size;
- size -= result;
- offset &= 63UL;
- if(offset) {
- tmp = __swab64p(p++);
- tmp |= (~0UL >> (64-offset));
- if(size < 64)
- goto found_first;
- if(~tmp)
- goto found_middle;
- size -= 64;
- result += 64;
- }
- while(size & ~63) {
- if(~(tmp = __swab64p(p++)))
- goto found_middle;
- result += 64;
- size -= 64;
- }
- if(!size)
- return result;
- tmp = __swab64p(p);
-found_first:
- tmp |= (~0UL << size);
- if (tmp = ~0UL) /* Are any bits zero? */
- return result + size; /* Nope. */
-found_middle:
- return result + ffz(tmp);
-}
--
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-01 9:02 ` [patch 14/44] generic hweight{64,32,16,8}() Akinobu Mita
@ 2006-02-01 9:06 ` Andi Kleen
2006-02-01 9:26 ` Michael Tokarev
2006-02-02 1:26 ` Gabriel Paubert
2006-02-03 8:31 ` Ulrich Eckhardt
2 siblings, 1 reply; 28+ messages in thread
From: Andi Kleen @ 2006-02-01 9:06 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, Russell King,
Ian Molton, dev-etrax, David Howells, Yoshinori Sato,
Linus Torvalds, linux-ia64, Hirokazu Takata, linux-m68k,
Greg Ungerer, linux-mips, parisc-linux, linuxppc-dev, linux390,
linuxsh-dev, linuxsh-shmedia-dev, sparclinux, ultralinux,
Miles Bader, Chris Zankel
On Wednesday 01 February 2006 10:02, Akinobu Mita wrote:
> +static inline unsigned int hweight32(unsigned int w)
> +{
> + unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
> + res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
> + res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
> + res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
> + return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
> +}
How large are these functions on x86? Maybe it would be better to not inline them,
but put it into some C file out of line.
-Andi
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-01 9:06 ` Andi Kleen
@ 2006-02-01 9:26 ` Michael Tokarev
2006-02-01 10:24 ` Andi Kleen
0 siblings, 1 reply; 28+ messages in thread
From: Michael Tokarev @ 2006-02-01 9:26 UTC (permalink / raw)
To: Andi Kleen
Cc: Akinobu Mita, linux-kernel, Richard Henderson, Ivan Kokshaysky,
Russell King, Ian Molton, dev-etrax, David Howells,
Yoshinori Sato, Linus Torvalds, linux-ia64, Hirokazu Takata,
linux-m68k, Greg Ungerer, linux-mips, parisc-linux, linuxppc-dev,
linux390, linuxsh-dev, linuxsh-shmedia-dev, sparclinux,
ultralinux, Miles Bader, Chris Zankel
Andi Kleen wrote:
> On Wednesday 01 February 2006 10:02, Akinobu Mita wrote:
>
>>+static inline unsigned int hweight32(unsigned int w)
[]
> How large are these functions on x86? Maybe it would be better to not inline them,
> but put it into some C file out of line.
hweight8 47 bytes
hweight16 76 bytes
hweight32 97 bytes
hweight64 56 bytes (NOT inlining hweight32)
hweight64 197 bytes (inlining hweight32)
Those are when compiled as separate non-inlined functions,
with pushl %ebp and ret.
/mjt
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-01 9:26 ` Michael Tokarev
@ 2006-02-01 10:24 ` Andi Kleen
2006-02-02 12:50 ` Akinobu Mita
0 siblings, 1 reply; 28+ messages in thread
From: Andi Kleen @ 2006-02-01 10:24 UTC (permalink / raw)
To: Michael Tokarev
Cc: Akinobu Mita, linux-kernel, Richard Henderson, Ivan Kokshaysky,
Russell King, Ian Molton, dev-etrax, David Howells,
Yoshinori Sato, Linus Torvalds, linux-ia64, Hirokazu Takata,
linux-m68k, Greg Ungerer, linux-mips, parisc-linux, linuxppc-dev,
linux390, linuxsh-dev, linuxsh-shmedia-dev, sparclinux,
ultralinux, Miles Bader, Chris Zankel
On Wednesday 01 February 2006 10:26, Michael Tokarev wrote:
> Andi Kleen wrote:
> > On Wednesday 01 February 2006 10:02, Akinobu Mita wrote:
> >
> >>+static inline unsigned int hweight32(unsigned int w)
> []
> > How large are these functions on x86? Maybe it would be better to not inline them,
> > but put it into some C file out of line.
>
> hweight8 47 bytes
> hweight16 76 bytes
> hweight32 97 bytes
> hweight64 56 bytes (NOT inlining hweight32)
> hweight64 197 bytes (inlining hweight32)
>
> Those are when compiled as separate non-inlined functions,
> with pushl %ebp and ret.
This would argue for moving them out of line.
-Andi
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
2006-02-01 9:02 ` [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit() Akinobu Mita
@ 2006-02-01 11:27 ` Roman Zippel
2006-02-06 11:47 ` Akinobu Mita
2006-02-08 10:41 ` Akinobu Mita
0 siblings, 2 replies; 28+ messages in thread
From: Roman Zippel @ 2006-02-01 11:27 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, dev-etrax,
David Howells, Yoshinori Sato, Linus Torvalds, linux-ia64,
Hirokazu Takata, linux-m68k, linux-mips, parisc-linux,
linuxsh-dev, linuxsh-shmedia-dev, sparclinux, ultralinux,
Miles Bader, Andi Kleen, Chris Zankel
Hi,
On Wed, 1 Feb 2006, Akinobu Mita wrote:
> +static __inline__ int generic_test_le_bit(unsigned long nr,
> + __const__ unsigned long *addr)
> +{
> + __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
> + return (tmp[nr >> 3] >> (nr & 7)) & 1;
> +}
The underscores are not needed.
For the inline version I would prefer this version:
{
const unsigned char *tmp = (const unsigned char *)addr;
return (tmp[nr >> 3] & (unsigned char)(1 << (nr & 7))) != 0;
}
Although this would be a good alternative as well:
{
return (addr[nr >> 5] & (1 << ((nr ^ 24) & 31))) != 0;
}
bye, Roman
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-01 9:02 ` [patch 14/44] generic hweight{64,32,16,8}() Akinobu Mita
2006-02-01 9:06 ` Andi Kleen
@ 2006-02-02 1:26 ` Gabriel Paubert
2006-02-06 11:52 ` Akinobu Mita
2006-02-03 8:31 ` Ulrich Eckhardt
2 siblings, 1 reply; 28+ messages in thread
From: Gabriel Paubert @ 2006-02-02 1:26 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, linux-mips, linux-ia64, Ian Molton, David Howells,
linuxppc-dev, Greg Ungerer, sparclinux, Miles Bader,
Linus Torvalds, Yoshinori Sato, Hirokazu Takata,
linuxsh-shmedia-dev, linux-m68k, Ivan Kokshaysky,
Richard Henderson, Chris Zankel, dev-etrax, ultralinux,
Andi Kleen, linuxsh-dev, linux390, Russell King, parisc-linux
On Wed, Feb 01, 2006 at 06:02:38PM +0900, Akinobu Mita wrote:
>
> This patch introduces the C-language equivalents of the functions below:
>
> unsigned int hweight32(unsigned int w);
> unsigned int hweight16(unsigned int w);
> unsigned int hweight8(unsigned int w);
> unsigned long hweight64(__u64 w);
>
> In include/asm-generic/bitops/hweight.h
>
> This code largely copied from:
> include/linux/bitops.h
>
> Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
> include/asm-generic/bitops/hweight.h | 54 +++++++++++++++++++++++++++++++++++
> 1 files changed, 54 insertions(+)
>
> Index: 2.6-git/include/asm-generic/bitops/hweight.h
> =================================> --- /dev/null
> +++ 2.6-git/include/asm-generic/bitops/hweight.h
> @@ -0,0 +1,54 @@
> +#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_
> +#define _ASM_GENERIC_BITOPS_HWEIGHT_H_
> +
> +#include <asm/types.h>
> +
> +/**
> + * hweightN - returns the hamming weight of a N-bit word
> + * @x: the word to weigh
> + *
> + * The Hamming Weight of a number is the total number of bits set in it.
> + */
> +
> +static inline unsigned int hweight32(unsigned int w)
> +{
> + unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
> + res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
> + res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
> + res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
> + return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
> +}
The first step can be implemented slightly better:
unsigned int res = w-((w>>1)&0x55555555);
as I found once on the web[1].
Several of the following steps can also be simplified
by omitting the masking when the result can't possibly
cause a carry to propagate too far.
This might also have a non negligible impact
on code size.
> +
> +static inline unsigned int hweight16(unsigned int w)
> +{
> + unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
> + res = (res & 0x3333) + ((res >> 2) & 0x3333);
> + res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
> + return (res & 0x00FF) + ((res >> 8) & 0x00FF);
> +}
> +
> +static inline unsigned int hweight8(unsigned int w)
> +{
> + unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
> + res = (res & 0x33) + ((res >> 2) & 0x33);
> + return (res & 0x0F) + ((res >> 4) & 0x0F);
> +}
> +
> +static inline unsigned long hweight64(__u64 w)
> +{
> +#if BITS_PER_LONG = 32
> + return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
> +#elif BITS_PER_LONG = 64
> + u64 res;
> + res = (w & 0x5555555555555555ul) + ((w >> 1) & 0x5555555555555555ul);
> + res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
> + res = (res & 0x0F0F0F0F0F0F0F0Ful) + ((res >> 4) & 0x0F0F0F0F0F0F0F0Ful);
> + res = (res & 0x00FF00FF00FF00FFul) + ((res >> 8) & 0x00FF00FF00FF00FFul);
> + res = (res & 0x0000FFFF0000FFFFul) + ((res >> 16) & 0x0000FFFF0000FFFFul);
> + return (res & 0x00000000FFFFFFFFul) + ((res >> 32) & 0x00000000FFFFFFFFul);
> +#else
> +#error BITS_PER_LONG not defined
> +#endif
> +}
> +
> +#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
>
Regards,
Gabriel
[1] It might be better to write the first line
unsigned res = w - ((w&0xaaaaaaaa)>>1);
but I can never remember what the C standard guarantess about
right shifts values (very little IIRC). I believe that it will
work properly on all architectures that GCC supports, however,
and that it will help on many.
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-01 10:24 ` Andi Kleen
@ 2006-02-02 12:50 ` Akinobu Mita
0 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-02 12:50 UTC (permalink / raw)
To: Andi Kleen
Cc: Michael Tokarev, linux-kernel, Richard Henderson, Ivan Kokshaysky,
Russell King, Ian Molton, dev-etrax, David Howells,
Yoshinori Sato, Linus Torvalds, linux-ia64, Hirokazu Takata,
linux-m68k, Greg Ungerer, linux-mips, parisc-linux, linuxppc-dev,
linux390, linuxsh-dev, linuxsh-shmedia-dev, sparclinux,
ultralinux, Miles Bader, Chris Zankel
On Wed, Feb 01, 2006 at 11:24:27AM +0100, Andi Kleen wrote:
> On Wednesday 01 February 2006 10:26, Michael Tokarev wrote:
> > Andi Kleen wrote:
> > > On Wednesday 01 February 2006 10:02, Akinobu Mita wrote:
> > >
> > >>+static inline unsigned int hweight32(unsigned int w)
> > []
> > > How large are these functions on x86? Maybe it would be better to not inline them,
> > > but put it into some C file out of line.
> >
> > hweight8 47 bytes
> > hweight16 76 bytes
> > hweight32 97 bytes
> > hweight64 56 bytes (NOT inlining hweight32)
> > hweight64 197 bytes (inlining hweight32)
> >
> > Those are when compiled as separate non-inlined functions,
> > with pushl %ebp and ret.
>
> This would argue for moving them out of line.
This patch will put hweight*() into lib/hweight.c
Index: 2.6-git/include/asm-generic/bitops/hweight.h
=================================--- 2.6-git.orig/include/asm-generic/bitops/hweight.h
+++ 2.6-git/include/asm-generic/bitops/hweight.h
@@ -1,54 +1,9 @@
#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_
#define _ASM_GENERIC_BITOPS_HWEIGHT_H_
-#include <asm/types.h>
-
-/**
- * hweightN - returns the hamming weight of a N-bit word
- * @x: the word to weigh
- *
- * The Hamming Weight of a number is the total number of bits set in it.
- */
-
-static inline unsigned int hweight32(unsigned int w)
-{
- unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
- res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
- res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
- res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
- return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
-}
-
-static inline unsigned int hweight16(unsigned int w)
-{
- unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
- res = (res & 0x3333) + ((res >> 2) & 0x3333);
- res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
- return (res & 0x00FF) + ((res >> 8) & 0x00FF);
-}
-
-static inline unsigned int hweight8(unsigned int w)
-{
- unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
- res = (res & 0x33) + ((res >> 2) & 0x33);
- return (res & 0x0F) + ((res >> 4) & 0x0F);
-}
-
-static inline unsigned long hweight64(__u64 w)
-{
-#if BITS_PER_LONG = 32
- return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
-#elif BITS_PER_LONG = 64
- u64 res;
- res = (w & 0x5555555555555555ul) + ((w >> 1) & 0x5555555555555555ul);
- res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
- res = (res & 0x0F0F0F0F0F0F0F0Ful) + ((res >> 4) & 0x0F0F0F0F0F0F0F0Ful);
- res = (res & 0x00FF00FF00FF00FFul) + ((res >> 8) & 0x00FF00FF00FF00FFul);
- res = (res & 0x0000FFFF0000FFFFul) + ((res >> 16) & 0x0000FFFF0000FFFFul);
- return (res & 0x00000000FFFFFFFFul) + ((res >> 32) & 0x00000000FFFFFFFFul);
-#else
-#error BITS_PER_LONG not defined
-#endif
-}
+extern unsigned int hweight32(unsigned int w);
+extern unsigned int hweight16(unsigned int w);
+extern unsigned int hweight8(unsigned int w);
+extern unsigned long hweight64(__u64 w);
#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
Index: 2.6-git/lib/Makefile
=================================--- 2.6-git.orig/lib/Makefile
+++ 2.6-git/lib/Makefile
@@ -5,7 +5,7 @@
lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \
bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
- sha1.o
+ sha1.o hweight.o
lib-y += kobject.o kref.o kobject_uevent.o klist.o
Index: 2.6-git/lib/hweight.c
=================================--- /dev/null
+++ 2.6-git/lib/hweight.c
@@ -0,0 +1,54 @@
+#include <linux/module.h>
+#include <asm/types.h>
+
+/**
+ * hweightN - returns the hamming weight of a N-bit word
+ * @x: the word to weigh
+ *
+ * The Hamming Weight of a number is the total number of bits set in it.
+ */
+
+unsigned int hweight32(unsigned int w)
+{
+ unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
+ res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+ res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
+ res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
+ return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
+}
+EXPORT_SYMBOL(hweight32);
+
+unsigned int hweight16(unsigned int w)
+{
+ unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
+ res = (res & 0x3333) + ((res >> 2) & 0x3333);
+ res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
+ return (res & 0x00FF) + ((res >> 8) & 0x00FF);
+}
+EXPORT_SYMBOL(hweight16);
+
+unsigned int hweight8(unsigned int w)
+{
+ unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
+ res = (res & 0x33) + ((res >> 2) & 0x33);
+ return (res & 0x0F) + ((res >> 4) & 0x0F);
+}
+EXPORT_SYMBOL(hweight8);
+
+unsigned long hweight64(__u64 w)
+{
+#if BITS_PER_LONG = 32
+ return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
+#elif BITS_PER_LONG = 64
+ u64 res;
+ res = (w & 0x5555555555555555ul) + ((w >> 1) & 0x5555555555555555ul);
+ res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
+ res = (res & 0x0F0F0F0F0F0F0F0Ful) + ((res >> 4) & 0x0F0F0F0F0F0F0F0Ful);
+ res = (res & 0x00FF00FF00FF00FFul) + ((res >> 8) & 0x00FF00FF00FF00FFul);
+ res = (res & 0x0000FFFF0000FFFFul) + ((res >> 16) & 0x0000FFFF0000FFFFul);
+ return (res & 0x00000000FFFFFFFFul) + ((res >> 32) & 0x00000000FFFFFFFFul);
+#else
+#error BITS_PER_LONG not defined
+#endif
+}
+EXPORT_SYMBOL(hweight64);
^ permalink raw reply [flat|nested] 28+ messages in thread
* RE: [patch 10/44] generic fls64()
2006-02-01 9:02 ` [patch 10/44] generic fls64() Akinobu Mita
@ 2006-02-02 15:05 ` Rune Torgersen
2006-02-03 1:27 ` [PATCH] fix generic_fls64() Akinobu Mita
0 siblings, 1 reply; 28+ messages in thread
From: Rune Torgersen @ 2006-02-02 15:05 UTC (permalink / raw)
To: Akinobu Mita, linux-kernel
Cc: linux-mips, linux-ia64, Ian Molton, David Howells, linuxppc-dev,
Greg Ungerer, sparclinux, Miles Bader, Linus Torvalds,
Yoshinori Sato, Hirokazu Takata, linuxsh-shmedia-dev, linux-m68k,
Ivan Kokshaysky, Richard Henderson, Chris Zankel, dev-etrax,
ultralinux, Andi Kleen, linuxsh-dev, linux390, Russell King,
parisc-linux
> From: Akinobu Mita
> Sent: Wednesday, February 01, 2006 03:03
> +static inline int fls64(__u64 x)
> +{
> + __u32 h = x >> 32;
> + if (h)
> + return fls(x) + 32;
Shouldn't this be return fls(h) + 32; ??
^^^
> + return fls(x);
> +}
> +
> +#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */
>
> --
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>
>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH] fix generic_fls64()
2006-02-02 15:05 ` Rune Torgersen
@ 2006-02-03 1:27 ` Akinobu Mita
0 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-03 1:27 UTC (permalink / raw)
To: Rune Torgersen
Cc: linux-kernel, linux-mips, linux-ia64, Ian Molton, David Howells,
linuxppc-dev, Greg Ungerer, sparclinux, Miles Bader,
Linus Torvalds, Yoshinori Sato, Hirokazu Takata,
linuxsh-shmedia-dev, linux-m68k, Ivan Kokshaysky,
Richard Henderson, Chris Zankel, dev-etrax, ultralinux,
Andi Kleen, linuxsh-dev, linux390, Russell King, parisc-linux,
akpm, Stephen Hemminger
Noticed by Rune Torgersen.
fix generic_fls64().
tcp_cubic is using fls64().
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/linux/bitops.h | 2 +-
1 files changed, 1 insertion(+), 1 deletion(-)
Index: 2.6-git/include/linux/bitops.h
=================================--- 2.6-git.orig/include/linux/bitops.h
+++ 2.6-git/include/linux/bitops.h
@@ -81,7 +81,7 @@ static inline int generic_fls64(__u64 x)
{
__u32 h = x >> 32;
if (h)
- return fls(x) + 32;
+ return fls(h) + 32;
return fls(x);
}
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [parisc-linux] [patch 12/44] generic sched_find_first_bit()
2006-02-01 9:02 ` [patch 12/44] generic sched_find_first_bit() Akinobu Mita
@ 2006-02-03 3:58 ` Grant Grundler
0 siblings, 0 replies; 28+ messages in thread
From: Grant Grundler @ 2006-02-03 3:58 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, linux-mips, linux-ia64, Ian Molton, David Howells,
linuxppc-dev, Greg Ungerer, sparclinux, Miles Bader,
Linus Torvalds, Yoshinori Sato, Hirokazu Takata, linuxsh-dev,
linux-m68k, Chris Zankel, dev-etrax, ultralinux, Andi Kleen,
linuxsh-shmedia-dev, linux390, Russell King, parisc-linux
On Wed, Feb 01, 2006 at 06:02:36PM +0900, Akinobu Mita wrote:
> This patch introduces the C-language equivalent of the function:
> int sched_find_first_bit(const unsigned long *b);
Akinobu, would you prefer this is a slightly cleaner way?
(Not compile tested)
static inline int sched_find_first_bit(const unsigned long *b)
{
if (unlikely(b[0]))
return __ffs(b[0]);
if (unlikely(b[1]))
return __ffs(b[1]) + BITS_PER_LONG;
#if BITS_PER_LONG = 32
if (unlikely(b[2]))
return __ffs(b[2]) + 64;
if (b[3])
return __ffs(b[3]) + 96;
#endif
return __ffs(b[128/BITS_PER_LONG]) + 128;
}
If BITS_PER_LONG isn't defined, the link step will fail and point
at a some unknown .o as the offender. But it's the responsibility
of the header file to make sure it's including the BITS_PER_LONG
definition, not the code that calls sched_find_first_bit().
hth,
grant
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-01 9:02 ` [patch 14/44] generic hweight{64,32,16,8}() Akinobu Mita
2006-02-01 9:06 ` Andi Kleen
2006-02-02 1:26 ` Gabriel Paubert
@ 2006-02-03 8:31 ` Ulrich Eckhardt
2 siblings, 0 replies; 28+ messages in thread
From: Ulrich Eckhardt @ 2006-02-03 8:31 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, Russell King,
Ian Molton, dev-etrax, David Howells, Yoshinori Sato,
Linus Torvalds, linux-ia64, Hirokazu Takata, linux-m68k,
Greg Ungerer, linux-mips, parisc-linux, linuxppc-dev, linux390,
linuxsh-dev, linuxsh-shmedia-dev, sparclinux, ultralinux,
Miles Bader, Andi Kleen, Chris Zankel
On Wednesday 01 February 2006 10:02, Akinobu Mita wrote:
> unsigned int hweight32(unsigned int w);
> unsigned int hweight16(unsigned int w);
> unsigned int hweight8(unsigned int w);
> unsigned long hweight64(__u64 w);
IMHO, this should use explicitly sized integers like __u8, __u16 etc, unless
there are stringent reasons like better register use - which is hard to tell
for generic C code. Also, why on earth is the returntype for hweight64 a
long?
> +static inline unsigned int hweight32(unsigned int w)
> +{
> + unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
> + res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
[...]
Why not use unsigned constants here?
> +static inline unsigned long hweight64(__u64 w)
> +{
[..]
> + u64 res;
> + res = (w & 0x5555555555555555ul) + ((w >> 1) & 0x5555555555555555ul);
Why not use initialisation here, too?
just my 2c
Uli
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 11/44] generic find_{next,first}{,_zero}_bit()
2006-02-01 9:02 ` [patch 11/44] generic find_{next,first}{,_zero}_bit() Akinobu Mita
@ 2006-02-06 10:26 ` David Howells
2006-02-07 2:02 ` Akinobu Mita
0 siblings, 1 reply; 28+ messages in thread
From: David Howells @ 2006-02-06 10:26 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, dev-etrax,
David Howells, Yoshinori Sato, linux-ia64, Hirokazu Takata,
Greg Ungerer, linux-mips, parisc-linux, linuxsh-dev,
linuxsh-shmedia-dev, sparclinux, ultralinux, Miles Bader,
Chris Zankel
Akinobu Mita <mita@miraclelinux.com> wrote:
> This patch introduces the C-language equivalents of the functions below:
>
> unsigned logn find_next_bit(const unsigned long *addr, unsigned long size,
> unsigned long offset);
> unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
> unsigned long offset);
> unsigned long find_first_zero_bit(const unsigned long *addr,
> unsigned long size);
> unsigned long find_first_bit(const unsigned long *addr, unsigned long size);
These big functions should perhaps be out of line.
David
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
2006-02-01 11:27 ` Roman Zippel
@ 2006-02-06 11:47 ` Akinobu Mita
2006-02-08 10:41 ` Akinobu Mita
1 sibling, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-06 11:47 UTC (permalink / raw)
To: Roman Zippel
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, dev-etrax,
David Howells, Yoshinori Sato, Linus Torvalds, linux-ia64,
Hirokazu Takata, linux-m68k, linux-mips, parisc-linux,
linuxsh-dev, linuxsh-shmedia-dev, sparclinux, ultralinux,
Miles Bader, Andi Kleen, Chris Zankel
On Wed, Feb 01, 2006 at 12:27:38PM +0100, Roman Zippel wrote:
> > +static __inline__ int generic_test_le_bit(unsigned long nr,
> > + __const__ unsigned long *addr)
> > +{
> > + __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
> > + return (tmp[nr >> 3] >> (nr & 7)) & 1;
> > +}
>
> The underscores are not needed.
>
Thanks, I converted to 'inline' and 'const'.
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 14/44] generic hweight{64,32,16,8}()
2006-02-02 1:26 ` Gabriel Paubert
@ 2006-02-06 11:52 ` Akinobu Mita
0 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-06 11:52 UTC (permalink / raw)
To: Gabriel Paubert
Cc: linux-kernel, linux-mips, linux-ia64, Ian Molton, David Howells,
linuxppc-dev, Greg Ungerer, sparclinux, Miles Bader,
Linus Torvalds, Yoshinori Sato, Hirokazu Takata,
linuxsh-shmedia-dev, linux-m68k, Ivan Kokshaysky,
Richard Henderson, Chris Zankel, dev-etrax, ultralinux,
Andi Kleen, linuxsh-dev, linux390, Russell King, parisc-linux,
Balbir Singh, linux
On Thu, Feb 02, 2006 at 02:26:38AM +0100, Gabriel Paubert wrote:
>
> The first step can be implemented slightly better:
>
> unsigned int res = w-((w>>1)&0x55555555);
>
Yes. I've got many advices about hweight speedup.
static unsigned int hweight32(unsigned int w)
{
unsigned int res = w - ((w >> 1) & 0x55555555);
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
res = (res + (res >> 4)) & 0x0F0F0F0F;
res = res + (res >> 8);
return (res + (res >> 16)) & 0x000000FF;
}
static unsigned int hweight16(unsigned int w)
{
unsigned int res = w - ((w >> 1) & 0x5555);
res = (res & 0x3333) + ((res >> 2) & 0x3333);
res = (res + (res >> 4)) & 0x0F0F;
return (res + (res >> 8)) & 0x00FF;
}
static unsigned int hweight8(unsigned int w)
{
unsigned int res = w - ((w >> 1) & 0x55);
res = (res & 0x33) + ((res >> 2) & 0x33);
return (res + (res >> 4)) & 0x0F;
}
static unsigned long hweight64(__u64 w)
{
#if BITS_PER_LONG < 64
return hweight32((unsigned int)(w >> 32)) +
hweight32((unsigned int)w);
#else
__u64 res = w - ((w >> 1) & 0x5555555555555555ul);
res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
res = res + (res >> 8);
res = res + (res >> 16);
return (res + (res >> 32)) & 0x00000000000000FFul;
#endif
}
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 11/44] generic find_{next,first}{,_zero}_bit()
2006-02-06 10:26 ` David Howells
@ 2006-02-07 2:02 ` Akinobu Mita
0 siblings, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-07 2:02 UTC (permalink / raw)
To: David Howells
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, dev-etrax,
Yoshinori Sato, linux-ia64, Hirokazu Takata, Greg Ungerer,
linux-mips, parisc-linux, linuxsh-dev, linuxsh-shmedia-dev,
sparclinux, ultralinux, Miles Bader, Chris Zankel
On Mon, Feb 06, 2006 at 10:26:00AM +0000, David Howells wrote:
> Akinobu Mita <mita@miraclelinux.com> wrote:
>
> > This patch introduces the C-language equivalents of the functions below:
> >
> > unsigned logn find_next_bit(const unsigned long *addr, unsigned long size,
> > unsigned long offset);
> > unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
> > unsigned long offset);
> > unsigned long find_first_zero_bit(const unsigned long *addr,
> > unsigned long size);
> > unsigned long find_first_bit(const unsigned long *addr, unsigned long size);
>
> These big functions should perhaps be out of line.
Yes. I'll make them and below out of line.
- hweight*()
- ext2_find_*_zero_bit()
- minix_find_first_zero_bit()
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
2006-02-01 11:27 ` Roman Zippel
2006-02-06 11:47 ` Akinobu Mita
@ 2006-02-08 10:41 ` Akinobu Mita
1 sibling, 0 replies; 28+ messages in thread
From: Akinobu Mita @ 2006-02-08 10:41 UTC (permalink / raw)
To: Roman Zippel
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, dev-etrax,
David Howells, Yoshinori Sato, Linus Torvalds, linux-ia64,
Hirokazu Takata, linux-m68k, linux-mips, parisc-linux,
linuxsh-dev, linuxsh-shmedia-dev, sparclinux, ultralinux,
Miles Bader, Andi Kleen, Chris Zankel
On Wed, Feb 01, 2006 at 12:27:38PM +0100, Roman Zippel wrote:
> For the inline version I would prefer this version:
>
> {
> const unsigned char *tmp = (const unsigned char *)addr;
> return (tmp[nr >> 3] & (unsigned char)(1 << (nr & 7))) != 0;
> }
>
> Although this would be a good alternative as well:
>
> {
> return (addr[nr >> 5] & (1 << ((nr ^ 24) & 31))) != 0;
> }
Thanks, maybe I could use BITOP_LE_SWIZZLE similar to other *_le_bit().
#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
:
#define generic_test_le_bit(nr, addr) test_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
:
#endif /* __BIG_ENDIAN */
^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2006-02-08 10:41 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20060201090224.536581000@localhost.localdomain>
2006-02-01 9:02 ` [patch 04/44] use non atomic operations for minix_*_bit() and ext2_*_bit() Akinobu Mita
2006-02-01 9:02 ` [patch 06/44] generic __{,test_and_}{set,clear,change}_bit() and test_bit() Akinobu Mita
2006-02-01 9:02 ` [patch 07/44] generic __ffs() Akinobu Mita
2006-02-01 9:02 ` [patch 08/44] generic ffz() Akinobu Mita
2006-02-01 9:02 ` [patch 09/44] generic fls() Akinobu Mita
2006-02-01 9:02 ` [patch 10/44] generic fls64() Akinobu Mita
2006-02-02 15:05 ` Rune Torgersen
2006-02-03 1:27 ` [PATCH] fix generic_fls64() Akinobu Mita
2006-02-01 9:02 ` [patch 11/44] generic find_{next,first}{,_zero}_bit() Akinobu Mita
2006-02-06 10:26 ` David Howells
2006-02-07 2:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 12/44] generic sched_find_first_bit() Akinobu Mita
2006-02-03 3:58 ` [parisc-linux] " Grant Grundler
2006-02-01 9:02 ` [patch 13/44] generic ffs() Akinobu Mita
2006-02-01 9:02 ` [patch 14/44] generic hweight{64,32,16,8}() Akinobu Mita
2006-02-01 9:06 ` Andi Kleen
2006-02-01 9:26 ` Michael Tokarev
2006-02-01 10:24 ` Andi Kleen
2006-02-02 12:50 ` Akinobu Mita
2006-02-02 1:26 ` Gabriel Paubert
2006-02-06 11:52 ` Akinobu Mita
2006-02-03 8:31 ` Ulrich Eckhardt
2006-02-01 9:02 ` [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit() Akinobu Mita
2006-02-01 11:27 ` Roman Zippel
2006-02-06 11:47 ` Akinobu Mita
2006-02-08 10:41 ` Akinobu Mita
2006-02-01 9:02 ` [patch 17/44] generic minix_{test,set,test_and_clear,test,find_first_zero}_bit() Akinobu Mita
2006-02-01 9:03 ` [patch 36/44] sparc64: use generic bitops Akinobu Mita
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox