CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/CommonFuncs.h
Views: 1401
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
#else
45
#include <signal.h>
46
#define Crash() {kill(getpid(), SIGINT);}
47
#endif
48
49
inline u32 __rotl(u32 x, int shift) {
50
shift &= 31;
51
if (!shift) return x;
52
return (x << shift) | (x >> (32 - shift));
53
}
54
55
inline u64 __rotl64(u64 x, unsigned int shift){
56
unsigned int n = shift % 64;
57
return (x << n) | (x >> (64 - n));
58
}
59
60
inline u32 __rotr(u32 x, int shift) {
61
shift &= 31;
62
if (!shift) return x;
63
return (x >> shift) | (x << (32 - shift));
64
}
65
66
inline u64 __rotr64(u64 x, unsigned int shift){
67
unsigned int n = shift % 64;
68
return (x >> n) | (x << (64 - n));
69
}
70
71
#else // WIN32
72
73
// Function Cross-Compatibility
74
#ifndef __MINGW32__
75
#define strcasecmp _stricmp
76
#define strncasecmp _strnicmp
77
#endif
78
79
#define unlink _unlink
80
#define __rotl _rotl
81
#define __rotl64 _rotl64
82
#define __rotr _rotr
83
#define __rotr64 _rotr64
84
85
// 64 bit offsets for windows
86
#ifndef __MINGW32__
87
#define fseeko _fseeki64
88
#define ftello _ftelli64
89
#define atoll _atoi64
90
#endif
91
#define Crash() {__debugbreak();}
92
#endif // WIN32 ndef
93
94