PER Firmware
Loading...
Searching...
No Matches
common_defs.h
Go to the documentation of this file.
1
12#ifndef COMMON_DEFS_H
13#define COMMON_DEFS_H
14
15// todo: axe this file. common/utils/ contains modernized implementations
16
17#include <stdint.h>
18
19// Base-2 logarithm that rounds down
20static inline uint32_t LOG2_DOWN(uint32_t x) {
21 return 31U - (uint32_t)__builtin_clz(x);
22}
23
24// Base-2 logarithm that rounds up
25static inline uint32_t LOG2_UP(uint32_t x) {
26 return LOG2_DOWN(x - 1) + 1;
27}
28
29static inline uint32_t ROUNDDOWN(uint32_t a, uint32_t n) {
30 return a - (a % n);
31}
32
33// Round up to the nearest multiple of n
34static inline uint32_t ROUNDUP(uint32_t a, uint32_t n) {
35 return ROUNDDOWN(a + n - 1, n);
36}
37
38#endif // COMMON_DEFS_H