Menu Toggle
v2.3.1 (RP2350)
Toggle main menu visibility
Loading...
Searching...
No Matches
compiler.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3
*
4
* SPDX-License-Identifier: BSD-3-Clause
5
*/
6
7
#ifndef _PICO_PLATFORM_COMPILER_H
8
#define _PICO_PLATFORM_COMPILER_H
9
17
18
#include "hardware/platform_defs.h"
19
20
#ifndef __ASSEMBLER__
21
22
#if defined __GNUC__
23
#include <sys/cdefs.h>
24
#if !defined(__printflike) && defined(__picolibc_format)
25
#define __printflike(a,b) __picolibc_format(printf,a,b)
26
#endif
27
// note LLVM defines __GNUC__
28
#ifdef __clang__
29
#define PICO_C_COMPILER_IS_CLANG 1
30
#else
31
#define PICO_C_COMPILER_IS_GNU 1
32
#endif
33
#elif defined __ICCARM__
34
#ifndef __aligned
35
#define __aligned(x) __attribute__((__aligned__(x)))
36
#endif
37
#ifndef __always_inline
38
#define __always_inline __attribute__((__always_inline__))
39
#endif
40
#ifndef __noinline
41
#define __noinline __attribute__((__noinline__))
42
#endif
43
#ifndef __packed
44
#define __packed __attribute__((__packed__))
45
#endif
46
#ifndef __printflike
47
#define __printflike(a, b)
48
#endif
49
#ifndef __unused
50
#define __unused __attribute__((__unused__))
51
#endif
52
#ifndef __used
53
#define __used __attribute__((__used__))
54
#endif
55
#ifndef __CONCAT1
56
#define __CONCAT1(a, b) a ## b
57
#endif
58
#ifndef __CONCAT
59
#define __CONCAT(a, b) __CONCAT1(a, b)
60
#endif
61
#ifndef __STRING
62
#define __STRING(a) #a
63
#endif
64
/* Compatible definitions of GCC builtins */
65
66
static
inline
uint __builtin_ctz(uint x) {
67
extern
uint32_t __ctzsi2(uint32_t);
68
return
__ctzsi2(x);
69
}
70
#define __builtin_expect(x, y) (x)
71
#define __builtin_isnan(x) __iar_isnan(x)
72
#else
73
#error Unsupported toolchain
74
#endif
75
76
#define __weak __attribute__((weak))
77
78
#include "pico/types.h"
79
80
// GCC_Like_Pragma(x) is a pragma on GNUC compatible compilers
81
#ifdef __GNUC__
82
#define GCC_Like_Pragma _Pragma
83
#else
84
#define GCC_Like_Pragma(x)
85
#endif
86
87
// Clang_Pragma(x) is a pragma on Clang only
88
#ifdef __clang__
89
#define Clang_Pragma _Pragma
90
#else
91
#define Clang_Pragma(x)
92
#endif
93
94
// GCC_Pragma(x) is a pragma on GCC only
95
#if PICO_C_COMPILER_IS_GNU
96
#define GCC_Pragma _Pragma
97
#else
98
#define GCC_Pragma(x)
99
#endif
100
101
#ifdef __cplusplus
102
extern
"C"
{
103
#endif
104
112
#define __isr
113
114
#define __packed_aligned __packed __aligned(4)
115
124
125
#if PICO_C_COMPILER_IS_GNU && (__GNUC__ <= 6 || (__GNUC__ == 7 && (__GNUC_MINOR__ < 3 || !defined(__cplusplus))))
126
#define __force_inline inline __always_inline
127
#else
128
#define __force_inline __always_inline
129
#endif
130
134
#ifndef count_of
135
#define count_of(a) (sizeof(a)/sizeof((a)[0]))
136
#endif
137
141
#ifndef MAX
142
#define MAX(a, b) ((a)>(b)?(a):(b))
143
#endif
144
148
#ifndef MIN
149
#define MIN(a, b) ((b)>(a)?(a):(b))
150
#endif
151
152
#ifdef __ARM_ARCH_ISA_THUMB
153
#define pico_default_asm(...) __asm (".syntax unified\n" __VA_ARGS__)
154
#define pico_default_asm_volatile(...) __asm volatile (".syntax unified\n" __VA_ARGS__)
155
#define pico_default_asm_goto(...) __asm goto (".syntax unified\n" __VA_ARGS__)
156
#define pico_default_asm_volatile_goto(...) __asm volatile goto (".syntax unified\n" __VA_ARGS__)
157
#else
158
#define pico_default_asm(...) __asm (__VA_ARGS__)
159
#define pico_default_asm_volatile(...) __asm volatile (__VA_ARGS__)
160
#define pico_default_asm_goto(...) __asm goto (__VA_ARGS__)
161
#define pico_default_asm_volatile_goto(...) __asm volatile goto (__VA_ARGS__)
162
#endif
163
176
__force_inline
static
void
__compiler_memory_barrier
(
void
) {
177
pico_default_asm_volatile (
""
: : :
"memory"
);
178
}
179
186
#define __check_type_compatible(type_a, type_b) static_assert(__builtin_types_compatible_p(type_a, type_b), __STRING(type_a) " is not compatible with " __STRING(type_b));
187
188
#define WRAPPER_FUNC(x) __wrap_ ## x
189
#define REAL_FUNC(x) __real_ ## x
190
191
#ifdef __cplusplus
192
}
193
#endif
194
195
#else
// __ASSEMBLER__
196
197
#if defined __GNUC__
198
// note LLVM defines __GNUC__
199
#ifdef __clang__
200
#define PICO_ASSEMBLER_IS_CLANG 1
201
#else
202
#define PICO_ASSEMBLER_IS_GNU 1
203
#endif
204
#elif defined __ICCARM__
205
#else
206
#error Unsupported toolchain
207
#endif
208
209
#define WRAPPER_FUNC_NAME(x) __wrap_##x
210
211
#endif
// !__ASSEMBLER__
212
213
#endif
__force_inline
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition
compiler.h:128
__compiler_memory_barrier
static __always_inline void __compiler_memory_barrier(void)
Ensure that the compiler does not move memory access across this method call.
Definition
compiler.h:176