L4Re - L4 Runtime Environment
splitlog2.h
Go to the documentation of this file.
1 
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
7  * economic rights: Technische Universit├Ąt Dresden (Germany)
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU Lesser General Public License 2.1.
10  * Please see the COPYING-LGPL-2.1 file for details.
11  */
12 #ifndef __L4UTIL__INCLUDE__SPLITLOG2_H__
13 #define __L4UTIL__INCLUDE__SPLITLOG2_H__
14 
15 #include <l4/sys/linkage.h>
16 #include <l4/sys/err.h>
17 #include <l4/util/bitops.h>
18 
20 
33 L4_INLINE long
35  long (*handler)(l4_addr_t s, l4_addr_t e, int log2size));
36 
45 L4_INLINE l4_addr_t
47 
49 
50 /* Implementation */
51 
52 L4_INLINE long
54  long (*handler)(l4_addr_t s, l4_addr_t e, int log2size))
55 {
56  if (end < start)
57  return -L4_EINVAL;
58 
59  while (start <= end)
60  {
61  long retval;
62  int len2 = l4util_splitlog2_size(start, end);
63  l4_addr_t len = 1UL << len2;
64  if ((retval = handler(start, start + len - 1, len2)))
65  return retval;
66  start += len;
67  }
68  return 0;
69 }
70 
71 L4_INLINE l4_addr_t
73 {
74  int start_bits = l4util_bsf(start);
75  int len_bits = l4util_bsr(end - start + 1);
76  if (start_bits != -1 && len_bits > start_bits)
77  len_bits = start_bits;
78 
79  return len_bits;
80 }
81 
82 #endif /* ! __L4UTIL__INCLUDE__SPLITLOG2_H__ */
Invalid argument.
Definition: err.h:56
long l4util_splitlog2_hdl(l4_addr_t start, l4_addr_t end, long(*handler)(l4_addr_t s, l4_addr_t e, int log2size))
Split a range into log2 base and size aligned chunks.
Definition: splitlog2.h:53
#define EXTERN_C_END
End section with C types and functions.
Definition: compiler.h:187
bit manipulation functions
int l4util_bsf(l4_umword_t word)
Bit scan forward.
Definition: bitops.h:316
Error codes.
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition: compiler.h:186
l4_addr_t l4util_splitlog2_size(l4_addr_t start, l4_addr_t end)
Return log2 base and size aligned length of a range.
Definition: splitlog2.h:72
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
int l4util_bsr(l4_umword_t word)
Bit scan reverse.
Definition: bitops.h:299