source: GPL/include/asm/bitops.h@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

File size: 2.7 KB
Line 
1#ifndef _I386_BITOPS_H
2#define _I386_BITOPS_H
3
4/*
5 * Copyright 1992, Linus Torvalds.
6 */
7
8/*
9 * These have to be done with inline assembly: that way the bit-setting
10 * is guaranteed to be atomic. All bit operations return 0 if the bit
11 * was cleared before the operation and != 0 if it was not.
12 *
13 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
14 */
15
16/*
17 * Function prototypes to keep gcc -Wall happy
18 */
19#ifdef __WATCOMC__
20int set_bit(int nr, volatile void * addr);
21#pragma aux set_bit = \
22 "bts dword ptr [esi], eax" \
23 "setc al" \
24 "movzx eax, al" \
25 parm [eax] [esi] \
26 value [eax]
27
28int clear_bit(int nr, volatile void * addr);
29#pragma aux clear_bit = \
30 "btr dword ptr [esi], eax" \
31 "setc al" \
32 "movzx eax, al" \
33 parm [eax] [esi] \
34 value [eax]
35
36int change_bit(int nr, volatile void * addr);
37#pragma aux change_bit = \
38 "btc dword ptr [esi], eax" \
39 "setc al" \
40 "movzx eax, al" \
41 parm [eax] [esi] \
42 value [eax]
43
44#define test_and_set_bit(nr, addr) set_bit(nr, addr)
45#define test_and_clear_bit(nr, addr) clear_bit(nr, addr)
46#define test_and_change_bit(nr, addr) change_bit(nr, addr)
47
48/*
49 * ffs: find first bit set. This is defined the same way as
50 * the libc and compiler builtin ffs routines, therefore
51 * differs in spirit from the above ffz (man ffs).
52 */
53
54int ffs(int x);
55#pragma aux ffs = \
56 "bsf eax, ebx" \
57 "jnz @f" \
58 "mov eax, -1" \
59 "@f:" \
60 "inc eax" \
61 parm [ebx] \
62 value [eax]
63
64/*
65 * ffz = Find First Zero in word. Undefined if no zero exists,
66 * so code should check against ~0UL first..
67 */
68unsigned long ffz(unsigned long word);
69#pragma aux ffz = \
70 "bsf eax, ebx" \
71 parm [ebx] \
72 value [eax]
73
74//{
75// int r;
76//
77// __asm__("bsfl %1,%0\n\t"
78// "jnz 1f\n\t"
79// "movl $-1,%0\n"
80// "1:" : "=r" (r) : "g" (x));
81// return r+1;
82//}
83
84#else
85extern void set_bit(int nr, volatile void * addr);
86extern void clear_bit(int nr, volatile void * addr);
87extern void change_bit(int nr, volatile void * addr);
88extern int test_and_set_bit(int nr, volatile void * addr);
89extern int test_and_clear_bit(int nr, volatile void * addr);
90extern int test_and_change_bit(int nr, volatile void * addr);
91#endif
92
93extern int __constant_test_bit(int nr, const volatile void * addr);
94extern int __test_bit(int nr, volatile void * addr);
95extern int find_first_zero_bit(void * addr, unsigned size);
96extern int find_next_zero_bit (void * addr, int size, int offset);
97
98/*
99 * This routine doesn't need to be atomic.
100 */
101#define test_bit(nr, addr) (((1UL << (nr & 31)) & (((const unsigned int *) addr)[nr >> 5])) != 0)
102
103#endif /* _I386_BITOPS_H */
Note: See TracBrowser for help on using the repository browser.