~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Common/CommonFuncs.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "base/compat.h"
 
21
#include "CommonTypes.h"
 
22
 
 
23
template <bool> struct CompileTimeAssert;
 
24
template<> struct CompileTimeAssert<true> {};
 
25
 
 
26
#if !defined(_WIN32)
 
27
 
 
28
#include <unistd.h>
 
29
#include <errno.h>
 
30
 
 
31
#if defined(_M_IX86) || defined(_M_X86)
 
32
#define Crash() {asm ("int $3");}
 
33
#else
 
34
#include <signal.h>
 
35
#define Crash() {kill(getpid(), SIGINT);}
 
36
#endif
 
37
 
 
38
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
 
39
 
 
40
inline u32 __rotl(u32 x, int shift) {
 
41
        shift &= 31;
 
42
        if (!shift) return x;
 
43
        return (x << shift) | (x >> (32 - shift));
 
44
}
 
45
 
 
46
inline u64 __rotl64(u64 x, unsigned int shift){
 
47
        unsigned int n = shift % 64;
 
48
        return (x << n) | (x >> (64 - n));
 
49
}
 
50
 
 
51
inline u32 __rotr(u32 x, int shift) {
 
52
    shift &= 31;
 
53
    if (!shift) return x;
 
54
    return (x >> shift) | (x << (32 - shift));
 
55
}
 
56
 
 
57
inline u64 __rotr64(u64 x, unsigned int shift){
 
58
        unsigned int n = shift % 64;
 
59
        return (x >> n) | (x << (64 - n));
 
60
}
 
61
 
 
62
#else // WIN32
 
63
 
 
64
// Function Cross-Compatibility
 
65
        #define strcasecmp _stricmp
 
66
        #define strncasecmp _strnicmp
 
67
        #define unlink _unlink
 
68
        #define __rotl _rotl
 
69
        #define __rotl64 _rotl64
 
70
        #define __rotr _rotr
 
71
        #define __rotr64 _rotr64
 
72
 
 
73
// 64 bit offsets for windows
 
74
        #define fseeko _fseeki64
 
75
        #define ftello _ftelli64
 
76
        #define atoll _atoi64
 
77
        #define fileno _fileno
 
78
#ifndef _XBOX
 
79
        #if _M_IX86
 
80
                #define Crash() {__asm int 3}
 
81
        #else
 
82
extern "C" {
 
83
        __declspec(dllimport) void __stdcall DebugBreak(void);
 
84
}
 
85
                #define Crash() {DebugBreak();}
 
86
        #endif // M_IX86
 
87
#else
 
88
        #define Crash() {DebugBreak();}
 
89
#endif // _XBOX ndef
 
90
#endif // WIN32 ndef
 
91
 
 
92
// Generic function to get last error message.
 
93
// Call directly after the command or use the error num.
 
94
// This function might change the error code.
 
95
// Defined in Misc.cpp.
 
96
const char *GetLastErrorMsg();
 
97
const char *GetStringErrorMsg(int errCode);
 
98