Commit ed6b796c authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] i386 uninline some bitops

Uninline the non-leaf bit search functions.  Saves 9 kbytes from my vmlinux.

And gratuitously s/__inline__/inline/
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 91c87360
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
# #
lib-y = checksum.o delay.o \ lib-y = checksum.o delay.o usercopy.o getuser.o memcpy.o strstr.o \
usercopy.o getuser.o \ bitops.o
memcpy.o strstr.o
lib-$(CONFIG_X86_USE_3DNOW) += mmx.o lib-$(CONFIG_X86_USE_3DNOW) += mmx.o
lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o
#include <linux/bitops.h>
#include <linux/module.h>
/**
* find_next_bit - find the first 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
*/
int find_next_bit(const unsigned long *addr, int size, int offset)
{
const unsigned long *p = addr + (offset >> 5);
int set = 0, bit = offset & 31, res;
if (bit) {
/*
* Look for nonzero in the first 32 bits:
*/
__asm__("bsfl %1,%0\n\t"
"jne 1f\n\t"
"movl $32, %0\n"
"1:"
: "=r" (set)
: "r" (*p >> bit));
if (set < (32 - bit))
return set + offset;
set = 32 - bit;
p++;
}
/*
* No set bit yet, search remaining full words for a bit
*/
res = find_first_bit (p, size - 32 * (p - addr));
return (offset + set + res);
}
EXPORT_SYMBOL(find_next_bit);
/**
* find_next_zero_bit - find the first zero 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
*/
int find_next_zero_bit(const unsigned long *addr, int size, int offset)
{
unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
int set = 0, bit = offset & 31, res;
if (bit) {
/*
* Look for zero in the first 32 bits.
*/
__asm__("bsfl %1,%0\n\t"
"jne 1f\n\t"
"movl $32, %0\n"
"1:"
: "=r" (set)
: "r" (~(*p >> bit)));
if (set < (32 - bit))
return set + offset;
set = 32 - bit;
p++;
}
/*
* No zero yet, search remaining full bytes for a zero
*/
res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr));
return (offset + set + res);
}
EXPORT_SYMBOL(find_next_zero_bit);
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* Note that @nr may be almost arbitrarily large; this function is not * Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity. * restricted to acting on a single-word quantity.
*/ */
static __inline__ void set_bit(int nr, volatile unsigned long * addr) static inline void set_bit(int nr, volatile unsigned long * addr)
{ {
__asm__ __volatile__( LOCK_PREFIX __asm__ __volatile__( LOCK_PREFIX
"btsl %1,%0" "btsl %1,%0"
...@@ -51,7 +51,7 @@ static __inline__ void set_bit(int nr, volatile unsigned long * addr) ...@@ -51,7 +51,7 @@ static __inline__ void set_bit(int nr, volatile unsigned long * addr)
* If it's called on the same region of memory simultaneously, the effect * If it's called on the same region of memory simultaneously, the effect
* may be that only one operation succeeds. * may be that only one operation succeeds.
*/ */
static __inline__ void __set_bit(int nr, volatile unsigned long * addr) static inline void __set_bit(int nr, volatile unsigned long * addr)
{ {
__asm__( __asm__(
"btsl %1,%0" "btsl %1,%0"
...@@ -69,7 +69,7 @@ static __inline__ void __set_bit(int nr, volatile unsigned long * addr) ...@@ -69,7 +69,7 @@ static __inline__ void __set_bit(int nr, volatile unsigned long * addr)
* you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
* in order to ensure changes are visible on other processors. * in order to ensure changes are visible on other processors.
*/ */
static __inline__ void clear_bit(int nr, volatile unsigned long * addr) static inline void clear_bit(int nr, volatile unsigned long * addr)
{ {
__asm__ __volatile__( LOCK_PREFIX __asm__ __volatile__( LOCK_PREFIX
"btrl %1,%0" "btrl %1,%0"
...@@ -77,7 +77,7 @@ static __inline__ void clear_bit(int nr, volatile unsigned long * addr) ...@@ -77,7 +77,7 @@ static __inline__ void clear_bit(int nr, volatile unsigned long * addr)
:"Ir" (nr)); :"Ir" (nr));
} }
static __inline__ void __clear_bit(int nr, volatile unsigned long * addr) static inline void __clear_bit(int nr, volatile unsigned long * addr)
{ {
__asm__ __volatile__( __asm__ __volatile__(
"btrl %1,%0" "btrl %1,%0"
...@@ -96,7 +96,7 @@ static __inline__ void __clear_bit(int nr, volatile unsigned long * addr) ...@@ -96,7 +96,7 @@ static __inline__ void __clear_bit(int nr, volatile unsigned long * addr)
* If it's called on the same region of memory simultaneously, the effect * If it's called on the same region of memory simultaneously, the effect
* may be that only one operation succeeds. * may be that only one operation succeeds.
*/ */
static __inline__ void __change_bit(int nr, volatile unsigned long * addr) static inline void __change_bit(int nr, volatile unsigned long * addr)
{ {
__asm__ __volatile__( __asm__ __volatile__(
"btcl %1,%0" "btcl %1,%0"
...@@ -113,7 +113,7 @@ static __inline__ void __change_bit(int nr, volatile unsigned long * addr) ...@@ -113,7 +113,7 @@ static __inline__ void __change_bit(int nr, volatile unsigned long * addr)
* Note that @nr may be almost arbitrarily large; this function is not * Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity. * restricted to acting on a single-word quantity.
*/ */
static __inline__ void change_bit(int nr, volatile unsigned long * addr) static inline void change_bit(int nr, volatile unsigned long * addr)
{ {
__asm__ __volatile__( LOCK_PREFIX __asm__ __volatile__( LOCK_PREFIX
"btcl %1,%0" "btcl %1,%0"
...@@ -129,7 +129,7 @@ static __inline__ void change_bit(int nr, volatile unsigned long * addr) ...@@ -129,7 +129,7 @@ static __inline__ void change_bit(int nr, volatile unsigned long * addr)
* This operation is atomic and cannot be reordered. * This operation is atomic and cannot be reordered.
* It also implies a memory barrier. * It also implies a memory barrier.
*/ */
static __inline__ int test_and_set_bit(int nr, volatile unsigned long * addr) static inline int test_and_set_bit(int nr, volatile unsigned long * addr)
{ {
int oldbit; int oldbit;
...@@ -149,7 +149,7 @@ static __inline__ int test_and_set_bit(int nr, volatile unsigned long * addr) ...@@ -149,7 +149,7 @@ static __inline__ int test_and_set_bit(int nr, volatile unsigned long * addr)
* If two examples of this operation race, one can appear to succeed * If two examples of this operation race, one can appear to succeed
* but actually fail. You must protect multiple accesses with a lock. * but actually fail. You must protect multiple accesses with a lock.
*/ */
static __inline__ int __test_and_set_bit(int nr, volatile unsigned long * addr) static inline int __test_and_set_bit(int nr, volatile unsigned long * addr)
{ {
int oldbit; int oldbit;
...@@ -168,7 +168,7 @@ static __inline__ int __test_and_set_bit(int nr, volatile unsigned long * addr) ...@@ -168,7 +168,7 @@ static __inline__ int __test_and_set_bit(int nr, volatile unsigned long * addr)
* This operation is atomic and cannot be reordered. * This operation is atomic and cannot be reordered.
* It also implies a memory barrier. * It also implies a memory barrier.
*/ */
static __inline__ int test_and_clear_bit(int nr, volatile unsigned long * addr) static inline int test_and_clear_bit(int nr, volatile unsigned long * addr)
{ {
int oldbit; int oldbit;
...@@ -188,7 +188,7 @@ static __inline__ int test_and_clear_bit(int nr, volatile unsigned long * addr) ...@@ -188,7 +188,7 @@ static __inline__ int test_and_clear_bit(int nr, volatile unsigned long * addr)
* If two examples of this operation race, one can appear to succeed * If two examples of this operation race, one can appear to succeed
* but actually fail. You must protect multiple accesses with a lock. * but actually fail. You must protect multiple accesses with a lock.
*/ */
static __inline__ int __test_and_clear_bit(int nr, volatile unsigned long *addr) static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
{ {
int oldbit; int oldbit;
...@@ -200,7 +200,7 @@ static __inline__ int __test_and_clear_bit(int nr, volatile unsigned long *addr) ...@@ -200,7 +200,7 @@ static __inline__ int __test_and_clear_bit(int nr, volatile unsigned long *addr)
} }
/* WARNING: non atomic and it can be reordered! */ /* WARNING: non atomic and it can be reordered! */
static __inline__ int __test_and_change_bit(int nr, volatile unsigned long *addr) static inline int __test_and_change_bit(int nr, volatile unsigned long *addr)
{ {
int oldbit; int oldbit;
...@@ -219,7 +219,7 @@ static __inline__ int __test_and_change_bit(int nr, volatile unsigned long *addr ...@@ -219,7 +219,7 @@ static __inline__ int __test_and_change_bit(int nr, volatile unsigned long *addr
* This operation is atomic and cannot be reordered. * This operation is atomic and cannot be reordered.
* It also implies a memory barrier. * It also implies a memory barrier.
*/ */
static __inline__ int test_and_change_bit(int nr, volatile unsigned long* addr) static inline int test_and_change_bit(int nr, volatile unsigned long* addr)
{ {
int oldbit; int oldbit;
...@@ -244,7 +244,7 @@ static inline int constant_test_bit(int nr, const volatile unsigned long *addr) ...@@ -244,7 +244,7 @@ static inline int constant_test_bit(int nr, const volatile unsigned long *addr)
return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0; return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
} }
static __inline__ int variable_test_bit(int nr, const volatile unsigned long * addr) static inline int variable_test_bit(int nr, const volatile unsigned long * addr)
{ {
int oldbit; int oldbit;
...@@ -270,7 +270,7 @@ static __inline__ int variable_test_bit(int nr, const volatile unsigned long * a ...@@ -270,7 +270,7 @@ static __inline__ int variable_test_bit(int nr, const volatile unsigned long * a
* Returns the bit-number of the first zero bit, not the number of the byte * Returns the bit-number of the first zero bit, not the number of the byte
* containing a bit. * containing a bit.
*/ */
static __inline__ int find_first_zero_bit(const unsigned long *addr, unsigned size) static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
{ {
int d0, d1, d2; int d0, d1, d2;
int res; int res;
...@@ -294,6 +294,14 @@ static __inline__ int find_first_zero_bit(const unsigned long *addr, unsigned si ...@@ -294,6 +294,14 @@ static __inline__ int find_first_zero_bit(const unsigned long *addr, unsigned si
return res; return res;
} }
/**
* find_next_zero_bit - find the first zero 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
*/
int find_next_zero_bit(const unsigned long *addr, int size, int offset);
/** /**
* find_first_bit - find the first set bit in a memory region * find_first_bit - find the first set bit in a memory region
* @addr: The address to start the search at * @addr: The address to start the search at
...@@ -302,7 +310,7 @@ static __inline__ int find_first_zero_bit(const unsigned long *addr, unsigned si ...@@ -302,7 +310,7 @@ static __inline__ int find_first_zero_bit(const unsigned long *addr, unsigned si
* Returns the bit-number of the first set bit, not the number of the byte * Returns the bit-number of the first set bit, not the number of the byte
* containing a bit. * containing a bit.
*/ */
static __inline__ int find_first_bit(const unsigned long *addr, unsigned size) static inline int find_first_bit(const unsigned long *addr, unsigned size)
{ {
int d0, d1; int d0, d1;
int res; int res;
...@@ -322,71 +330,13 @@ static __inline__ int find_first_bit(const unsigned long *addr, unsigned size) ...@@ -322,71 +330,13 @@ static __inline__ int find_first_bit(const unsigned long *addr, unsigned size)
return res; return res;
} }
/**
* find_next_zero_bit - find the first zero 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__ int find_next_zero_bit(const unsigned long *addr, int size, int offset)
{
unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
int set = 0, bit = offset & 31, res;
if (bit) {
/*
* Look for zero in the first 32 bits.
*/
__asm__("bsfl %1,%0\n\t"
"jne 1f\n\t"
"movl $32, %0\n"
"1:"
: "=r" (set)
: "r" (~(*p >> bit)));
if (set < (32 - bit))
return set + offset;
set = 32 - bit;
p++;
}
/*
* No zero yet, search remaining full bytes for a zero
*/
res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr));
return (offset + set + res);
}
/** /**
* find_next_bit - find the first set bit in a memory region * find_next_bit - find the first set bit in a memory region
* @addr: The address to base the search on * @addr: The address to base the search on
* @offset: The bitnumber to start searching at * @offset: The bitnumber to start searching at
* @size: The maximum size to search * @size: The maximum size to search
*/ */
static __inline__ int find_next_bit(const unsigned long *addr, int size, int offset) int find_next_bit(const unsigned long *addr, int size, int offset);
{
const unsigned long *p = addr + (offset >> 5);
int set = 0, bit = offset & 31, res;
if (bit) {
/*
* Look for nonzero in the first 32 bits:
*/
__asm__("bsfl %1,%0\n\t"
"jne 1f\n\t"
"movl $32, %0\n"
"1:"
: "=r" (set)
: "r" (*p >> bit));
if (set < (32 - bit))
return set + offset;
set = 32 - bit;
p++;
}
/*
* No set bit yet, search remaining full words for a bit
*/
res = find_first_bit (p, size - 32 * (p - addr));
return (offset + set + res);
}
/** /**
* ffz - find first zero in word. * ffz - find first zero in word.
...@@ -394,7 +344,7 @@ static __inline__ int find_next_bit(const unsigned long *addr, int size, int off ...@@ -394,7 +344,7 @@ static __inline__ int find_next_bit(const unsigned long *addr, int size, int off
* *
* Undefined if no zero exists, so code should check against ~0UL first. * Undefined if no zero exists, so code should check against ~0UL first.
*/ */
static __inline__ unsigned long ffz(unsigned long word) static inline unsigned long ffz(unsigned long word)
{ {
__asm__("bsfl %1,%0" __asm__("bsfl %1,%0"
:"=r" (word) :"=r" (word)
...@@ -408,7 +358,7 @@ static __inline__ unsigned long ffz(unsigned long word) ...@@ -408,7 +358,7 @@ static __inline__ unsigned long ffz(unsigned long word)
* *
* Undefined if no bit exists, so code should check against 0 first. * Undefined if no bit exists, so code should check against 0 first.
*/ */
static __inline__ unsigned long __ffs(unsigned long word) static inline unsigned long __ffs(unsigned long word)
{ {
__asm__("bsfl %1,%0" __asm__("bsfl %1,%0"
:"=r" (word) :"=r" (word)
...@@ -451,7 +401,7 @@ static inline int sched_find_first_bit(const unsigned long *b) ...@@ -451,7 +401,7 @@ static inline int sched_find_first_bit(const unsigned long *b)
* the libc and compiler builtin ffs routines, therefore * the libc and compiler builtin ffs routines, therefore
* differs in spirit from the above ffz (man ffs). * differs in spirit from the above ffz (man ffs).
*/ */
static __inline__ int ffs(int x) static inline int ffs(int x)
{ {
int r; int r;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment