Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/CommonFuncs.h
3185 views
1
// Copyright (C) 2003 Dolphin Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official SVN repository and contact information can be found at
16
// http://code.google.com/p/dolphin-emu/
17
18
#pragma once
19
20
#include "ppsspp_config.h"
21
22
#include "CommonTypes.h"
23
24
#ifndef ARRAY_SIZE
25
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
26
#endif
27
28
#if !defined(_WIN32)
29
30
#include <unistd.h>
31
#include <errno.h>
32
33
#if (PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)) && !defined(__EMSCRIPTEN__)
34
#define Crash() {asm ("int $3");}
35
#elif PPSSPP_PLATFORM(SWITCH)
36
// TODO: Implement Crash() for Switch, lets not use breakpoint for the time being
37
#define Crash() {*((volatile u32 *)0x0) = 0xDEADC0DE;}
38
#elif PPSSPP_ARCH(ARM)
39
#define Crash() {asm ("bkpt #0");}
40
#elif PPSSPP_ARCH(ARM64)
41
#define Crash() {asm ("brk #0");}
42
#elif PPSSPP_ARCH(RISCV64)
43
#define Crash() {asm ("ebreak");}
44
#elif PPSSPP_ARCH(LOONGARCH64)
45
#define Crash() {asm ("break 0");}
46
#else
47
#include <signal.h>
48
#define Crash() {kill(getpid(), SIGINT);}
49
#endif
50
51
#else // WIN32
52
53
// Function Cross-Compatibility
54
#ifndef __MINGW32__
55
#define strcasecmp _stricmp
56
#define strncasecmp _strnicmp
57
#endif
58
59
#ifndef __MINGW32__
60
#define unlink _unlink
61
#endif
62
63
// 64 bit offsets for windows
64
#ifndef __MINGW32__
65
#define fseeko _fseeki64
66
#define ftello _ftelli64
67
#define atoll _atoi64
68
#endif
69
#define Crash() {__debugbreak();}
70
#endif // WIN32 ndef
71
72
#if defined(_MSC_VER)
73
#include <cstdlib>
74
#elif (PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64))
75
#include <x86intrin.h>
76
#endif
77
78
inline u32 __rotl(u32 x, int shift) {
79
#if defined(_MSC_VER)
80
return _rotl(x, shift);
81
#elif (PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64))
82
return __rold(x, shift);
83
#else
84
shift &= 31;
85
if (!shift) return x;
86
return (x << shift) | (x >> (32 - shift));
87
#endif
88
}
89
90
inline u64 __rotl64(u64 x, unsigned int shift){
91
#if defined(_MSC_VER)
92
return _rotl64(x, shift);
93
#elif PPSSPP_ARCH(AMD64)
94
return __rolq(x, shift);
95
#else
96
unsigned int n = shift % 64;
97
return (x << n) | (x >> (64 - n));
98
#endif
99
}
100
101
inline u32 __rotr(u32 x, int shift) {
102
#if defined(_MSC_VER)
103
return _rotr(x, shift);
104
#elif (PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64))
105
return __rord(x, shift);
106
#else
107
shift &= 31;
108
if (!shift) return x;
109
return (x >> shift) | (x << (32 - shift));
110
#endif
111
}
112
113
inline u64 __rotr64(u64 x, unsigned int shift){
114
#if defined(_MSC_VER)
115
return _rotr64(x, shift);
116
#elif PPSSPP_ARCH(AMD64)
117
return __rorq(x, shift);
118
#else
119
unsigned int n = shift % 64;
120
return (x >> n) | (x << (64 - n));
121
#endif
122
}
123
124