This source file includes following definitions.
- set_bit
- clear_bit
- change_bit
- test_bit
- find_first_zero_bit
- find_next_zero_bit
- ffz
1 #ifndef _I386_BITOPS_H
2 #define _I386_BITOPS_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 struct __dummy { unsigned long a[100]; };
20 #define ADDR (*(struct __dummy *) addr)
21
22 extern __inline__ int set_bit(int nr, void * addr)
23 {
24 int oldbit;
25
26 __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
27 :"=r" (oldbit),"=m" (ADDR)
28 :"ir" (nr));
29 return oldbit;
30 }
31
32 extern __inline__ int clear_bit(int nr, void * addr)
33 {
34 int oldbit;
35
36 __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
37 :"=r" (oldbit),"=m" (ADDR)
38 :"ir" (nr));
39 return oldbit;
40 }
41
42 extern __inline__ int change_bit(int nr, void * addr)
43 {
44 int oldbit;
45
46 __asm__ __volatile__("btcl %2,%1\n\tsbbl %0,%0"
47 :"=r" (oldbit),"=m" (ADDR)
48 :"ir" (nr));
49 return oldbit;
50 }
51
52
53
54
55
56 extern __inline__ int test_bit(int nr, void * addr)
57 {
58 int oldbit;
59
60 __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
61 :"=r" (oldbit)
62 :"m" (ADDR),"ir" (nr));
63 return oldbit;
64 }
65
66
67
68
69 extern __inline__ int find_first_zero_bit(void * addr, unsigned size)
70 {
71 int res;
72
73 if (!size)
74 return 0;
75 __asm__("
76 cld
77 movl $-1,%%eax
78 xorl %%edx,%%edx
79 repe; scasl
80 je 1f
81 xorl -4(%%edi),%%eax
82 subl $4,%%edi
83 bsfl %%eax,%%edx
84 1: subl %%ebx,%%edi
85 shll $3,%%edi
86 addl %%edi,%%edx"
87 :"=d" (res)
88 :"c" ((size + 31) >> 5), "D" (addr), "b" (addr)
89 :"ax", "cx", "di");
90 return res;
91 }
92
93 extern __inline__ int find_next_zero_bit (void * addr, int size, int offset)
94 {
95 unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
96 int set = 0, bit = offset & 31, res;
97
98 if (bit) {
99
100
101
102 __asm__("
103 bsfl %1,%0
104 jne 1f
105 movl $32, %0
106 1: "
107 : "=r" (set)
108 : "r" (~(*p >> bit)));
109 if (set < (32 - bit))
110 return set + offset;
111 set = 32 - bit;
112 p++;
113 }
114
115
116
117 res = find_first_zero_bit (p, size - 32 * (p - (unsigned long *) addr));
118 return (offset + set + res);
119 }
120
121
122
123
124
125 extern __inline__ unsigned long ffz(unsigned long word)
126 {
127 __asm__("bsfl %1,%0"
128 :"=r" (word)
129 :"r" (~word));
130 return word;
131 }
132
133 #endif