• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define likely(x)      __builtin_expect(!!(x), 1)
27 #define unlikely(x)    __builtin_expect(!!(x), 0)
28 #else
29 #define likely(x)      (x)
30 #define unlikely(x)    (x)
31 #endif
32 
33 /*
34  * Utility macros used for designated initializers, which work differently
35  * in C99 and C++ standards mainly for aggregate types.
36  * The member separator, comma, is already part of the macro, please omit the trailing comma.
37  * Usage example:
38  *   struct config_t { char* pchr; char arr[SIZE]; } config = {
39  *              ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(pchr)
40  *              ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value")
41  *          };
42  */
43 #ifdef __cplusplus
44 #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value)  { .member = value },
45 #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
46 #else
47 #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value)  .member = value,
48 #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member)
49 #endif
50 
51 #endif
52