| 1 | #pragma once |
| 2 | |
| 3 | /* |
| 4 | * Compiler-specific attributes/macros go here. This is the default placeholder |
| 5 | * that should work for MSVC/GCC/clang. |
| 6 | */ |
| 7 | |
| 8 | #ifdef UACPI_OVERRIDE_COMPILER |
| 9 | #include "uacpi_compiler.h" |
| 10 | #else |
| 11 | |
| 12 | #define UACPI_ALIGN(x) __declspec(align(x)) |
| 13 | |
| 14 | #if defined(__WATCOMC__) |
| 15 | #define UACPI_STATIC_ASSERT(expr, msg) |
| 16 | #elif defined(__cplusplus) |
| 17 | #define UACPI_STATIC_ASSERT static_assert |
| 18 | #else |
| 19 | #define UACPI_STATIC_ASSERT _Static_assert |
| 20 | #endif |
| 21 | |
| 22 | #ifdef _MSC_VER |
| 23 | #include <intrin.h> |
| 24 | |
| 25 | #define UACPI_ALWAYS_INLINE __forceinline |
| 26 | |
| 27 | #define UACPI_PACKED(decl) \ |
| 28 | __pragma(pack(push, 1)) \ |
| 29 | decl; \ |
| 30 | __pragma(pack(pop)) |
| 31 | #elif defined(__WATCOMC__) |
| 32 | #define UACPI_ALWAYS_INLINE inline |
| 33 | #define UACPI_PACKED(decl) _Packed decl; |
| 34 | #else |
| 35 | #define UACPI_ALWAYS_INLINE inline __attribute__((always_inline)) |
| 36 | #define UACPI_PACKED(decl) decl __attribute__((packed)); |
| 37 | #endif |
| 38 | |
| 39 | #if defined(__GNUC__) || defined(__clang__) |
| 40 | #define uacpi_unlikely(expr) __builtin_expect(!!(expr), 0) |
| 41 | #define uacpi_likely(expr) __builtin_expect(!!(expr), 1) |
| 42 | |
| 43 | #ifdef __has_attribute |
| 44 | #if __has_attribute(__fallthrough__) |
| 45 | #define UACPI_FALLTHROUGH __attribute__((__fallthrough__)) |
| 46 | #endif |
| 47 | #endif |
| 48 | |
| 49 | #define UACPI_MAYBE_UNUSED __attribute__ ((unused)) |
| 50 | |
| 51 | #define UACPI_NO_UNUSED_PARAMETER_WARNINGS_BEGIN \ |
| 52 | _Pragma("GCC diagnostic push") \ |
| 53 | _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") |
| 54 | |
| 55 | #define UACPI_NO_UNUSED_PARAMETER_WARNINGS_END \ |
| 56 | _Pragma("GCC diagnostic pop") |
| 57 | |
| 58 | #ifdef __clang__ |
| 59 | #define UACPI_PRINTF_DECL(fmt_idx, args_idx) \ |
| 60 | __attribute__((format(printf, fmt_idx, args_idx))) |
| 61 | #else |
| 62 | #define UACPI_PRINTF_DECL(fmt_idx, args_idx) \ |
| 63 | __attribute__((format(gnu_printf, fmt_idx, args_idx))) |
| 64 | #endif |
| 65 | |
| 66 | #define UACPI_COMPILER_HAS_BUILTIN_MEMCPY |
| 67 | #define UACPI_COMPILER_HAS_BUILTIN_MEMMOVE |
| 68 | #define UACPI_COMPILER_HAS_BUILTIN_MEMSET |
| 69 | #define UACPI_COMPILER_HAS_BUILTIN_MEMCMP |
| 70 | #elif defined(__WATCOMC__) |
| 71 | #define uacpi_unlikely(expr) expr |
| 72 | #define uacpi_likely(expr) expr |
| 73 | |
| 74 | /* |
| 75 | * The OpenWatcom documentation suggests this should be done using |
| 76 | * _Pragma("off (unreferenced)") and _Pragma("pop (unreferenced)"), |
| 77 | * but these pragmas appear to be no-ops. Use inline as the next best thing. |
| 78 | * Note that OpenWatcom accepts redundant modifiers without a warning, |
| 79 | * so UACPI_MAYBE_UNUSED inline still works. |
| 80 | */ |
| 81 | #define UACPI_MAYBE_UNUSED inline |
| 82 | |
| 83 | #define UACPI_NO_UNUSED_PARAMETER_WARNINGS_BEGIN |
| 84 | #define UACPI_NO_UNUSED_PARAMETER_WARNINGS_END |
| 85 | |
| 86 | #define UACPI_PRINTF_DECL(fmt_idx, args_idx) |
| 87 | #else |
| 88 | #define uacpi_unlikely(expr) expr |
| 89 | #define uacpi_likely(expr) expr |
| 90 | |
| 91 | #define UACPI_MAYBE_UNUSED |
| 92 | |
| 93 | #define UACPI_NO_UNUSED_PARAMETER_WARNINGS_BEGIN |
| 94 | #define UACPI_NO_UNUSED_PARAMETER_WARNINGS_END |
| 95 | |
| 96 | #define UACPI_PRINTF_DECL(fmt_idx, args_idx) |
| 97 | #endif |
| 98 | |
| 99 | #ifndef UACPI_FALLTHROUGH |
| 100 | #define UACPI_FALLTHROUGH do {} while (0) |
| 101 | #endif |
| 102 | |
| 103 | #ifndef UACPI_POINTER_SIZE |
| 104 | #ifdef _WIN32 |
| 105 | #ifdef _WIN64 |
| 106 | #define UACPI_POINTER_SIZE 8 |
| 107 | #else |
| 108 | #define UACPI_POINTER_SIZE 4 |
| 109 | #endif |
| 110 | #elif defined(__GNUC__) |
| 111 | #define UACPI_POINTER_SIZE __SIZEOF_POINTER__ |
| 112 | #elif defined(__WATCOMC__) |
| 113 | #ifdef __386__ |
| 114 | #define UACPI_POINTER_SIZE 4 |
| 115 | #elif defined(__I86__) |
| 116 | #error uACPI does not support 16-bit mode compilation |
| 117 | #else |
| 118 | #error Unknown target architecture |
| 119 | #endif |
| 120 | #else |
| 121 | #error Failed to detect pointer size |
| 122 | #endif |
| 123 | #endif |
| 124 | |
| 125 | #endif |
| 126 | |