Phoenix
Object-oriented orthogonally persistent operating system
|
00001 /* 00002 * /phoenix/include/defs.h 00003 * 00004 * This file is a part of Phoenix operating system. 00005 * Copyright (c) 2011-2012, Artyom Lebedev <artyom.lebedev@gmail.com> 00006 * All rights reserved. 00007 * See COPYING file for copyright details. 00008 */ 00009 00017 #ifndef DEFS_H_ 00018 #define DEFS_H_ 00019 00021 #define OFFSETOF(type, member) __builtin_offsetof(type, member) 00022 00023 #define SIZEOF_ARRAY(array) (sizeof(array) / sizeof((array)[0])) 00024 00025 #define __CONCAT2(x, y) x##y 00026 00027 #define __CONCAT(x, y) __CONCAT2(x, y) 00028 00029 #define __STR2(x) # x 00030 00031 #define __STR(x) __STR2(x) 00032 00034 #define __UID(str) __CONCAT(str, __COUNTER__) 00035 00044 #define LIKELY(condition) __builtin_expect(!!(condition), 1) 00045 00053 #define UNLIKELY(condition) __builtin_expect(!!(condition), 0) 00054 00062 #define UNUSED __attribute__((unused)) 00063 00065 #define BIN(x) ((x & 0x1) | ((x & 0x10) ? 0x2 : 0) | \ 00066 ((x & 0x100) ? 0x4 : 0) | ((x & 0x1000) ? 0x8 : 0) | \ 00067 ((x & 0x10000) ? 0x10 : 0) | ((x & 0x100000) ? 0x20 : 0) | \ 00068 ((x & 0x1000000) ? 0x40 : 0) | ((x & 0x10000000) ? 0x80 : 0)) 00069 00071 #define NBBY 8 00072 00073 #ifdef __cplusplus 00074 00077 #define TYPECAST(type, value) static_cast<type>(value) 00078 #else /* __cplusplus */ 00079 #define TYPECAST(type, value) ((type)value) 00080 #endif /* __cplusplus */ 00081 00083 #define TYPE_INT_MIN(type) (TYPECAST(type, 1) << (sizeof(type) * NBBY - 1)) 00084 00085 #define TYPE_INT_MAX(type) (~TYPE_INT_MIN(type)) 00086 00087 #define TYPE_UINT_MAX(type) (TYPECAST(type, ~0ul)) 00088 00090 #define ASMCALL extern "C" __attribute__((regparm(0))) 00091 00093 #define ASM __asm__ __volatile__ 00094 00096 #define ASM_NAME(name) __asm__(__STR2(name)) 00097 00098 /* Shortcuts for various compiler attributes */ 00099 #define __PACKED __attribute__((packed)) 00100 #define __FORMAT(type, fmtIdx, argIdx) __attribute__ ((format(type, fmtIdx, argIdx))) 00101 #define __NORETURN __attribute__ ((noreturn)) 00102 #define __NOINLINE __attribute__ ((noinline)) 00103 00105 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 00106 00107 #define MAX(x, y) ((x) > (y) ? (x) : (y)) 00108 00110 #define ROUND_UP(size, align) (((size) + (align) - 1) / (align) * (align)) 00111 00112 #define ROUND_DOWN(size, align) ((size) / (align) * (align)) 00113 #define IS_POWER_OF_2(value) ((((value) - 1) & (value)) == 0) 00114 00118 #define ROUND_UP2(size, align) (((size) + (align) - 1) & (~((align) - 1))) 00119 00122 #define ROUND_DOWN2(size, align) ((size) & (~((align) - 1))) 00123 00124 //XXX should be removed after Eclipse will have 'constexpr' and 'nullptr' keyword recognized. 00125 #ifdef __CDT_PARSER__ 00126 #define constexpr 00127 #define nullptr ((void *)0) 00128 #endif /* __CDT_PARSER__ */ 00129 00130 #endif /* DEFS_H_ */