| 1 | #ifndef __MDFN_TYPES |
| 2 | #define __MDFN_TYPES |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | typedef int8_t int8; |
| 8 | typedef int16_t int16; |
| 9 | typedef int32_t int32; |
| 10 | typedef int64_t int64; |
| 11 | |
| 12 | typedef uint8_t uint8; |
| 13 | typedef uint16_t uint16; |
| 14 | typedef uint32_t uint32; |
| 15 | typedef uint64_t uint64; |
| 16 | |
| 17 | #ifdef __GNUC__ |
| 18 | #define MDFN_UNLIKELY(n) __builtin_expect((n) != 0, 0) |
| 19 | #define MDFN_LIKELY(n) __builtin_expect((n) != 0, 1) |
| 20 | |
| 21 | #define INLINE inline __attribute__((always_inline)) |
| 22 | #define NO_INLINE __attribute__((noinline)) |
| 23 | |
| 24 | #if defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) |
| 25 | #define MDFN_FASTCALL __attribute__((fastcall)) |
| 26 | #else |
| 27 | #define MDFN_FASTCALL |
| 28 | #endif |
| 29 | |
| 30 | #define MDFN_ALIGN(n) __attribute__ ((aligned (n))) |
| 31 | #define MDFN_FORMATSTR(a,b,c) __attribute__ ((format (a, b, c))); |
| 32 | #define MDFN_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) |
| 33 | #define MDFN_NOWARN_UNUSED __attribute__((unused)) |
| 34 | |
| 35 | #elif defined(_MSC_VER) |
| 36 | #define roundf(in) (in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f)) |
| 37 | #define INLINE inline |
| 38 | #define NO_INLINE |
| 39 | #define MDFN_LIKELY(n) ((n) != 0) |
| 40 | #define MDFN_UNLIKELY(n) ((n) != 0) |
| 41 | |
| 42 | #define MDFN_FASTCALL |
| 43 | |
| 44 | #define MDFN_ALIGN(n) __declspec(align(n)) |
| 45 | |
| 46 | #define MDFN_FORMATSTR(a,b,c) |
| 47 | |
| 48 | #define MDFN_WARN_UNUSED_RESULT |
| 49 | #define MDFN_NOWARN_UNUSED |
| 50 | |
| 51 | #else |
| 52 | #error "Not compiling with GCC nor MSVC" |
| 53 | #define INLINE inline |
| 54 | #define NO_INLINE |
| 55 | |
| 56 | #define MDFN_FASTCALL |
| 57 | |
| 58 | #define MDFN_ALIGN(n) // hence the #error. |
| 59 | |
| 60 | #define MDFN_FORMATSTR(a,b,c) |
| 61 | |
| 62 | #define MDFN_WARN_UNUSED_RESULT |
| 63 | |
| 64 | #endif |
| 65 | |
| 66 | |
| 67 | typedef struct |
| 68 | { |
| 69 | union |
| 70 | { |
| 71 | struct |
| 72 | { |
| 73 | #ifdef MSB_FIRST |
| 74 | uint8 High; |
| 75 | uint8 Low; |
| 76 | #else |
| 77 | uint8 Low; |
| 78 | uint8 High; |
| 79 | #endif |
| 80 | } Union8; |
| 81 | uint16 Val16; |
| 82 | }; |
| 83 | } Uuint16; |
| 84 | |
| 85 | typedef struct |
| 86 | { |
| 87 | union |
| 88 | { |
| 89 | struct |
| 90 | { |
| 91 | #ifdef MSB_FIRST |
| 92 | Uuint16 High; |
| 93 | Uuint16 Low; |
| 94 | #else |
| 95 | Uuint16 Low; |
| 96 | Uuint16 High; |
| 97 | #endif |
| 98 | } Union16; |
| 99 | uint32 Val32; |
| 100 | }; |
| 101 | } Uuint32; |
| 102 | |
| 103 | #define MDFN_COLD |
| 104 | |
| 105 | #undef require |
| 106 | #define require( expr ) assert( expr ) |
| 107 | |
| 108 | #endif |