SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Core/defs.h
1 #pragma once
2
3 #define GB_likely(x) __builtin_expect((bool)(x), 1)
4 #define GB_unlikely(x) __builtin_expect((bool)(x), 0)
5 #define GB_inline_const(type, ...) (*({static const typeof(type) _= __VA_ARGS__; &_;}))
6
7 #if !defined(typeof)
8 #if defined(__cplusplus) || __STDC_VERSION__ < 202311
9 #define typeof __typeof__
10 #endif
11 #endif
12
13 #ifdef GB_INTERNAL
14
15 // "Keyword" definitions
16 #define likely(x) GB_likely(x)
17 #define unlikely(x) GB_unlikely(x)
18 #define inline_const GB_inline_const
19
20 #if !defined(MIN)
21 #define MIN(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
22 #endif
23
24 #if !defined(MAX)
25 #define MAX(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
26 #endif
27
28 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
29 #define __builtin_bswap16(x) ({ typeof(x) _x = (x); _x >> 8 | _x << 8; })
30 #endif
31
32 #define internal __attribute__((visibility("hidden")))
33 #define noinline __attribute__((noinline))
34
35 #if __clang__
36 #define unrolled _Pragma("unroll")
37 #define nounroll _Pragma("clang loop unroll(disable)")
38 #elif __GNUC__ >= 8
39 #define unrolled _Pragma("GCC unroll 8")
40 #define nounroll _Pragma("GCC unroll 0")
41 #else
42 #define unrolled
43 #define nounroll
44 #endif
45
46 #define unreachable() __builtin_unreachable();
47 #define nodefault default: unreachable()
48
49 #ifdef GB_BIG_ENDIAN
50 #define LE16(x) __builtin_bswap16(x)
51 #define LE32(x) __builtin_bswap32(x)
52 #define LE64(x) __builtin_bswap64(x)
53 #define BE16(x) (x)
54 #define BE32(x) (x)
55 #define BE64(x) (x)
56 #else
57 #define LE16(x) (x)
58 #define LE32(x) (x)
59 #define LE64(x) (x)
60 #define BE16(x) __builtin_bswap16(x)
61 #define BE32(x) __builtin_bswap32(x)
62 #define BE64(x) __builtin_bswap64(x)
63 #endif
64 #endif
65
66 struct GB_gameboy_s;
67 typedef struct GB_gameboy_s GB_gameboy_t;
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.