From a02e4ac262208f9e2604d5d03aa096a0d2d47b25 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Sun, 25 Jun 2017 20:46:23 +0200 Subject: 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. --- kern/macros.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'kern/macros.h') 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 -#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 */ -- cgit v1.2.3