Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/nall/intrinsics.hpp
2 views
1
#ifndef NALL_INTRINSICS_HPP
2
#define NALL_INTRINSICS_HPP
3
4
struct Intrinsics {
5
enum class Compiler : unsigned { GCC, VisualC, Unknown };
6
enum class Platform : unsigned { X, OSX, Windows, Unknown };
7
enum class Endian : unsigned { LSB, MSB, Unknown };
8
9
static inline Compiler compiler();
10
static inline Platform platform();
11
static inline Endian endian();
12
};
13
14
/* Compiler detection */
15
16
#if defined(__GNUC__)
17
#define COMPILER_GCC
18
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::GCC; }
19
#elif defined(_MSC_VER)
20
#define COMPILER_VISUALC
21
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::VisualC; }
22
#else
23
#warning "unable to detect compiler"
24
#define COMPILER_UNKNOWN
25
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::Unknown; }
26
#endif
27
28
/* Platform detection */
29
30
#if defined(linux) || defined(__sun__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
31
#define PLATFORM_X
32
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::X; }
33
#elif defined(__APPLE__)
34
#define PLATFORM_OSX
35
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::OSX; }
36
#elif defined(_WIN32)
37
#define PLATFORM_WINDOWS
38
#define PLATFORM_WIN
39
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; }
40
#else
41
#warning "unable to detect platform"
42
#define PLATFORM_UNKNOWN
43
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Unknown; }
44
#endif
45
46
/* Endian detection */
47
48
#if defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64)
49
#define ENDIAN_LSB
50
#define ARCH_LSB
51
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::LSB; }
52
#elif defined(__powerpc__) || defined(_M_PPC) || defined(__BIG_ENDIAN__)
53
#define ENDIAN_MSB
54
#define ARCH_MSB
55
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::MSB; }
56
#else
57
#warning "unable to detect endian"
58
#define ENDIAN_UNKNOWN
59
#define ARCH_UNKNOWN
60
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::Unknown; }
61
#endif
62
63
#endif
64
65