2005-04-16 16:20:36 -06:00
|
|
|
#ifndef _I386_BITOPS_H
|
|
|
|
#define _I386_BITOPS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1992, Linus Torvalds.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_first_zero_bit - find the first zero bit in a memory region
|
|
|
|
* @addr: The address to start the search at
|
|
|
|
* @size: The maximum size to search
|
|
|
|
*
|
2008-01-30 05:30:32 -07:00
|
|
|
* Returns the bit number of the first zero bit, not the number of the byte
|
2005-04-16 16:20:36 -06:00
|
|
|
* containing a bit.
|
|
|
|
*/
|
|
|
|
static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
|
|
|
|
{
|
|
|
|
int d0, d1, d2;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
return 0;
|
2008-03-23 02:01:43 -06:00
|
|
|
/* This looks at memory.
|
|
|
|
* Mark it volatile to tell gcc not to move it around
|
|
|
|
*/
|
|
|
|
asm volatile("movl $-1,%%eax\n\t"
|
|
|
|
"xorl %%edx,%%edx\n\t"
|
|
|
|
"repe; scasl\n\t"
|
|
|
|
"je 1f\n\t"
|
|
|
|
"xorl -4(%%edi),%%eax\n\t"
|
|
|
|
"subl $4,%%edi\n\t"
|
|
|
|
"bsfl %%eax,%%edx\n"
|
|
|
|
"1:\tsubl %%ebx,%%edi\n\t"
|
|
|
|
"shll $3,%%edi\n\t"
|
|
|
|
"addl %%edi,%%edx"
|
|
|
|
: "=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
|
|
|
|
: "1" ((size + 31) >> 5), "2" (addr),
|
|
|
|
"b" (addr) : "memory");
|
2005-04-16 16:20:36 -06:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_next_zero_bit - find the first zero bit in a memory region
|
|
|
|
* @addr: The address to base the search on
|
2008-01-30 05:30:32 -07:00
|
|
|
* @offset: The bit number to start searching at
|
2005-04-16 16:20:36 -06:00
|
|
|
* @size: The maximum size to search
|
|
|
|
*/
|
|
|
|
int find_next_zero_bit(const unsigned long *addr, int size, int offset);
|
|
|
|
|
2005-07-28 06:45:06 -06:00
|
|
|
/**
|
|
|
|
* __ffs - find first bit in word.
|
|
|
|
* @word: The word to search
|
|
|
|
*
|
|
|
|
* Undefined if no bit exists, so code should check against 0 first.
|
|
|
|
*/
|
|
|
|
static inline unsigned long __ffs(unsigned long word)
|
|
|
|
{
|
|
|
|
__asm__("bsfl %1,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"rm" (word));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/**
|
|
|
|
* find_first_bit - find the first set bit in a memory region
|
|
|
|
* @addr: The address to start the search at
|
|
|
|
* @size: The maximum size to search
|
|
|
|
*
|
2008-01-30 05:30:32 -07:00
|
|
|
* Returns the bit number of the first set bit, not the number of the byte
|
2005-04-16 16:20:36 -06:00
|
|
|
* containing a bit.
|
|
|
|
*/
|
2006-01-06 01:11:59 -07:00
|
|
|
static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-01-06 01:11:59 -07:00
|
|
|
unsigned x = 0;
|
2005-07-29 09:01:22 -06:00
|
|
|
|
|
|
|
while (x < size) {
|
|
|
|
unsigned long val = *addr++;
|
|
|
|
if (val)
|
|
|
|
return __ffs(val) + x;
|
2008-03-23 02:01:43 -06:00
|
|
|
x += sizeof(*addr) << 3;
|
2005-07-29 09:01:22 -06:00
|
|
|
}
|
2005-07-28 06:45:06 -06:00
|
|
|
return x;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_next_bit - find the first set bit in a memory region
|
|
|
|
* @addr: The address to base the search on
|
2008-01-30 05:30:32 -07:00
|
|
|
* @offset: The bit number to start searching at
|
2005-04-16 16:20:36 -06:00
|
|
|
* @size: The maximum size to search
|
|
|
|
*/
|
|
|
|
int find_next_bit(const unsigned long *addr, int size, int offset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ffz - find first zero in word.
|
|
|
|
* @word: The word to search
|
|
|
|
*
|
|
|
|
* Undefined if no zero exists, so code should check against ~0UL first.
|
|
|
|
*/
|
|
|
|
static inline unsigned long ffz(unsigned long word)
|
|
|
|
{
|
|
|
|
__asm__("bsfl %1,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"r" (~word));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
[PATCH] bitops: i386: use generic bitops
- remove generic_fls64()
- remove sched_find_first_bit()
- remove generic_hweight{32,16,8}()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 02:39:24 -07:00
|
|
|
#include <asm-generic/bitops/sched.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ffs - find first bit set
|
|
|
|
* @x: the word to search
|
|
|
|
*
|
|
|
|
* This is defined the same way as
|
|
|
|
* the libc and compiler builtin ffs routines, therefore
|
2007-02-10 02:45:59 -07:00
|
|
|
* differs in spirit from the above ffz() (man ffs).
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
static inline int ffs(int x)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__asm__("bsfl %1,%0\n\t"
|
|
|
|
"jnz 1f\n\t"
|
|
|
|
"movl $-1,%0\n"
|
|
|
|
"1:" : "=r" (r) : "rm" (x));
|
|
|
|
return r+1;
|
|
|
|
}
|
|
|
|
|
2006-01-06 01:12:12 -07:00
|
|
|
/**
|
|
|
|
* fls - find last bit set
|
|
|
|
* @x: the word to search
|
|
|
|
*
|
2007-02-10 02:45:59 -07:00
|
|
|
* This is defined the same way as ffs().
|
2006-01-06 01:12:12 -07:00
|
|
|
*/
|
|
|
|
static inline int fls(int x)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__asm__("bsrl %1,%0\n\t"
|
|
|
|
"jnz 1f\n\t"
|
|
|
|
"movl $-1,%0\n"
|
|
|
|
"1:" : "=r" (r) : "rm" (x));
|
|
|
|
return r+1;
|
|
|
|
}
|
|
|
|
|
[PATCH] bitops: i386: use generic bitops
- remove generic_fls64()
- remove sched_find_first_bit()
- remove generic_hweight{32,16,8}()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 02:39:24 -07:00
|
|
|
#include <asm-generic/bitops/hweight.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
[PATCH] bitops: i386: use generic bitops
- remove generic_fls64()
- remove sched_find_first_bit()
- remove generic_hweight{32,16,8}()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 02:39:24 -07:00
|
|
|
#include <asm-generic/bitops/fls64.h>
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
[PATCH] bitops: i386: use generic bitops
- remove generic_fls64()
- remove sched_find_first_bit()
- remove generic_hweight{32,16,8}()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 02:39:24 -07:00
|
|
|
#include <asm-generic/bitops/ext2-non-atomic.h>
|
|
|
|
|
2008-03-23 02:01:43 -06:00
|
|
|
#define ext2_set_bit_atomic(lock, nr, addr) \
|
|
|
|
test_and_set_bit((nr), (unsigned long *)(addr))
|
|
|
|
#define ext2_clear_bit_atomic(lock, nr, addr) \
|
|
|
|
test_and_clear_bit((nr), (unsigned long *)(addr))
|
[PATCH] bitops: i386: use generic bitops
- remove generic_fls64()
- remove sched_find_first_bit()
- remove generic_hweight{32,16,8}()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 02:39:24 -07:00
|
|
|
|
|
|
|
#include <asm-generic/bitops/minix.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* _I386_BITOPS_H */
|