1 /* Copyright (c) 2015 Regents of the University of California
3 * Author: Brian Demsky <bdemsky@uci.edu>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
11 * @brief General purpose macros.
21 #define NANOSEC 1000000000.0
26 extern int switch_alloc;
28 #define model_dprintf(fd, fmt, ...) do { int oldsw = switch_alloc; switch_alloc = 1; dprintf(fd, fmt, ## __VA_ARGS__); switch_alloc = oldsw; } while (0)
30 #define model_print(fmt, ...) do { model_dprintf(model_out, fmt, ## __VA_ARGS__); } while (0)
31 #define model_print_err(fmt, ...) do { model_dprintf(model_err, fmt, ## __VA_ARGS__); } while (0)
33 #define model_print printf
38 #define NEXTPOW2(x) ((x == 1) ? 1 : (1 << (sizeof(uint) * 8 - __builtin_clz(x - 1))))
39 #define NUMBITS(x) ((x == 0) ? 0 : 8 * sizeof(x) - __builtin_clz(x))
42 #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ## __VA_ARGS__); } while (0)
43 #define DBG() DEBUG("\n")
44 #define LOG(fmt, ...) do{model_print(fmt, ## __VA_ARGS__);}while(0)
45 #define DBG_ENABLED() (1)
47 #define DEBUG(fmt, ...)
49 #define DBG_ENABLED() (0)
52 void assert_hook(void);
55 #define ASSERT(expr) \
58 fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
59 /* print_trace(); // Trace printing may cause dynamic memory allocation */ \
65 #define ASSERT(expr) \
67 #endif/* CONFIG_ASSERT */
69 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
71 void print_trace(void);
73 static inline long long getTimeNano() {
75 clock_gettime(CLOCK_REALTIME, &time);
76 return time.tv_sec * 1000000000 + time.tv_nsec;
78 #endif/* __COMMON_H__ */