Zephyr API Documentation
4.1.99
A Scalable Open Source RTOS
4.1.99
Toggle main menu visibility
Main Page
Related Pages
Topics
Data Structures
Data Structures
Data Structure Index
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
Enumerator
Files
File List
Globals
All
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
$
a
b
c
d
f
g
h
i
k
l
m
n
o
p
r
s
t
u
x
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Macros
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
▼
Zephyr API Documentation
►
Introduction
Deprecated List
►
Topics
►
Data Structures
▼
Files
▼
File List
►
doc
►
kernel
►
lib
►
subsys
▼
zephyr
►
acpi
►
app_memory
►
arch
►
audio
►
bluetooth
►
canbus
►
console
►
crypto
►
data
►
debug
►
devicetree
►
dfu
►
display
►
drivers
►
dsp
►
dt-bindings
►
fs
►
input
►
internal
►
ipc
►
kernel
►
linker
►
llext
►
logging
►
lorawan
▼
math
►
ilog2.h
►
interpolation.h
►
mem_mgmt
►
mgmt
►
misc
►
modbus
►
modem
►
multi_heap
►
net
►
platform
►
pm
►
pmci
►
portability
►
posix
►
psa
►
random
►
retention
►
rtio
►
sd
►
sensing
►
settings
►
shell
►
sip_svc
►
stats
►
storage
►
sys
►
task_wdt
►
timing
►
toolchain
►
tracing
►
usb
►
usb_c
►
xen
►
zbus
►
zvfs
►
bindesc.h
►
cache.h
►
device.h
►
devicetree.h
►
fatal.h
►
fatal_types.h
►
init.h
►
irq.h
►
irq_multilevel.h
►
irq_nextlevel.h
►
irq_offload.h
►
kernel.h
kernel_includes.h
►
kernel_structs.h
►
kernel_version.h
►
net_buf.h
►
shared_irq.h
►
smf.h
►
spinlock.h
►
sw_isr_table.h
►
sys_clock.h
►
syscall.h
►
toolchain.h
types.h
►
Globals
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
ilog2.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2021 Intel Corporation
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_MATH_ILOG2_H_
8
#define ZEPHYR_INCLUDE_MATH_ILOG2_H_
9
10
#include <
stdint.h
>
11
12
#include <
zephyr/toolchain.h
>
13
#include <
zephyr/arch/common/ffs.h
>
14
#include <
zephyr/sys/util.h
>
15
39
#define ilog2_compile_time_const_u32(n) \
40
( \
41
((n) < 2) ? 0 : \
42
(((n) & BIT(31)) == BIT(31)) ? 31 : \
43
(((n) & BIT(30)) == BIT(30)) ? 30 : \
44
(((n) & BIT(29)) == BIT(29)) ? 29 : \
45
(((n) & BIT(28)) == BIT(28)) ? 28 : \
46
(((n) & BIT(27)) == BIT(27)) ? 27 : \
47
(((n) & BIT(26)) == BIT(26)) ? 26 : \
48
(((n) & BIT(25)) == BIT(25)) ? 25 : \
49
(((n) & BIT(24)) == BIT(24)) ? 24 : \
50
(((n) & BIT(23)) == BIT(23)) ? 23 : \
51
(((n) & BIT(22)) == BIT(22)) ? 22 : \
52
(((n) & BIT(21)) == BIT(21)) ? 21 : \
53
(((n) & BIT(20)) == BIT(20)) ? 20 : \
54
(((n) & BIT(19)) == BIT(19)) ? 19 : \
55
(((n) & BIT(18)) == BIT(18)) ? 18 : \
56
(((n) & BIT(17)) == BIT(17)) ? 17 : \
57
(((n) & BIT(16)) == BIT(16)) ? 16 : \
58
(((n) & BIT(15)) == BIT(15)) ? 15 : \
59
(((n) & BIT(14)) == BIT(14)) ? 14 : \
60
(((n) & BIT(13)) == BIT(13)) ? 13 : \
61
(((n) & BIT(12)) == BIT(12)) ? 12 : \
62
(((n) & BIT(11)) == BIT(11)) ? 11 : \
63
(((n) & BIT(10)) == BIT(10)) ? 10 : \
64
(((n) & BIT(9)) == BIT(9)) ? 9 : \
65
(((n) & BIT(8)) == BIT(8)) ? 8 : \
66
(((n) & BIT(7)) == BIT(7)) ? 7 : \
67
(((n) & BIT(6)) == BIT(6)) ? 6 : \
68
(((n) & BIT(5)) == BIT(5)) ? 5 : \
69
(((n) & BIT(4)) == BIT(4)) ? 4 : \
70
(((n) & BIT(3)) == BIT(3)) ? 3 : \
71
(((n) & BIT(2)) == BIT(2)) ? 2 : \
72
1 \
73
)
39
#define ilog2_compile_time_const_u32(n) \
…
74
87
/*
88
* This is in #define form as this needs to also work on
89
* compile time constants. Doing this as a static inline
90
* function will result in compiler complaining with
91
* "initializer element is not constant".
92
*/
93
#define ilog2(n) \
94
( \
95
__builtin_constant_p(n) ? \
96
ilog2_compile_time_const_u32(n) : \
97
find_msb_set(n) - 1 \
98
)
93
#define ilog2(n) \
…
99
100
#endif
/* ZEPHYR_INCLUDE_MATH_ILOG2_H_ */
ffs.h
stdint.h
util.h
Misc utilities.
toolchain.h
Macros to abstract toolchain specific capabilities.
zephyr
math
ilog2.h
Generated on Fri May 16 2025 06:06:19 for Zephyr API Documentation by
1.12.0