summaryrefslogtreecommitdiff
path: root/kern/macros.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-25 20:46:23 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-25 20:50:32 +0200
commita02e4ac262208f9e2604d5d03aa096a0d2d47b25 (patch)
tree67ab9121d6c56a435cd5d33565cef80fc58d0a86 /kern/macros.h
parentaf89762df2afa2528b85bf32a63fc4bee804d758 (diff)
kern/macros: update
Add comments to power-of-two alignment macros, remove functionality made standard in C11, remove the __alias macro, add the __noinline macro.
Diffstat (limited to 'kern/macros.h')
-rw-r--r--kern/macros.h31
1 files changed, 19 insertions, 12 deletions
diff --git a/kern/macros.h b/kern/macros.h
index 743bdc0d..6259dcee 100644
--- a/kern/macros.h
+++ b/kern/macros.h
@@ -24,9 +24,9 @@
#ifndef _KERN_MACROS_H
#define _KERN_MACROS_H
-#ifndef __ASSEMBLER__
-#include <stddef.h>
-#endif /* __ASSEMBLER__ */
+#if !defined(__GNUC__) || (__GNUC__ < 4)
+#error "GCC 4+ required"
+#endif
/*
* Attributes for variables that are mostly read and seldom changed.
@@ -56,29 +56,36 @@
#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 P2ALIGN(x, a) ((x) & -(a)) /* decreases if not aligned */
+#define P2ROUND(x, a) (-(-(x) & -(a))) /* increases if not aligned */
+#define P2END(x, a) (-(~(x) & -(a))) /* always increases */
#define structof(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
-#define alignof(x) __alignof__(x)
-
#define likely(expr) __builtin_expect(!!(expr), 1)
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#define barrier() asm volatile("" : : : "memory")
-#define __noreturn __attribute__((noreturn))
-#define __aligned(x) __attribute__((aligned(x)))
+/*
+ * The following macros may be provided by the C environment.
+ */
+
+#ifndef __noinline
+#define __noinline __attribute__((noinline))
+#endif
#ifndef __always_inline
#define __always_inline inline __attribute__((always_inline))
-#endif /* __attribute__ */
+#endif
+#ifndef __section
#define __section(x) __attribute__((section(x)))
+#endif
+
+#ifndef __packed
#define __packed __attribute__((packed))
-#define __alias(x) __attribute__((alias(x)))
+#endif
#endif /* _KERN_MACROS_H */