ppsspp/Common/CommonFuncs.h

92 lines
2.3 KiB
C
Raw Normal View History

2012-11-01 16:19:01 +01:00
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
2012-11-01 16:19:01 +01:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#pragma once
2012-11-01 16:19:01 +01:00
2014-09-06 10:47:25 +02:00
#include "base/compat.h"
2014-12-06 12:19:23 +01:00
#include "CommonTypes.h"
2012-11-01 16:19:01 +01:00
template <bool> struct CompileTimeAssert;
template<> struct CompileTimeAssert<true> {};
2016-05-08 22:27:20 +02:00
#if !defined(_WIN32)
2012-11-01 16:19:01 +01:00
#include <unistd.h>
2012-11-01 16:19:01 +01:00
#include <errno.h>
2014-11-11 22:55:49 +10:00
#if defined(_M_IX86) || defined(_M_X86)
2016-05-08 22:27:20 +02:00
#define Crash() {asm ("int $3");}
2012-11-01 16:19:01 +01:00
#else
2016-05-08 22:32:08 +02:00
#include <signal.h>
2016-05-08 22:27:20 +02:00
#define Crash() {kill(getpid(), SIGINT);}
2012-11-01 16:19:01 +01:00
#endif
2014-09-06 10:47:25 +02:00
2012-11-01 16:19:01 +01:00
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
2013-04-04 19:16:15 +02:00
inline u32 __rotl(u32 x, int shift) {
2016-05-08 22:27:20 +02:00
shift &= 31;
if (!shift) return x;
return (x << shift) | (x >> (32 - shift));
2012-11-01 16:19:01 +01:00
}
2013-04-04 19:16:15 +02:00
inline u64 __rotl64(u64 x, unsigned int shift){
2012-11-01 16:19:01 +01:00
unsigned int n = shift % 64;
return (x << n) | (x >> (64 - n));
}
2013-04-04 19:16:15 +02:00
inline u32 __rotr(u32 x, int shift) {
2012-11-01 16:19:01 +01:00
shift &= 31;
if (!shift) return x;
return (x >> shift) | (x << (32 - shift));
}
2013-04-04 19:16:15 +02:00
inline u64 __rotr64(u64 x, unsigned int shift){
2012-11-01 16:19:01 +01:00
unsigned int n = shift % 64;
return (x >> n) | (x << (64 - n));
}
#else // WIN32
2014-09-06 10:47:25 +02:00
2012-11-01 16:19:01 +01:00
// Function Cross-Compatibility
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define unlink _unlink
2013-04-05 00:29:29 -07:00
#define __rotl _rotl
2013-04-05 10:16:19 -07:00
#define __rotl64 _rotl64
#define __rotr _rotr
#define __rotr64 _rotr64
2012-11-01 16:19:01 +01:00
// 64 bit offsets for windows
#define fseeko _fseeki64
#define ftello _ftelli64
#define atoll _atoi64
#define fileno _fileno
#if _M_IX86
#define Crash() {__asm int 3}
#else
2017-02-25 00:25:46 +01:00
#define Crash() {__debugbreak();}
2012-11-01 16:19:01 +01:00
#endif // M_IX86
#endif // WIN32 ndef
// Generic function to get last error message.
// Call directly after the command or use the error num.
// This function might change the error code.
// Defined in Misc.cpp.
const char *GetLastErrorMsg();
const char *GetStringErrorMsg(int errCode);
2012-11-01 16:19:01 +01:00