1 /*****************************************************************************/
4 * \brief amd64 bit manipulation functions
8 * \author Lars Reuther <reuther@os.inf.tu-dresden.de>
9 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10 * Frank Mehnert <fm3@os.inf.tu-dresden.de> */
12 * (c) 2000-2009 Author(s)
13 * economic rights: Technische Universität Dresden (Germany)
14 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU Lesser General Public License 2.1.
16 * Please see the COPYING-LGPL-2.1 file for details.
19 /*****************************************************************************/
20 #ifndef __L4UTIL__INCLUDE__ARCH_AMD64__BITOPS_ARCH_H__
21 #define __L4UTIL__INCLUDE__ARCH_AMD64__BITOPS_ARCH_H__
25 /*****************************************************************************
27 *****************************************************************************/
30 #define __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT32
32 l4util_set_bit32(int b, volatile l4_uint32_t * dest)
39 "m" (*dest), /* 0 mem, destination operand */
40 "Ir" (b) /* 1, bit number */
46 #define __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT64
48 l4util_set_bit64(int b, volatile l4_uint64_t * dest)
55 "m" (*dest), /* 0 mem, destination operand */
56 "Ir" (b) /* 1, bit number */
62 #define __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT
64 l4util_set_bit(int b, volatile l4_umword_t * dest)
66 return l4util_set_bit64(b, (volatile l4_uint64_t*)dest);
70 #define __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT32
72 l4util_clear_bit32(int b, volatile l4_uint32_t * dest)
79 "m" (*dest), /* 0 mem, destination operand */
80 "Ir" (b) /* 1, bit number */
86 #define __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT64
88 l4util_clear_bit64(int b, volatile l4_uint64_t * dest)
95 "m" (*dest), /* 0 mem, destination operand */
96 "Ir" (b) /* 1, bit number */
102 #define __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT
104 l4util_clear_bit(int b, volatile l4_umword_t * dest)
106 return l4util_clear_bit64(b, (volatile l4_uint64_t*)dest);
110 #define __L4UTIL_BITOPS_HAVE_ARCH_COMPLEMENT_BIT
112 l4util_complement_bit(int b, volatile l4_umword_t * dest)
119 "m" (*dest), /* 0 mem, destination operand */
120 "Ir" ((l4_umword_t)b) /* 1, bit number */
127 #define __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT32
129 l4util_test_bit32(int b, const volatile l4_uint32_t * dest)
138 "=r" (bit) /* 0, old bit value */
140 "m" (*dest), /* 1 mem, destination operand */
141 "Ir" (b) /* 2, bit number */
149 #define __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT64
151 l4util_test_bit64(int b, const volatile l4_uint64_t * dest)
160 "=r" (bit) /* 0, old bit value */
162 "m" (*dest), /* 1 mem, destination operand */
163 "Ir" (b) /* 2, bit number */
171 #define __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT
173 l4util_test_bit(int b, const volatile l4_umword_t * dest)
175 return l4util_test_bit64(b, (const volatile l4_uint64_t *)dest);
179 /* bit test and set */
180 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_SET
182 l4util_bts(int b, volatile l4_umword_t * dest)
191 "=r" (bit) /* 0, old bit value */
193 "m" (*dest), /* 1 mem, destination operand */
194 "Ir" (b) /* 2, bit number */
202 /* bit test and reset */
203 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_RESET
205 l4util_btr(int b, volatile l4_umword_t * dest)
214 "=r" (bit) /* 0, old bit value */
216 "m" (*dest), /* 1 mem, destination operand */
217 "Ir" (b) /* 2, bit number */
225 /* bit test and complement */
226 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_COMPLEMENT
228 l4util_btc(int b, volatile l4_umword_t * dest)
237 "=r" (bit) /* 0, old bit value */
239 "m" (*dest), /* 1 mem, destination operand */
240 "Ir" ((l4_umword_t)b) /* 2, bit number */
248 /* bit scan reverse */
249 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_REVERSE
251 l4util_bsr(l4_umword_t word)
255 if (L4_UNLIKELY(word == 0))
262 "=r" (tmp) /* 0, index of most significant set bit */
264 "r" (word) /* 1, argument */
270 /* bit scan forwad */
271 #define __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_FORWARD
273 l4util_bsf(l4_umword_t word)
277 if (L4_UNLIKELY(word == 0))
284 "=r" (tmp) /* 0, index of least significant set bit */
286 "r" (word) /* 1, argument */
292 #define __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_SET_BIT
294 l4util_find_first_set_bit(const void * dest, l4_size_t size)
296 l4_mword_t dummy0, dummy1, res;
300 "xor %%rax,%%rax \n\t"
303 "lea -4(%%rdi),%%rdi \n\t"
304 "bsfq (%%rdi),%%rax \n"
306 "sub %%rbx,%%rdi \n\t"
308 "add %%rdi,%%rax \n\t"
310 "=a" (res), "=&c" (dummy0), "=&D" (dummy1)
312 "1" ((size + 31) >> 5), "2" (dest), "b" (dest)
319 #define __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_ZERO_BIT
321 l4util_find_first_zero_bit(const void * dest, l4_size_t size)
323 l4_mword_t dummy0, dummy1, dummy2, res;
331 "xor %%rdx,%%rdx \n\t"
334 "xor -4(%%rdi),%%rax \n\t"
338 "sub %[dest],%%rdi \n\t"
340 "add %%rdi,%%rdx \n\t"
342 "=d" (res), "=&c" (dummy0), "=&D" (dummy1), "=&a" (dummy2)
344 "1" ((size + 31) >> 5), "2" (dest), [dest] "S" (dest)
353 #endif /* ! __L4UTIL__INCLUDE__ARCH_AMD64__BITOPS_ARCH_H__ */