1 #ifndef __LUNAIX_SPIKE_H
2 #define __LUNAIX_SPIKE_H
4 // Some helper functions. As helpful as Spike the Dragon! :)
7 #define CEIL(v, k) (((v) + (1 << (k)) - 1) >> (k))
9 #define ICEIL(x, y) ((x) / (y) + ((x) % (y) != 0))
12 #define FLOOR(v, k) ((v) >> (k))
15 #define ROUNDUP(v, k) (((v) + (k)-1) & ~((k)-1))
18 #define ROUNDDOWN(v, k) ((v) & ~((k)-1))
20 #define MIN(a, b) ((a) < (b) ? (a) : (b))
21 #define MAX(a, b) ((a) > (b) ? (a) : (b))
23 #define __USER__ __attribute__((section(".usrtext")))
32 #ifdef __LUNAIXOS_DEBUG__
33 #define assert(cond) \
35 __assert_fail(#cond, __FILE__, __LINE__); \
38 #define assert_msg(cond, msg) \
40 __assert_fail(msg, __FILE__, __LINE__); \
43 __assert_fail(const char* expr, const char* file, unsigned int line)
44 __attribute__((noinline, noreturn));
46 #define assert(cond) (void)(cond); // assert nothing
47 #define assert_msg(cond, msg) (void)(cond); // assert nothing
51 panick(const char* msg);
53 #define wait_until(cond) \
56 #define loop_until(cond) \
60 #define wait_until_expire(cond, max) \
62 unsigned int __wcounter__ = (max); \
63 while (!(cond) && __wcounter__-- > 1) \
68 #endif /* __LUNAIX_SPIKE_H */