#ifndef AVREMU_UTIL_H_ #define AVREMU_UTIL_H_ #ifndef __GNUC__ # error "Not using the GNU GCC compiler." #endif #include "list.h" #include #include #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #ifdef RUNTIME_SANITY_CHECKS # define CHECK(x) unlikely(x) #else # define CHECK(x) 0 #endif #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) #define is_const_value(x) __builtin_constant_p(x) /* Force reload a variable from memory. */ #define reload_var(x) (*((volatile typeof(x) *)&(x))) /* Break the linkage of the binary, if the constant condition is true. * This is useful for compiletime checks of constant values. */ #define break_linkage_on(constant_condition, reason) do { \ if (constant_condition) { \ extern void __avremu_bug__##reason(void); \ __avremu_bug__##reason(); \ } \ } while (0) #define __stringify(x) #x #define stringify(x) __stringify(x) typedef uint16_t le16_t; typedef uint32_t le32_t; typedef _Bool bool; static inline uint16_t swap16(uint16_t x) { return (x >> 8) | (x << 8); } static inline uint16_t le16_to_cpu(le16_t x) { #ifdef BIG_ENDIAN_HOST return swap16((uint16_t)x); #else return (uint16_t)x; #endif } static inline le16_t cpu_to_le16(uint16_t x) { #ifdef BIG_ENDIAN_HOST return (le16_t)swap16(x); #else return (le16_t)x; #endif } void * avr_malloc(size_t size); #endif /* AVREMU_UTIL_H_ */