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 __USER__ __attribute__((section(".usrtext")))
29 #ifdef __LUNAIXOS_DEBUG__
30 #define assert(cond) \
32 __assert_fail(#cond, __FILE__, __LINE__); \
35 #define assert_msg(cond, msg) \
37 __assert_fail(msg, __FILE__, __LINE__); \
40 __assert_fail(const char* expr, const char* file, unsigned int line)
41 __attribute__((noinline, noreturn));
43 #define assert(cond) (void)(cond); // assert nothing
44 #define assert_msg(cond, msg) (void)(cond); // assert nothing
48 panick(const char* msg);
50 #define wait_until(cond) \
53 #define loop_until(cond) \
57 #define wait_until_expire(cond, max) \
59 unsigned int __wcounter__ = (max); \
60 while (!(cond) && __wcounter__-- > 0) \
65 #endif /* __LUNAIX_SPIKE_H */