18#ifndef __L4UTIL__INCLUDE__BITOPS_H__
19#define __L4UTIL__INCLUDE__BITOPS_H__
22#include <l4/sys/l4int.h>
26#define l4util_test_and_clear_bit(b, dest) l4util_btr(b, dest)
27#define l4util_test_and_set_bit(b, dest) l4util_bts(b, dest)
28#define l4util_test_and_change_bit(b, dest) l4util_btc(b, dest)
29#define l4util_log2(word) l4util_bsr(word)
200#include <l4/util/bitops_arch.h>
206#ifndef __L4UTIL_BITOPS_HAVE_ARCH_SET_BIT
213 dest += b / (
sizeof(*dest) * 8);
214 b &=
sizeof(*dest) * 8 - 1;
219 newval = oldval | (1UL << b);
225#ifndef __L4UTIL_BITOPS_HAVE_ARCH_CLEAR_BIT
232 dest += b / (
sizeof(*dest) * 8);
233 b &=
sizeof(*dest) * 8 - 1;
238 newval = oldval & ~(1UL << b);
244#ifndef __L4UTIL_BITOPS_HAVE_ARCH_TEST_BIT
248 dest += b / (
sizeof(*dest) * 8);
249 b &=
sizeof(*dest) * 8 - 1;
251 return (*dest >> b) & 1;
255#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_SET
262 dest += b / (
sizeof(*dest) * 8);
263 b &=
sizeof(*dest) * 8 - 1;
268 newval = oldval | (1UL << b);
273 return (oldval >> b) & 1;
277#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_RESET
284 dest += b / (
sizeof(*dest) * 8);
285 b &=
sizeof(*dest) * 8 - 1;
290 newval = oldval & ~(1UL << b);
295 return (oldval >> b) & 1;
299#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_REVERSE
308 for (i = 8 *
sizeof(word) - 1; i >= 0; i--)
309 if ((1UL << i) & word)
312 __builtin_unreachable();
316#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_SCAN_FORWARD
325 for (i = 0; i <
sizeof(word) * 8; i++)
326 if ((1UL << i) & word)
329 __builtin_unreachable();
333#ifndef __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_ZERO_BIT
338 unsigned long *v = (
unsigned long*)dest;
343 size = (size + 31) & ~0x1f;
345 for (i = j = 0; i < size; i++, j++)
347 if (j >=
sizeof(*v) * 8)
352 if (!((1UL << j) & *v))
359#ifndef __L4UTIL_BITOPS_HAVE_ARCH_COMPLEMENT_BIT
363 dest += b / (
sizeof(*dest) * 8);
364 b &=
sizeof(*dest) * 8 - 1;
383 for (i=1; i <
sizeof(
unsigned long)*8; i<<=1)
384 val = val | val >> i;
392extern int __this_l4util_bitops_function_is_not_implemented_for_this_arch__sorry(
void);
394#ifndef __L4UTIL_BITOPS_HAVE_ARCH_BIT_TEST_AND_COMPLEMENT
397{ (void)b; (void)dest; __this_l4util_bitops_function_is_not_implemented_for_this_arch__sorry();
return 0; }
400#ifndef __L4UTIL_BITOPS_HAVE_ARCH_FIND_FIRST_SET_BIT
403{ (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 L4_INLINE
L4 Inline function attribute.
#define EXTERN_C_BEGIN
Start section with C types and functions.
#define EXTERN_C_END
End 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