esp_compiler.h 2.0 KB

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