2005-04-16 18:20:36 -04:00
|
|
|
#ifndef _X86_64_BITOPS_H
|
|
|
|
#define _X86_64_BITOPS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1992, Linus Torvalds.
|
|
|
|
*/
|
|
|
|
|
2007-10-25 17:27:24 -04:00
|
|
|
extern long find_first_zero_bit(const unsigned long *addr, unsigned long size);
|
|
|
|
extern long find_next_zero_bit(const unsigned long *addr, long size, long offset);
|
|
|
|
extern long find_first_bit(const unsigned long *addr, unsigned long size);
|
|
|
|
extern long find_next_bit(const unsigned long *addr, long size, long offset);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
/* return index of first bet set in val or max when no bit is set */
|
2007-10-17 12:04:38 -04:00
|
|
|
static inline long __scanbit(unsigned long val, unsigned long max)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
asm("bsfq %1,%0 ; cmovz %2,%0" : "=&r" (val) : "r" (val), "r" (max));
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define find_first_bit(addr,size) \
|
|
|
|
((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
|
|
|
|
(__scanbit(*(unsigned long *)addr,(size))) : \
|
|
|
|
find_first_bit(addr,size)))
|
|
|
|
|
|
|
|
#define find_next_bit(addr,size,off) \
|
|
|
|
((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
|
|
|
|
((off) + (__scanbit((*(unsigned long *)addr) >> (off),(size)-(off)))) : \
|
|
|
|
find_next_bit(addr,size,off)))
|
|
|
|
|
|
|
|
#define find_first_zero_bit(addr,size) \
|
|
|
|
((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
|
|
|
|
(__scanbit(~*(unsigned long *)addr,(size))) : \
|
|
|
|
find_first_zero_bit(addr,size)))
|
|
|
|
|
|
|
|
#define find_next_zero_bit(addr,size,off) \
|
|
|
|
((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
|
|
|
|
((off)+(__scanbit(~(((*(unsigned long *)addr)) >> (off)),(size)-(off)))) : \
|
|
|
|
find_next_zero_bit(addr,size,off)))
|
|
|
|
|
|
|
|
static inline void set_bit_string(unsigned long *bitmap, unsigned long i,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
unsigned long end = i + len;
|
|
|
|
while (i < end) {
|
|
|
|
__set_bit(i, bitmap);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ffz - find first zero in word.
|
|
|
|
* @word: The word to search
|
|
|
|
*
|
|
|
|
* Undefined if no zero exists, so code should check against ~0UL first.
|
|
|
|
*/
|
2007-10-25 17:27:24 -04:00
|
|
|
static inline unsigned long ffz(unsigned long word)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
__asm__("bsfq %1,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"r" (~word));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __ffs - find first bit in word.
|
|
|
|
* @word: The word to search
|
|
|
|
*
|
|
|
|
* Undefined if no bit exists, so code should check against 0 first.
|
|
|
|
*/
|
2007-10-25 17:27:24 -04:00
|
|
|
static inline unsigned long __ffs(unsigned long word)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
__asm__("bsfq %1,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"rm" (word));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2005-12-21 22:31:36 -05:00
|
|
|
/*
|
|
|
|
* __fls: find last bit set.
|
|
|
|
* @word: The word to search
|
|
|
|
*
|
|
|
|
* Undefined if no zero exists, so code should check against ~0UL first.
|
|
|
|
*/
|
2007-10-25 17:27:24 -04:00
|
|
|
static inline unsigned long __fls(unsigned long word)
|
2005-12-21 22:31:36 -05:00
|
|
|
{
|
|
|
|
__asm__("bsrq %1,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"rm" (word));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
[PATCH] bitops: x86_64: use generic bitops
- remove sched_find_first_bit()
- remove generic_hweight{64,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>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 04:39:42 -05:00
|
|
|
#include <asm-generic/bitops/sched.h>
|
2005-04-16 18:20:36 -04: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
|
|
|
|
* differs in spirit from the above ffz (man ffs).
|
|
|
|
*/
|
2007-10-25 17:27:24 -04:00
|
|
|
static inline int ffs(int x)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__asm__("bsfl %1,%0\n\t"
|
|
|
|
"cmovzl %2,%0"
|
|
|
|
: "=r" (r) : "rm" (x), "r" (-1));
|
|
|
|
return r+1;
|
|
|
|
}
|
|
|
|
|
2005-12-21 22:31:36 -05:00
|
|
|
/**
|
|
|
|
* fls64 - find last bit set in 64 bit word
|
|
|
|
* @x: the word to search
|
|
|
|
*
|
|
|
|
* This is defined the same way as fls.
|
|
|
|
*/
|
2007-10-25 17:27:24 -04:00
|
|
|
static inline int fls64(__u64 x)
|
2005-12-21 22:31:36 -05:00
|
|
|
{
|
|
|
|
if (x == 0)
|
|
|
|
return 0;
|
|
|
|
return __fls(x) + 1;
|
|
|
|
}
|
|
|
|
|
2006-01-11 16:43:24 -05:00
|
|
|
/**
|
|
|
|
* fls - find last bit set
|
|
|
|
* @x: the word to search
|
|
|
|
*
|
|
|
|
* This is defined the same way as ffs.
|
|
|
|
*/
|
2007-10-25 17:27:24 -04:00
|
|
|
static inline int fls(int x)
|
2006-01-11 16:43:24 -05:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
__asm__("bsrl %1,%0\n\t"
|
|
|
|
"cmovzl %2,%0"
|
|
|
|
: "=&r" (r) : "rm" (x), "rm" (-1));
|
|
|
|
return r+1;
|
|
|
|
}
|
|
|
|
|
2006-09-26 04:52:38 -04:00
|
|
|
#define ARCH_HAS_FAST_MULTIPLIER 1
|
|
|
|
|
[PATCH] bitops: x86_64: use generic bitops
- remove sched_find_first_bit()
- remove generic_hweight{64,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>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 04:39:42 -05:00
|
|
|
#include <asm-generic/bitops/hweight.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
[PATCH] bitops: x86_64: use generic bitops
- remove sched_find_first_bit()
- remove generic_hweight{64,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>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 04:39:42 -05:00
|
|
|
#include <asm-generic/bitops/ext2-non-atomic.h>
|
|
|
|
|
2005-04-16 18:20:36 -04: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: x86_64: use generic bitops
- remove sched_find_first_bit()
- remove generic_hweight{64,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>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-26 04:39:42 -05:00
|
|
|
|
|
|
|
#include <asm-generic/bitops/minix.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* _X86_64_BITOPS_H */
|