summaryrefslogtreecommitdiff
path: root/lib/macros.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2012-10-10 21:18:27 +0200
committerRichard Braun <rbraun@sceen.net>2012-10-10 21:18:27 +0200
commit696a41936ac9712f928c86be1b61bd1baea7405c (patch)
treec045f45cf8b61ccf93bdfc9a25a48cc0a79b0500 /lib/macros.h
parenta4485f033c4ffa07955a45cad30424aedb89dff4 (diff)
macros: new DECL_CONST macro
This macro is needed where a constant value can be used in both assembly and C code, but it needs a specific type in C code for correct results. This type is usually assigned with a suffix such as "UL", which makes assembly fail. DECL_CONST creates different forms based on the language.
Diffstat (limited to 'lib/macros.h')
-rw-r--r--lib/macros.h55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/macros.h b/lib/macros.h
index ca6379ac..4894a335 100644
--- a/lib/macros.h
+++ b/lib/macros.h
@@ -21,42 +21,51 @@
#ifndef _LIB_MACROS_H
#define _LIB_MACROS_H
+#ifndef __ASSEMBLY__
#include <lib/stddef.h>
+#endif /* __ASSEMBLY__ */
-#define MACRO_BEGIN ({
-#define MACRO_END })
+#define MACRO_BEGIN ({
+#define MACRO_END })
-#define XQUOTE(x) #x
-#define QUOTE(x) XQUOTE(x)
+#define XQUOTE(x) #x
+#define QUOTE(x) XQUOTE(x)
-#define STRLEN(x) (sizeof(x) - 1)
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#ifdef __ASSEMBLY__
+#define DECL_CONST(x, s) x
+#else /* __ASSEMBLY__ */
+#define __DECL_CONST(x, s) x##s
+#define DECL_CONST(x, s) __DECL_CONST(x, s)
+#endif /* __ASSEMBLY__ */
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define STRLEN(x) (sizeof(x) - 1)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define P2ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
-#define ISP2(x) P2ALIGNED(x, x)
-#define P2ALIGN(x, a) ((x) & -(a))
-#define P2ROUND(x, a) (-(-(x) & -(a)))
-#define P2END(x, a) (-(~(x) & -(a)))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+#define P2ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
+#define ISP2(x) P2ALIGNED(x, x)
+#define P2ALIGN(x, a) ((x) & -(a))
+#define P2ROUND(x, a) (-(-(x) & -(a)))
+#define P2END(x, a) (-(~(x) & -(a)))
#define structof(ptr, type, member) \
((type *)((char *)ptr - offsetof(type, member)))
-#define alignof(x) __alignof__(x)
+#define alignof(x) __alignof__(x)
-#define likely(expr) __builtin_expect(!!(expr), 1)
-#define unlikely(expr) __builtin_expect(!!(expr), 0)
+#define likely(expr) __builtin_expect(!!(expr), 1)
+#define unlikely(expr) __builtin_expect(!!(expr), 0)
-#define barrier() asm volatile("" : : : "memory")
+#define barrier() asm volatile("" : : : "memory")
-#define __noreturn __attribute__((noreturn))
-#define __aligned(x) __attribute__((aligned(x)))
-#define __always_inline inline __attribute__((always_inline))
-#define __section(x) __attribute__((section(x)))
-#define __packed __attribute__((packed))
-#define __alias(x) __attribute__((alias(x)))
+#define __noreturn __attribute__((noreturn))
+#define __aligned(x) __attribute__((aligned(x)))
+#define __always_inline inline __attribute__((always_inline))
+#define __section(x) __attribute__((section(x)))
+#define __packed __attribute__((packed))
+#define __alias(x) __attribute__((alias(x)))
#define __format_printf(fmt, args) \
__attribute__((format(printf, fmt, args)))