2021-09-26 11:34:20 -07:00
|
|
|
#ifndef MACROS_H
|
|
|
|
|
#define MACROS_H
|
2019-08-25 00:46:40 -04:00
|
|
|
|
2019-11-03 14:36:27 -05:00
|
|
|
#include "platform_info.h"
|
|
|
|
|
|
2020-04-03 14:57:26 -04:00
|
|
|
#ifndef __sgi
|
|
|
|
|
#define GLOBAL_ASM(...)
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-08-25 00:46:40 -04:00
|
|
|
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
|
|
|
|
|
|
|
|
|
#define GLUE(a, b) a ## b
|
|
|
|
|
#define GLUE2(a, b) GLUE(a, b)
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Avoid compiler warnings for unused variables.
|
2019-08-25 00:46:40 -04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define UNUSED __attribute__((unused))
|
|
|
|
|
#else
|
|
|
|
|
#define UNUSED
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Avoid undefined behaviour for non-returning functions.
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define NORETURN __attribute__((noreturn))
|
|
|
|
|
#else
|
|
|
|
|
#define NORETURN
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Always inline a function.
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define ALWAYS_INLINE inline __attribute__((always_inline))
|
|
|
|
|
#else
|
|
|
|
|
#define ALWAYS_INLINE inline
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Fall through a switch case.
|
2021-12-30 10:57:51 -06:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define FALL_THROUGH __attribute__((fallthrough))
|
|
|
|
|
#else
|
|
|
|
|
#define FALL_THROUGH
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Use Og when compiling the function.
|
2020-06-02 12:44:34 -04:00
|
|
|
#ifdef __GNUC__
|
2023-01-31 15:50:19 -05:00
|
|
|
#define OPTIMIZE_OG __attribute__((optimize("Og")))
|
2020-06-02 12:44:34 -04:00
|
|
|
#else
|
2023-01-31 15:50:19 -05:00
|
|
|
#define OPTIMIZE_OG
|
2020-06-02 12:44:34 -04:00
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Use Os when compiling the function.
|
2019-08-25 00:46:40 -04:00
|
|
|
#ifdef __GNUC__
|
2023-01-31 15:50:19 -05:00
|
|
|
#define OPTIMIZE_OS __attribute__((optimize("Os")))
|
2019-08-25 00:46:40 -04:00
|
|
|
#else
|
2023-01-31 15:50:19 -05:00
|
|
|
#define OPTIMIZE_OS
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Use Ofast when compiling the function.
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define OPTIMIZE_OFAST __attribute__((optimize("Ofast")))
|
|
|
|
|
#else
|
|
|
|
|
#define OPTIMIZE_OFAST
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Ignore 4-byte alignment in structs.
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define PACKED __attribute__((packed))
|
|
|
|
|
#else
|
|
|
|
|
#define PACKED
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Align to 4-byte boundary.
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define ALIGNED4 __attribute__((aligned(4)))
|
|
|
|
|
#else
|
|
|
|
|
#define ALIGNED4
|
2019-08-25 00:46:40 -04:00
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Align to 8-byte boundary (for DMA requirements).
|
2019-11-03 14:36:27 -05:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define ALIGNED8 __attribute__((aligned(8)))
|
|
|
|
|
#else
|
|
|
|
|
#define ALIGNED8
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Align to 16-byte boundary (for audio lib requirements).
|
2019-11-03 14:36:27 -05:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define ALIGNED16 __attribute__((aligned(16)))
|
|
|
|
|
#else
|
|
|
|
|
#define ALIGNED16
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Align to 32-byte boundary.
|
2021-12-30 10:57:51 -06:00
|
|
|
#ifdef __GNUC__
|
2023-01-31 15:50:19 -05:00
|
|
|
#define ALIGNED32 __attribute__((aligned(32)))
|
2021-12-30 10:57:51 -06:00
|
|
|
#else
|
2023-01-31 15:50:19 -05:00
|
|
|
#define ALIGNED32
|
2021-12-30 10:57:51 -06:00
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Align to 64-byte boundary.
|
2021-12-30 10:57:51 -06:00
|
|
|
#ifdef __GNUC__
|
2023-01-31 15:50:19 -05:00
|
|
|
#define ALIGNED64 __attribute__((aligned(64)))
|
2021-12-30 10:57:51 -06:00
|
|
|
#else
|
2023-01-31 15:50:19 -05:00
|
|
|
#define ALIGNED64
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef ALIGN
|
|
|
|
|
#define ALIGN(VAL_, ALIGNMENT_) (((VAL_) + ((ALIGNMENT_) - 1)) & ~((ALIGNMENT_) - 1))
|
2021-12-30 10:57:51 -06:00
|
|
|
#endif
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Round up to the next multiple.
|
|
|
|
|
#define ALIGN4(val) ALIGN((val), 4)
|
|
|
|
|
#define ALIGN8(val) ALIGN((val), 8)
|
|
|
|
|
#define ALIGN16(val) ALIGN((val), 16)
|
|
|
|
|
#define ALIGN32(val) ALIGN((val), 32)
|
|
|
|
|
#define ALIGN64(val) ALIGN((val), 64)
|
|
|
|
|
|
2020-06-02 12:44:34 -04:00
|
|
|
#ifndef NO_SEGMENTED_MEMORY
|
2023-01-31 15:50:19 -05:00
|
|
|
// Convert a virtual address to physical.
|
2019-10-05 15:08:05 -04:00
|
|
|
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) & 0x1FFFFFFF)
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Convert a physical address to virtual.
|
2019-10-05 15:08:05 -04:00
|
|
|
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) | 0x80000000)
|
|
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Another way of converting virtual to physical.
|
2019-10-05 15:08:05 -04:00
|
|
|
#define VIRTUAL_TO_PHYSICAL2(addr) ((u8 *)(addr) - 0x80000000U)
|
2023-01-31 15:50:19 -05:00
|
|
|
#else // NO_SEGMENTED_MEMORY
|
|
|
|
|
// No conversion needed other than cast.
|
2020-06-02 12:44:34 -04:00
|
|
|
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr))
|
|
|
|
|
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr))
|
|
|
|
|
#define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr))
|
2023-01-31 15:50:19 -05:00
|
|
|
#endif // NO_SEGMENTED_MEMORY
|
2020-06-02 12:44:34 -04:00
|
|
|
|
2023-01-31 15:50:19 -05:00
|
|
|
// Static (compile-time) assertions.
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
|
|
|
|
|
#else
|
|
|
|
|
#define STATIC_ASSERT(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
|
|
|
|
|
#endif
|
2021-12-30 10:57:51 -06:00
|
|
|
|
|
|
|
|
#define FORCE_CRASH { *(vs8*)0 = 0; }
|
2021-09-26 11:34:20 -07:00
|
|
|
|
|
|
|
|
#endif // MACROS_H
|