NimBLE-Arduino 2.1.3
Loading...
Searching...
No Matches
esp_compiler.h
1// Copyright 2016-2019 Espressif Systems (Shanghai) PTE LTD
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14#ifndef __ESP_COMPILER_H
15#define __ESP_COMPILER_H
16
17/*
18 * The likely and unlikely macro pairs:
19 * These macros are useful to place when application
20 * knows the majority ocurrence of a decision paths,
21 * placing one of these macros can hint the compiler
22 * to reorder instructions producing more optimized
23 * code.
24 */
25#if (CONFIG_COMPILER_OPTIMIZATION_PERF)
26#ifndef likely
27#define likely(x) __builtin_expect(!!(x), 1)
28#endif
29#ifndef unlikely
30#define unlikely(x) __builtin_expect(!!(x), 0)
31#endif
32#else
33#ifndef likely
34#define likely(x) (x)
35#endif
36#ifndef unlikely
37#define unlikely(x) (x)
38#endif
39#endif
40
41/*
42 * Utility macros used for designated initializers, which work differently
43 * in C99 and C++ standards mainly for aggregate types.
44 * The member separator, comma, is already part of the macro, please omit the trailing comma.
45 * Usage example:
46 * struct config_t { char* pchr; char arr[SIZE]; } config = {
47 * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(pchr)
48 * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value")
49 * };
50 */
51#ifdef __cplusplus
52#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) { .member = value },
53#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
54#else
55#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) .member = value,
56#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member)
57#endif
58
59#endif