You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.2 KiB

  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2012.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaim all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Compiler specific definitions for code optimization and correctness.
  28. *
  29. * \copydetails Group_CompilerSpecific
  30. *
  31. * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
  32. * functionality.
  33. */
  34. /** \ingroup Group_Common
  35. * \defgroup Group_CompilerSpecific Compiler Specific Definitions
  36. * \brief Compiler specific definitions for code optimization and correctness.
  37. *
  38. * Compiler specific definitions to expose certain compiler features which may increase the level of code optimization
  39. * for a specific compiler, or correct certain issues that may be present such as memory barriers for use in conjunction
  40. * with atomic variable access.
  41. *
  42. * Where possible, on alternative compilers, these macros will either have no effect, or default to returning a sane value
  43. * so that they can be used in existing code without the need for extra compiler checks in the user application code.
  44. *
  45. * @{
  46. */
  47. #ifndef __LUFA_COMPILERSPEC_H__
  48. #define __LUFA_COMPILERSPEC_H__
  49. /* Preprocessor Checks: */
  50. #if !defined(__INCLUDE_FROM_COMMON_H)
  51. #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
  52. #endif
  53. /* Public Interface - May be used in end-application: */
  54. /* Macros: */
  55. #if defined(__GNUC__) || defined(__DOXYGEN__)
  56. /** Forces GCC to use pointer indirection (via the device's pointer register pairs) when accessing the given
  57. * struct pointer. In some cases GCC will emit non-optimal assembly code when accessing a structure through
  58. * a pointer, resulting in a larger binary. When this macro is used on a (non \c const) structure pointer before
  59. * use, it will force GCC to use pointer indirection on the elements rather than direct store and load
  60. * instructions.
  61. *
  62. * \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode.
  63. */
  64. #define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr))
  65. /** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point.
  66. * This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting
  67. * assembly output in an unexpected manner on sections of code that are ordering-specific.
  68. */
  69. #define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory");
  70. /** Determines if the specified value can be determined at compile-time to be a constant value when compiling under GCC.
  71. *
  72. * \param[in] x Value to check compile-time constantness of.
  73. *
  74. * \return Boolean true if the given value is known to be a compile time constant, false otherwise.
  75. */
  76. #define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x)
  77. #else
  78. #define GCC_FORCE_POINTER_ACCESS(StructPtr)
  79. #define GCC_MEMORY_BARRIER()
  80. #define GCC_IS_COMPILE_CONST(x) 0
  81. #endif
  82. #endif
  83. /** @} */