mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-10-31 13:09:38 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
 | |
|  *
 | |
|  * SPDX-License-Identifier: Apache-2.0
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include "sdkconfig.h"
 | |
| 
 | |
| /*
 | |
|  * The likely and unlikely macro pairs:
 | |
|  * These macros are useful to place when application
 | |
|  * knows the majority ocurrence of a decision paths,
 | |
|  * placing one of these macros can hint the compiler
 | |
|  * to reorder instructions producing more optimized
 | |
|  * code.
 | |
|  */
 | |
| #if (CONFIG_COMPILER_OPTIMIZATION_PERF)
 | |
| #ifndef likely
 | |
| #define likely(x)      __builtin_expect(!!(x), 1)
 | |
| #endif
 | |
| #ifndef unlikely
 | |
| #define unlikely(x)    __builtin_expect(!!(x), 0)
 | |
| #endif
 | |
| #else
 | |
| #ifndef likely
 | |
| #define likely(x)      (x)
 | |
| #endif
 | |
| #ifndef unlikely
 | |
| #define unlikely(x)    (x)
 | |
| #endif
 | |
| #endif
 | |
| 
 | |
| /*
 | |
|  * Utility macros used for designated initializers, which work differently
 | |
|  * in C99 and C++ standards mainly for aggregate types.
 | |
|  * The member separator, comma, is already part of the macro, please omit the trailing comma.
 | |
|  * Usage example:
 | |
|  *   struct config_t { char* pchr; char arr[SIZE]; } config = {
 | |
|  *              ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(pchr)
 | |
|  *              ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value")
 | |
|  *          };
 | |
|  */
 | |
| #if defined(__cplusplus) && __cplusplus >= 202002L
 | |
| #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value)  .member = value,
 | |
| #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
 | |
| #elif defined(__cplusplus) && __cplusplus < 202002L
 | |
| #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value)  { .member = value },
 | |
| #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
 | |
| #else
 | |
| #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value)  .member = value,
 | |
| #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member)
 | |
| #endif
 | 
