esp_compiler.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. * The likely and unlikely macro pairs:
  18. * These macros are useful to place when application
  19. * knows the majority ocurrence of a decision paths,
  20. * placing one of these macros can hint the compiler
  21. * to reorder instructions producing more optimized
  22. * code.
  23. */
  24. #if (CONFIG_COMPILER_OPTIMIZATION_PERF)
  25. #define likely(x) __builtin_expect(!!(x), 1)
  26. #define unlikely(x) __builtin_expect(!!(x), 0)
  27. #else
  28. #define likely(x) (x)
  29. #define unlikely(x) (x)
  30. #endif
  31. /*
  32. * Utility macros used for designated initializers, which work differently
  33. * in C99 and C++ standards mainly for aggregate types.
  34. * The member separator, comma, is already part of the macro, please omit the trailing comma.
  35. * Usage example:
  36. * struct config_t { char* pchr; char arr[SIZE]; } config = {
  37. * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(pchr)
  38. * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value")
  39. * };
  40. */
  41. #ifdef __cplusplus
  42. #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) { .member = value },
  43. #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { },
  44. #else
  45. #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) .member = value,
  46. #define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member)
  47. #endif
  48. #endif