* [patch 01/44] ia64: use cpu_set() instead of __set_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
@ 2006-02-01 9:02 ` Akinobu Mita
2006-02-01 9:02 ` [patch 04/44] use non atomic operations for minix_*_bit() and ext2_*_bit() Akinobu Mita
` (10 subsequent siblings)
11 siblings, 0 replies; 29+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-ia64, Akinobu Mita
__set_bit() --> cpu_set() cleanup
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
arch/ia64/kernel/mca.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletion(-)
Index: 2.6-git/arch/ia64/kernel/mca.c
=================================--- 2.6-git.orig/arch/ia64/kernel/mca.c
+++ 2.6-git/arch/ia64/kernel/mca.c
@@ -69,6 +69,7 @@
#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/workqueue.h>
+#include <linux/cpumask.h>
#include <asm/delay.h>
#include <asm/kdebug.h>
@@ -1430,7 +1431,7 @@ format_mca_init_stack(void *mca_data, un
ti->cpu = cpu;
p->thread_info = ti;
p->state = TASK_UNINTERRUPTIBLE;
- __set_bit(cpu, &p->cpus_allowed);
+ cpu_set(cpu, p->cpus_allowed);
INIT_LIST_HEAD(&p->tasks);
p->parent = p->real_parent = p->group_leader = p;
INIT_LIST_HEAD(&p->children);
--
^ permalink raw reply [flat|nested] 29+ messages in thread* [patch 04/44] use non atomic operations for minix_*_bit() and ext2_*_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
2006-02-01 9:02 ` [patch 01/44] ia64: use cpu_set() instead of __set_bit() Akinobu Mita
@ 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
` (9 subsequent siblings)
11 siblings, 0 replies; 29+ 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] 29+ 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 01/44] ia64: use cpu_set() instead of __set_bit() Akinobu Mita
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 10/44] generic fls64() Akinobu Mita
` (8 subsequent siblings)
11 siblings, 0 replies; 29+ 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] 29+ messages in thread* [patch 10/44] generic fls64()
[not found] <20060201090224.536581000@localhost.localdomain>
` (2 preceding siblings ...)
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-02 15:05 ` Rune Torgersen
2006-02-01 9:02 ` [patch 11/44] generic find_{next,first}{,_zero}_bit() Akinobu Mita
` (7 subsequent siblings)
11 siblings, 1 reply; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ messages in thread
* [patch 11/44] generic find_{next,first}{,_zero}_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (3 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
` (6 subsequent siblings)
11 siblings, 1 reply; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ messages in thread
* [patch 12/44] generic sched_find_first_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (4 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 14/44] generic hweight{64,32,16,8}() Akinobu Mita
` (5 subsequent siblings)
11 siblings, 1 reply; 29+ 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] 29+ 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; 29+ 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] 29+ messages in thread
* [patch 14/44] generic hweight{64,32,16,8}()
[not found] <20060201090224.536581000@localhost.localdomain>
` (5 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: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
` (4 subsequent siblings)
11 siblings, 3 replies; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ messages in thread
* [patch 15/44] generic ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (6 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
` (3 subsequent siblings)
11 siblings, 1 reply; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ 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; 29+ 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] 29+ messages in thread
* [patch 17/44] generic minix_{test,set,test_and_clear,test,find_first_zero}_bit()
[not found] <20060201090224.536581000@localhost.localdomain>
` (7 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:02 ` [patch 25/44] ia64: use generic bitops Akinobu Mita
` (2 subsequent siblings)
11 siblings, 0 replies; 29+ 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] 29+ messages in thread* [patch 25/44] ia64: use generic bitops
[not found] <20060201090224.536581000@localhost.localdomain>
` (8 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:02 ` Akinobu Mita
2006-02-01 9:03 ` [patch 41/44] make thread_info.flags an unsigned long Akinobu Mita
2006-02-01 9:03 ` [patch 42/44] ia64: make partial_page.bitmap " Akinobu Mita
11 siblings, 0 replies; 29+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:02 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-ia64, Akinobu Mita
- remove __{,test_and_}{set,clear,change}_bit() and test_bit()
- remove generic_fls64()
- 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()
- remove sched_find_first_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
arch/ia64/lib/Makefile | 2
arch/ia64/lib/bitop.c | 88 ------------------------
include/asm-ia64/bitops.h | 168 ++++------------------------------------------
3 files changed, 19 insertions(+), 239 deletions(-)
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
@@ -5,8 +5,8 @@
* Copyright (C) 1998-2003 Hewlett-Packard Co
* David Mosberger-Tang <davidm@hpl.hp.com>
*
- * 02/06/02 find_next_bit() and find_first_bit() added from Erich Focht's ia64 O(1)
- * scheduler patch
+ * 02/06/02 find_next_bit() and find_first_bit() added from Erich Focht's ia64
+ * O(1) scheduler patch
*/
#include <linux/compiler.h>
@@ -25,9 +25,9 @@
* restricted to acting on a single-word quantity.
*
* The address must be (at least) "long" aligned.
- * Note that there are driver (e.g., eepro100) which use these operations to operate on
- * hw-defined data-structures, so we can't easily change these operations to force a
- * bigger alignment.
+ * Note that there are driver (e.g., eepro100) which use these operations to
+ * operate on hw-defined data-structures, so we can't easily change these
+ * operations to force a bigger alignment.
*
* bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
*/
@@ -47,21 +47,6 @@ set_bit (int nr, volatile void *addr)
} while (cmpxchg_acq(m, old, new) != old);
}
-/**
- * __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 void *addr)
-{
- *((__u32 *) addr + (nr >> 5)) |= (1 << (nr & 31));
-}
-
/*
* clear_bit() has "acquire" semantics.
*/
@@ -95,17 +80,6 @@ clear_bit (int nr, volatile void *addr)
}
/**
- * __clear_bit - Clears a bit in memory (non-atomic version)
- */
-static __inline__ void
-__clear_bit (int nr, volatile void *addr)
-{
- volatile __u32 *p = (__u32 *) addr + (nr >> 5);
- __u32 m = 1 << (nr & 31);
- *p &= ~m;
-}
-
-/**
* change_bit - Toggle a bit in memory
* @nr: Bit to clear
* @addr: Address to start counting from
@@ -131,21 +105,6 @@ change_bit (int nr, volatile void *addr)
}
/**
- * __change_bit - Toggle a bit in memory
- * @nr: the bit to set
- * @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 void *addr)
-{
- *((__u32 *) addr + (nr >> 5)) ^= (1 << (nr & 31));
-}
-
-/**
* test_and_set_bit - Set a bit and return its old value
* @nr: Bit to set
* @addr: Address to count from
@@ -171,26 +130,6 @@ test_and_set_bit (int nr, volatile void
}
/**
- * __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 void *addr)
-{
- __u32 *p = (__u32 *) addr + (nr >> 5);
- __u32 m = 1 << (nr & 31);
- int oldbitset = (*p & m) != 0;
-
- *p |= m;
- return oldbitset;
-}
-
-/**
* test_and_clear_bit - Clear a bit and return its old value
* @nr: Bit to set
* @addr: Address to count from
@@ -216,26 +155,6 @@ test_and_clear_bit (int nr, volatile voi
}
/**
- * __test_and_clear_bit - Clear 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_clear_bit(int nr, volatile void * addr)
-{
- __u32 *p = (__u32 *) addr + (nr >> 5);
- __u32 m = 1 << (nr & 31);
- int oldbitset = *p & m;
-
- *p &= ~m;
- return oldbitset;
-}
-
-/**
* test_and_change_bit - Change a bit and return its old value
* @nr: Bit to set
* @addr: Address to count from
@@ -260,32 +179,14 @@ test_and_change_bit (int nr, volatile vo
return (old & bit) != 0;
}
-/*
- * WARNING: non atomic version.
- */
-static __inline__ int
-__test_and_change_bit (int nr, void *addr)
-{
- __u32 old, bit = (1 << (nr & 31));
- __u32 *m = (__u32 *) addr + (nr >> 5);
-
- old = *m;
- *m = old ^ bit;
- return (old & bit) != 0;
-}
-
-static __inline__ int
-test_bit (int nr, const volatile void *addr)
-{
- return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31));
-}
+#include <asm-generic/bitops/non-atomic.h>
/**
* ffz - find the first zero bit in a long word
* @x: The long word to find the bit in
*
- * Returns the bit-number (0..63) of the first (least significant) zero bit. Undefined if
- * no zero exists, so code should check against ~0UL first...
+ * Returns the bit-number (0..63) of the first (least significant) zero bit.
+ * Undefined if no zero exists, so code should check against ~0UL first...
*/
static inline unsigned long
ffz (unsigned long x)
@@ -345,13 +246,14 @@ fls (int t)
x |= x >> 16;
return ia64_popcnt(x);
}
-#define fls64(x) generic_fls64(x)
+
+#include <asm-generic/bitops/fls64.h>
/*
- * 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): it operates on
- * "int" values only and the result value is the bit number + 1. ffs(0) is defined to
- * return zero.
+ * 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): it operates on "int" values only and the result value is the
+ * bit number + 1. ffs(0) is defined to return zero.
*/
#define ffs(x) __builtin_ffs(x)
@@ -373,51 +275,17 @@ hweight64 (unsigned long x)
#endif /* __KERNEL__ */
-extern int __find_next_zero_bit (const void *addr, unsigned long size,
- unsigned long offset);
-extern int __find_next_bit(const void *addr, unsigned long size,
- unsigned long offset);
-
-#define find_next_zero_bit(addr, size, offset) \
- __find_next_zero_bit((addr), (size), (offset))
-#define find_next_bit(addr, size, offset) \
- __find_next_bit((addr), (size), (offset))
-
-/*
- * The optimizer actually does good code for this case..
- */
-#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)
+#include <asm-generic/bitops/find.h>
#ifdef __KERNEL__
-#define __clear_bit(nr, addr) clear_bit(nr, addr)
+#include <asm-generic/bitops/ext2-non-atomic.h>
-#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_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_bit(nr,addr) test_bit(nr,addr)
-#define minix_find_first_zero_bit(addr,size) find_first_zero_bit(addr,size)
-static inline int
-sched_find_first_bit (unsigned long *b)
-{
- if (unlikely(b[0]))
- return __ffs(b[0]);
- if (unlikely(b[1]))
- return 64 + __ffs(b[1]);
- return __ffs(b[2]) + 128;
-}
+#include <asm-generic/bitops/minix.h>
+#include <asm-generic/bitops/sched.h>
#endif /* __KERNEL__ */
Index: 2.6-git/arch/ia64/lib/Makefile
=================================--- 2.6-git.orig/arch/ia64/lib/Makefile
+++ 2.6-git/arch/ia64/lib/Makefile
@@ -6,7 +6,7 @@ obj-y := io.o
lib-y := __divsi3.o __udivsi3.o __modsi3.o __umodsi3.o \
__divdi3.o __udivdi3.o __moddi3.o __umoddi3.o \
- bitop.o checksum.o clear_page.o csum_partial_copy.o \
+ checksum.o clear_page.o csum_partial_copy.o \
clear_user.o strncpy_from_user.o strlen_user.o strnlen_user.o \
flush.o ip_fast_csum.o do_csum.o \
memset.o strlen.o
Index: 2.6-git/arch/ia64/lib/bitop.c
=================================--- 2.6-git.orig/arch/ia64/lib/bitop.c
+++ /dev/null
@@ -1,88 +0,0 @@
-#include <linux/compiler.h>
-#include <linux/types.h>
-#include <asm/intrinsics.h>
-#include <linux/module.h>
-#include <linux/bitops.h>
-
-/*
- * Find next zero bit in a bitmap reasonably efficiently..
- */
-
-int __find_next_zero_bit (const void *addr, unsigned long size, unsigned long offset)
-{
- unsigned long *p = ((unsigned long *) 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) /* any bits zero? */
- return result + size; /* nope */
-found_middle:
- return result + ffz(tmp);
-}
-EXPORT_SYMBOL(__find_next_zero_bit);
-
-/*
- * Find next bit in a bitmap reasonably efficiently..
- */
-int __find_next_bit(const void *addr, unsigned long size, unsigned long offset)
-{
- unsigned long *p = ((unsigned long *) 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);
-}
-EXPORT_SYMBOL(__find_next_bit);
--
^ permalink raw reply [flat|nested] 29+ messages in thread* [patch 41/44] make thread_info.flags an unsigned long
[not found] <20060201090224.536581000@localhost.localdomain>
` (9 preceding siblings ...)
2006-02-01 9:02 ` [patch 25/44] ia64: use generic bitops Akinobu Mita
@ 2006-02-01 9:03 ` Akinobu Mita
2006-02-01 18:17 ` Luck, Tony
2006-02-01 9:03 ` [patch 42/44] ia64: make partial_page.bitmap " Akinobu Mita
11 siblings, 1 reply; 29+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:03 UTC (permalink / raw)
To: linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, linux-ia64, linuxsh-dev,
Andi Kleen, Akinobu Mita
The *_bit() routines are defined to work on a pointer to unsigned long.
And the thread_info.flags is passed to *_bit() routines in
include/linux/thread_info.h. But
- alpha: flags is unsigned int
- ia64, sh, x86_64: flags is __u32
So flags should be changed to unsigned long instead.
The only affected 64-platforms are little endian, so it will work
without this change. But it's better to change it before people copy the
code to a big endian platform.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
include/asm-alpha/thread_info.h | 2 +-
include/asm-ia64/thread_info.h | 2 +-
include/asm-sh/thread_info.h | 2 +-
include/asm-x86_64/thread_info.h | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
Index: 2.6-git/include/asm-alpha/thread_info.h
=================================--- 2.6-git.orig/include/asm-alpha/thread_info.h
+++ 2.6-git/include/asm-alpha/thread_info.h
@@ -14,7 +14,7 @@ struct thread_info {
struct pcb_struct pcb; /* palcode state */
struct task_struct *task; /* main task structure */
- unsigned int flags; /* low level flags */
+ unsigned long flags; /* low level flags */
unsigned int ieee_state; /* see fpu.h */
struct exec_domain *exec_domain; /* execution domain */
Index: 2.6-git/include/asm-ia64/thread_info.h
=================================--- 2.6-git.orig/include/asm-ia64/thread_info.h
+++ 2.6-git/include/asm-ia64/thread_info.h
@@ -24,7 +24,7 @@
struct thread_info {
struct task_struct *task; /* XXX not really needed, except for dup_task_struct() */
struct exec_domain *exec_domain;/* execution domain */
- __u32 flags; /* thread_info flags (see TIF_*) */
+ unsigned long flags; /* thread_info flags (see TIF_*) */
__u32 cpu; /* current CPU */
mm_segment_t addr_limit; /* user-level address space limit */
int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */
Index: 2.6-git/include/asm-sh/thread_info.h
=================================--- 2.6-git.orig/include/asm-sh/thread_info.h
+++ 2.6-git/include/asm-sh/thread_info.h
@@ -18,7 +18,7 @@
struct thread_info {
struct task_struct *task; /* main task structure */
struct exec_domain *exec_domain; /* execution domain */
- __u32 flags; /* low level flags */
+ unsigned long flags; /* low level flags */
__u32 cpu;
int preempt_count; /* 0 => preemptable, <0 => BUG */
struct restart_block restart_block;
Index: 2.6-git/include/asm-x86_64/thread_info.h
=================================--- 2.6-git.orig/include/asm-x86_64/thread_info.h
+++ 2.6-git/include/asm-x86_64/thread_info.h
@@ -26,7 +26,7 @@ struct exec_domain;
struct thread_info {
struct task_struct *task; /* main task structure */
struct exec_domain *exec_domain; /* execution domain */
- __u32 flags; /* low level flags */
+ unsigned long flags; /* low level flags */
__u32 status; /* thread synchronous flags */
__u32 cpu; /* current CPU */
int preempt_count; /* 0 => preemptable, <0 => BUG */
--
^ permalink raw reply [flat|nested] 29+ messages in thread* RE: [patch 41/44] make thread_info.flags an unsigned long
2006-02-01 9:03 ` [patch 41/44] make thread_info.flags an unsigned long Akinobu Mita
@ 2006-02-01 18:17 ` Luck, Tony
2006-02-02 1:37 ` Akinobu Mita
0 siblings, 1 reply; 29+ messages in thread
From: Luck, Tony @ 2006-02-01 18:17 UTC (permalink / raw)
To: Akinobu Mita, linux-kernel
Cc: Richard Henderson, Ivan Kokshaysky, linux-ia64, linuxsh-dev,
Andi Kleen
--- 2.6-git.orig/include/asm-ia64/thread_info.h
+++ 2.6-git/include/asm-ia64/thread_info.h
@@ -24,7 +24,7 @@
struct thread_info {
struct task_struct *task; /* XXX not really needed, except for dup_task_struct() */
struct exec_domain *exec_domain;/* execution domain */
- __u32 flags; /* thread_info flags (see TIF_*) */
+ unsigned long flags; /* thread_info flags (see TIF_*) */
__u32 cpu; /* current CPU */
mm_segment_t addr_limit; /* user-level address space limit */
int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */
This leaves a useless hole in the structure. Tell me again why
this is a good thing?
-Tony
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch 41/44] make thread_info.flags an unsigned long
2006-02-01 18:17 ` Luck, Tony
@ 2006-02-02 1:37 ` Akinobu Mita
0 siblings, 0 replies; 29+ messages in thread
From: Akinobu Mita @ 2006-02-02 1:37 UTC (permalink / raw)
To: Luck, Tony
Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, linux-ia64,
linuxsh-dev, Andi Kleen
On Wed, Feb 01, 2006 at 10:17:43AM -0800, Luck, Tony wrote:
>
> --- 2.6-git.orig/include/asm-ia64/thread_info.h
> +++ 2.6-git/include/asm-ia64/thread_info.h
> @@ -24,7 +24,7 @@
> struct thread_info {
> struct task_struct *task; /* XXX not really needed, except for dup_task_struct() */
> struct exec_domain *exec_domain;/* execution domain */
> - __u32 flags; /* thread_info flags (see TIF_*) */
> + unsigned long flags; /* thread_info flags (see TIF_*) */
> __u32 cpu; /* current CPU */
> mm_segment_t addr_limit; /* user-level address space limit */
> int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */
>
> This leaves a useless hole in the structure. Tell me again why
> this is a good thing?
This patch stops warning message introduced by the "[patch 25/44]
ia64: use generic bitops" which replaces __set_bit() family to
generic one.
But I realize that I can't replace to generic one for ia64.
Because __set_bit() family are using the pointer to __u32, but
generic __set_bit() family are using the pointer to unsigned long.
So the patch 25/44 is wrong and the change above is unnessesary.
Thanks
^ permalink raw reply [flat|nested] 29+ messages in thread
* [patch 42/44] ia64: make partial_page.bitmap an unsigned long
[not found] <20060201090224.536581000@localhost.localdomain>
` (10 preceding siblings ...)
2006-02-01 9:03 ` [patch 41/44] make thread_info.flags an unsigned long Akinobu Mita
@ 2006-02-01 9:03 ` Akinobu Mita
11 siblings, 0 replies; 29+ messages in thread
From: Akinobu Mita @ 2006-02-01 9:03 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-ia64, Akinobu Mita
The *_bit() routines are defined to work on a pointer to unsigned long.
But partial_page.bitmap is unsigned int and it is passed to find_*_bit()
in arch/ia64/ia32/sys_ia32.c. So the compiler will print warnings.
This patch changes to unsigned long instead.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
arch/ia64/ia32/ia32priv.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
Index: 2.6-git/arch/ia64/ia32/ia32priv.h
=================================--- 2.6-git.orig/arch/ia64/ia32/ia32priv.h
+++ 2.6-git/arch/ia64/ia32/ia32priv.h
@@ -29,9 +29,9 @@
struct partial_page {
struct partial_page *next; /* linked list, sorted by address */
struct rb_node pp_rb;
- /* 64K is the largest "normal" page supported by ia64 ABI. So 4K*32
+ /* 64K is the largest "normal" page supported by ia64 ABI. So 4K*64
* should suffice.*/
- unsigned int bitmap;
+ unsigned long bitmap;
unsigned int base;
};
--
^ permalink raw reply [flat|nested] 29+ messages in thread