diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-06-05 21:25:37 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-06-20 09:26:10 -0400 |
commit | 189ebb4c7d5134296ce9e2bebe304a795b38ef89 (patch) | |
tree | 3b6c3249e9268b5bd0a87c50758e26146d867f0b /klippy/chelper/compiler.h | |
parent | bedbfceafc39489dfcc6cf453b7d64df262455e5 (diff) | |
download | kutter-189ebb4c7d5134296ce9e2bebe304a795b38ef89.tar.gz kutter-189ebb4c7d5134296ce9e2bebe304a795b38ef89.tar.xz kutter-189ebb4c7d5134296ce9e2bebe304a795b38ef89.zip |
chelper: Add compiler.h header
Add the compiler.h header file to the chelper code - this adds a
number of useful gcc definitions.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/chelper/compiler.h')
-rw-r--r-- | klippy/chelper/compiler.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/klippy/chelper/compiler.h b/klippy/chelper/compiler.h new file mode 100644 index 00000000..ab16efbd --- /dev/null +++ b/klippy/chelper/compiler.h @@ -0,0 +1,46 @@ +#ifndef __COMPILER_H +#define __COMPILER_H +// Low level definitions for C languange and gcc compiler. + +#define barrier() __asm__ __volatile__("": : :"memory") + +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) + +#define noinline __attribute__((noinline)) +#ifndef __always_inline +#define __always_inline inline __attribute__((always_inline)) +#endif +#define __visible __attribute__((externally_visible)) +#define __noreturn __attribute__((noreturn)) + +#define PACKED __attribute__((packed)) +#ifndef __aligned +#define __aligned(x) __attribute__((aligned(x))) +#endif +#ifndef __section +#define __section(S) __attribute__((section(S))) +#endif + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) +#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1)) + +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define __stringify_1(x) #x +#define __stringify(x) __stringify_1(x) + +#define ___PASTE(a,b) a##b +#define __PASTE(a,b) ___PASTE(a,b) + +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define DIV_ROUND_CLOSEST(x, divisor)({ \ + typeof(divisor) __divisor = divisor; \ + (((x) + ((__divisor) / 2)) / (__divisor)); \ + }) + +#endif // compiler.h |