Xen Test Framework
bitops.h
Go to the documentation of this file.
1
6#ifndef XTF_X86_BITOPS_H
7#define XTF_X86_BITOPS_H
8
9#include <xtf/lib.h>
10
11static inline bool test_bit(unsigned int bit, const void *addr)
12{
13 bool old;
14
15 asm volatile ("bt %[bit], %[ptr];"
16 ASM_FLAG_OUT(, "sbb %[old], %[old];")
17 : [old] ASM_FLAG_OUT("=@ccc", "=r") (old)
18 : [ptr] "m" (*(char *)addr),
19 [bit] "Ir" (bit)
20 : "memory");
21
22 return old;
23}
24
25static inline bool test_and_set_bit(unsigned int bit, volatile void *addr)
26{
27 bool old;
28
29 asm volatile ("lock; bts %[bit], %[ptr];"
30 ASM_FLAG_OUT(, "sbb %[old], %[old];")
31 : [old] ASM_FLAG_OUT("=@ccc", "=r") (old),
32 [ptr] "+m" (*(char *)addr)
33 : [bit] "Ir" (bit)
34 : "memory");
35
36 return old;
37}
38
39static inline bool test_and_change_bit(unsigned int bit, volatile void *addr)
40{
41 bool old;
42
43 asm volatile ("lock; btc %[bit], %[ptr];"
44 ASM_FLAG_OUT(, "sbb %[old], %[old];")
45 : [old] ASM_FLAG_OUT("=@ccc", "=r") (old),
46 [ptr] "+m" (*(char *)addr)
47 : [bit] "Ir" (bit)
48 : "memory");
49
50 return old;
51}
52
53static inline bool test_and_clear_bit(unsigned int bit, volatile void *addr)
54{
55 bool old;
56
57 asm volatile ("lock; btr %[bit], %[ptr];"
58 ASM_FLAG_OUT(, "sbb %[old], %[old];")
59 : [old] ASM_FLAG_OUT("=@ccc", "=r") (old),
60 [ptr] "+m" (*(char *)addr)
61 : [bit] "Ir" (bit)
62 : "memory");
63
64 return old;
65}
66
67#endif /* XTF_X86_BITOPS_H */
68
69/*
70 * Local variables:
71 * mode: C
72 * c-file-style: "BSD"
73 * c-basic-offset: 4
74 * tab-width: 4
75 * indent-tabs-mode: nil
76 * End:
77 */
static bool test_bit(unsigned int bit, const void *addr)
Definition: bitops.h:11
static bool test_and_set_bit(unsigned int bit, volatile void *addr)
Definition: bitops.h:25
static bool test_and_clear_bit(unsigned int bit, volatile void *addr)
Definition: bitops.h:53
static bool test_and_change_bit(unsigned int bit, volatile void *addr)
Definition: bitops.h:39
#define ASM_FLAG_OUT(yes, no)
Definition: compiler-gcc.h:24