bitops_32.h 2.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
#ifndef _I386_BITOPS_H
#define _I386_BITOPS_H

/*
 * Copyright 1992, Linus Torvalds.
 */

8
#ifndef CONFIG_GENERIC_FIND_FIRST_BIT
L
Linus Torvalds 已提交
9 10 11 12 13
/**
 * 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
 *
R
Randy Dunlap 已提交
14
 * Returns the bit number of the first zero bit, not the number of the byte
L
Linus Torvalds 已提交
15 16 17 18 19 20 21 22 23
 * 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;
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
	/* 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");
L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47
	return res;
}

/**
 * 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
 *
R
Randy Dunlap 已提交
48
 * Returns the bit number of the first set bit, not the number of the byte
L
Linus Torvalds 已提交
49 50
 * containing a bit.
 */
51
static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
L
Linus Torvalds 已提交
52
{
53
	unsigned x = 0;
L
Linus Torvalds 已提交
54 55 56 57 58

	while (x < size) {
		unsigned long val = *addr++;
		if (val)
			return __ffs(val) + x;
59
		x += sizeof(*addr) << 3;
L
Linus Torvalds 已提交
60
	}
61
	return x;
L
Linus Torvalds 已提交
62
}
63
#endif
L
Linus Torvalds 已提交
64 65 66

#ifdef __KERNEL__

67
#include <asm-generic/bitops/sched.h>
L
Linus Torvalds 已提交
68

69
#include <asm-generic/bitops/hweight.h>
L
Linus Torvalds 已提交
70 71 72

#endif /* __KERNEL__ */

73 74
#include <asm-generic/bitops/fls64.h>

L
Linus Torvalds 已提交
75 76
#ifdef __KERNEL__

77 78
#include <asm-generic/bitops/ext2-non-atomic.h>

79 80 81 82
#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))
83 84

#include <asm-generic/bitops/minix.h>
L
Linus Torvalds 已提交
85 86 87 88

#endif /* __KERNEL__ */

#endif /* _I386_BITOPS_H */