Xenomai 3.3.2
Loading...
Searching...
No Matches
compiler.h
1/*
2 * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 */
18#ifndef _BOILERPLATE_COMPILER_H
19#define _BOILERPLATE_COMPILER_H
20
21#include <stddef.h>
22
23#define container_of(ptr, type, member) \
24 ({ \
25 const __typeof__(((type *)0)->member) *__mptr = (ptr); \
26 (type *)((char *)__mptr - offsetof(type, member)); \
27 })
28
29#define __stringify_1(x...) #x
30#define __stringify(x...) __stringify_1(x)
31
32#ifndef __noreturn
33#define __noreturn __attribute__((__noreturn__))
34#endif
35
36#ifndef __must_check
37#define __must_check __attribute__((__warn_unused_result__))
38#endif
39
40#ifndef __weak
41#define __weak __attribute__((__weak__))
42#endif
43
44#ifndef __maybe_unused
45#define __maybe_unused __attribute__((__unused__))
46#endif
47
48#ifndef __aligned
49#define __aligned(__n) __attribute__((aligned (__n)))
50#endif
51
52#ifndef __deprecated
53#define __deprecated __attribute__((__deprecated__))
54#endif
55
56#ifndef __packed
57#define __packed __attribute__((__packed__))
58#endif
59
60#ifndef __alloc_size
61#define __alloc_size(__args) __attribute__((__alloc_size__(__args)))
62#endif
63
64#define __align_to(__size, __al) (((__size) + (__al) - 1) & (~((__al) - 1)))
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70#define xenomai_count_trailing_zeros(x) \
71 ((x) == 0 ? (int)(sizeof(x) * __CHAR_BIT__) \
72 : sizeof(x) <= sizeof(unsigned int) ? \
73 __builtin_ctz((unsigned int)x) \
74 : sizeof(x) <= sizeof(unsigned long) ? \
75 __builtin_ctzl((unsigned long)x) \
76 : __builtin_ctzll(x))
77
78#define xenomai_count_leading_zeros(x) \
79 ((x) == 0 ? (int)(sizeof(x) * __CHAR_BIT__) \
80 : sizeof(x) <= sizeof(unsigned int) ? \
81 __builtin_clz((unsigned int)x) + \
82 (int)(sizeof(unsigned int) - sizeof(x)) \
83 : sizeof(x) <= sizeof(unsigned long) ? \
84 __builtin_clzl((unsigned long)x) \
85 : __builtin_clzll(x))
86
87#ifdef __cplusplus
88}
89#endif
90
91#endif /* _BOILERPLATE_COMPILER_H */