1 /*****************************************************************************/
4 * \brief x86 bit manipulation functions
8 * \author Lars Reuther <reuther@os.inf.tu-dresden.de> */
10 * (c) 2000-2009 Author(s)
11 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU Lesser General Public License 2.1.
14 * Please see the COPYING-LGPL-2.1 file for details.
17 /*****************************************************************************/
18 #ifndef __L4UTIL__INCLUDE__ARCH_X86__BITOPS_ARCH_H__
19 #define __L4UTIL__INCLUDE__ARCH_X86__BITOPS_ARCH_H__
21 /*****************************************************************************
23 *****************************************************************************/
28 #define __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT32
30 l4util_set_bit32(int b, volatile l4_uint32_t * dest)
37 "m" (*dest), /* 0 mem, destination operand */
38 "Ir" (b) /* 1, bit number */
44 #define __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT
46 l4util_set_bit(int b, volatile l4_umword_t * dest)
48 return l4util_set_bit32(b, (volatile l4_uint32_t*)dest);
52 #define __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT32
54 l4util_clear_bit32(int b, volatile l4_uint32_t * dest)
61 "m" (*dest), /* 0 mem, destination operand */
62 "Ir" (b) /* 1, bit number */
68 #define __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT
70 l4util_clear_bit(int b, volatile l4_umword_t * dest)
72 return l4util_clear_bit32(b, (volatile l4_uint32_t*)dest);
76 #define __L4UTIL_BITOPS_HAVE_ARCH_COMPLEMENT_BIT
78 l4util_complement_bit(int b, volatile l4_umword_t * dest)
85 "m" (*dest), /* 0 mem, destination operand */
86 "Ir" (b) /* 1, bit number */
93 #define __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT32
95 l4util_test_bit32(int b, const volatile l4_uint32_t * dest)
104 "=q" (bit) /* 0, old bit value */
106 "m" (*dest), /* 1 mem, destination operand */
107 "Ir" (b) /* 2, bit number */
116 #define __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT
118 l4util_test_bit(int b, const volatile l4_umword_t * dest)
120 return l4util_test_bit32(b, (const volatile l4_uint32_t*)dest);
123 /* bit test and set */
124 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_SET
126 l4util_bts(int b, volatile l4_umword_t * dest)
135 "=q" (bit) /* 0, old bit value */
137 "m" (*dest), /* 1 mem, destination operand */
138 "Ir" (b) /* 2, bit number */
146 /* bit test and reset */
147 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_RESET
149 l4util_btr(int b, volatile l4_umword_t * dest)
158 "=q" (bit) /* 0, old bit value */
160 "m" (*dest), /* 1 mem, destination operand */
161 "Ir" (b) /* 2, bit number */
169 /* bit test and complement */
170 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_COMPLEMENT
172 l4util_btc(int b, volatile l4_umword_t * dest)
181 "=q" (bit) /* 0, old bit value */
183 "m" (*dest), /* 1 mem, destination operand */
184 "Ir" (b) /* 2, bit number */
192 /* bit scan reverse */
193 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_REVERSE
195 l4util_bsr(l4_umword_t word)
199 if (L4_UNLIKELY(word == 0))
206 "=r" (tmp) /* 0, index of most significant set bit */
208 "r" (word) /* 1, argument */
214 /* bit scan forwad */
215 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_FORWARD
217 l4util_bsf(l4_umword_t word)
221 if (L4_UNLIKELY(word == 0))
228 "=r" (tmp) /* 0, index of least significant set bit */
230 "r" (word) /* 1, argument */
236 #define __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_SET_BIT
238 l4util_find_first_set_bit(const void * dest, l4_size_t size)
240 l4_mword_t dummy0, dummy1, res;
246 "leal -4(%%edi),%%edi \n\t"
247 "bsfl (%%edi),%%eax \n"
249 "subl %%esi,%%edi \n\t"
251 "addl %%edi,%%eax \n\t"
253 "=a" (res), "=c" (dummy0), "=D" (dummy1)
255 "a"(0), "c" ((size+31) >> 5), "D" (dest), "S" (dest)
262 #define __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_ZERO_BIT
264 l4util_find_first_zero_bit(const void * dest, l4_size_t size)
266 l4_mword_t dummy0, dummy1, dummy2, res;
275 "xorl -4(%%edi),%%eax \n\t"
277 "bsfl %%eax,%%edx \n"
279 "subl %%esi,%%edi \n\t"
281 "addl %%edi,%%edx \n\t"
283 "=d" (res), "=c" (dummy0), "=D" (dummy1), "=a" (dummy2)
285 "a" (~0), "c" ((size+31) >> 5), "d"(0), "D" (dest), "S" (dest)
294 #endif /* ! __L4UTIL__INCLUDE__ARCH_X86__BITOPS_ARCH_H__ */