16#ifndef __L4UTIL__INCLUDE__BITOPS_H__
17#define __L4UTIL__INCLUDE__BITOPS_H__
20#include <l4/sys/l4int.h>
24#define l4util_test_and_clear_bit(b, dest) l4util_btr(b, dest)
25#define l4util_test_and_set_bit(b, dest) l4util_bts(b, dest)
26#define l4util_test_and_change_bit(b, dest) l4util_btc(b, dest)
27#define l4util_log2(word) l4util_bsr(word)
198#include <l4/util/bitops_arch.h>
204#ifndef __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT
211 dest += b / (
sizeof(*dest) * 8);
212 b &=
sizeof(*dest) * 8 - 1;
217 newval = oldval | (1UL << b);
223#ifndef __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT
230 dest += b / (
sizeof(*dest) * 8);
231 b &=
sizeof(*dest) * 8 - 1;
236 newval = oldval & ~(1UL << b);
242#ifndef __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT
246 dest += b / (
sizeof(*dest) * 8);
247 b &=
sizeof(*dest) * 8 - 1;
249 return (*dest >> b) & 1;
253#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_SET
260 dest += b / (
sizeof(*dest) * 8);
261 b &=
sizeof(*dest) * 8 - 1;
266 newval = oldval | (1UL << b);
271 return (oldval >> b) & 1;
275#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_RESET
282 dest += b / (
sizeof(*dest) * 8);
283 b &=
sizeof(*dest) * 8 - 1;
288 newval = oldval & ~(1UL << b);
293 return (oldval >> b) & 1;
297#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_REVERSE
306 for (i = 8 *
sizeof(word) - 1; i >= 0; i--)
307 if ((1UL << i) & word)
310 __builtin_unreachable();
314#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_FORWARD
323 for (i = 0; i <
sizeof(word) * 8; i++)
324 if ((1UL << i) & word)
327 __builtin_unreachable();
331#ifndef __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_ZERO_BIT
336 unsigned long *v = (
unsigned long*)dest;
341 size = (size + 31) & ~0x1f;
343 for (i = j = 0; i < size; i++, j++)
345 if (j >=
sizeof(*v) * 8)
350 if (!((1UL << j) & *v))
357#ifndef __L4UTIL_BITOPS_HAVE_ARCH_COMPLEMENT_BIT
361 dest += b / (
sizeof(*dest) * 8);
362 b &=
sizeof(*dest) * 8 - 1;
381 for (i=1; i <
sizeof(
unsigned long)*8; i<<=1)
382 val = val | val >> i;
390extern int __this_l4util_bitops_function_is_not_implemented_for_this_arch__sorry(
void);
392#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_COMPLEMENT
395{ (void)b; (void)dest; __this_l4util_bitops_function_is_not_implemented_for_this_arch__sorry();
return 0; }
398#ifndef __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_SET_BIT
401{ (void)dest; (void)size; __this_l4util_bitops_function_is_not_implemented_for_this_arch__sorry();
return 0; }
L4 compiler related defines.
unsigned int l4_size_t
Unsigned size type.
unsigned long l4_umword_t
Unsigned machine word.
#define __END_DECLS
End section with C types and functions.
#define L4_INLINE
L4 Inline function attribute.
#define __BEGIN_DECLS
Start section with C types and functions.
int l4util_cmpxchg(volatile l4_umword_t *dest, l4_umword_t cmp_val, l4_umword_t new_val)
Atomic compare and exchange (machine wide fields)
void l4util_set_bit(int b, volatile l4_umword_t *dest)
Set bit in memory.
int l4util_next_power2(unsigned long val)
Find the next power of 2 for a given number.
int l4util_bsf(l4_umword_t word)
Bit scan forward.
int l4util_btc(int b, volatile l4_umword_t *dest)
Bit test and complement.
int l4util_bsr(l4_umword_t word)
Bit scan reverse.
int l4util_btr(int b, volatile l4_umword_t *dest)
Bit test and reset.
int l4util_find_first_set_bit(const void *dest, l4_size_t size)
Find the first set bit in a memory region.
int l4util_bts(int b, volatile l4_umword_t *dest)
Bit test and set.
int l4util_find_first_zero_bit(const void *dest, l4_size_t size)
Find the first zero bit in a memory region.
void l4util_clear_bit(int b, volatile l4_umword_t *dest)
Clear bit in memory.
int l4util_test_bit(int b, const volatile l4_umword_t *dest)
Test bit (return value of bit)
void l4util_complement_bit(int b, volatile l4_umword_t *dest)
Complement bit in memory.
atomic operations header and generic implementations