mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-23 19:29:05 +02:00
commit
cfb05e66ad
47 files changed
+5
-3092
No files matched your search
+1
-12
@@ -247,22 +247,12 @@ add_library(Common STATIC
|
||||
Common/ConsoleListener.h
|
||||
Common/Crypto/aes_cbc.cpp
|
||||
Common/Crypto/aes_core.cpp
|
||||
Common/Crypto/bn.cpp
|
||||
Common/Crypto/ec.cpp
|
||||
Common/Crypto/md5.cpp
|
||||
Common/Crypto/md5.h
|
||||
Common/Crypto/sha1.cpp
|
||||
Common/Crypto/sha1.h
|
||||
Common/ExtendedTrace.cpp
|
||||
Common/ExtendedTrace.h
|
||||
Common/FPURoundModeGeneric.cpp
|
||||
# Common/FPURoundModeX86.cpp
|
||||
Common/FileSearch.cpp
|
||||
Common/FileSearch.h
|
||||
Common/FileUtil.cpp
|
||||
Common/FileUtil.h
|
||||
Common/Hash.cpp
|
||||
Common/Hash.h
|
||||
Common/KeyMap.cpp
|
||||
Common/KeyMap.h
|
||||
Common/LogManager.cpp
|
||||
@@ -283,8 +273,7 @@ add_library(Common STATIC
|
||||
Common/ThreadPools.cpp
|
||||
Common/ThreadPools.h
|
||||
Common/Timer.cpp
|
||||
Common/Timer.h
|
||||
Common/Version.cpp)
|
||||
Common/Timer.h)
|
||||
include_directories(Common)
|
||||
setup_target_project(Common Common)
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "x64Emitter.h"
|
||||
#include "ABI.h"
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "ArmEmitter.h"
|
||||
#include "ArmABI.h"
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "ArmEmitter.h"
|
||||
#include "CPUDetect.h"
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "Common.h"
|
||||
#include "MemoryUtil.h"
|
||||
#include "Thunk.h"
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
// - Serialization code for anything complex has to be manually written.
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#ifndef __SYMBIAN32__
|
||||
|
||||
@@ -179,31 +179,21 @@
|
||||
<ClInclude Include="CPUDetect.h" />
|
||||
<ClInclude Include="Crypto\md5.h" />
|
||||
<ClInclude Include="Crypto\sha1.h" />
|
||||
<ClInclude Include="DebugInterface.h" />
|
||||
<ClInclude Include="ExtendedTrace.h" />
|
||||
<ClInclude Include="FifoQueue.h" />
|
||||
<ClInclude Include="FileSearch.h" />
|
||||
<ClInclude Include="FileUtil.h" />
|
||||
<ClInclude Include="FixedSizeQueue.h" />
|
||||
<ClInclude Include="FixedSizeUnorderedSet.h" />
|
||||
<ClInclude Include="Hash.h" />
|
||||
<ClInclude Include="KeyMap.h" />
|
||||
<ClInclude Include="LinearDiskCache.h" />
|
||||
<ClInclude Include="Log.h" />
|
||||
<ClInclude Include="LogManager.h" />
|
||||
<ClInclude Include="MathUtil.h" />
|
||||
<ClInclude Include="MemArena.h" />
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
<ClInclude Include="MsgHandler.h" />
|
||||
<ClInclude Include="scmrev.h" />
|
||||
<ClInclude Include="Setup.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="StdConditionVariable.h" />
|
||||
<ClInclude Include="StdMutex.h" />
|
||||
<ClInclude Include="StdThread.h" />
|
||||
<ClInclude Include="StringUtils.h" />
|
||||
<ClInclude Include="Swap.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="Thread.h" />
|
||||
<ClInclude Include="ThreadPools.h" />
|
||||
<ClInclude Include="Thunk.h" />
|
||||
@@ -224,10 +214,7 @@
|
||||
<ClCompile Include="CPUDetect.cpp" />
|
||||
<ClCompile Include="Crypto\md5.cpp" />
|
||||
<ClCompile Include="Crypto\sha1.cpp" />
|
||||
<ClCompile Include="ExtendedTrace.cpp" />
|
||||
<ClCompile Include="FileSearch.cpp" />
|
||||
<ClCompile Include="FileUtil.cpp" />
|
||||
<ClCompile Include="Hash.cpp" />
|
||||
<ClCompile Include="KeyMap.cpp" />
|
||||
<ClCompile Include="LogManager.cpp" />
|
||||
<ClCompile Include="MathUtil.cpp" />
|
||||
@@ -246,7 +233,6 @@
|
||||
<ClCompile Include="ThreadPools.cpp" />
|
||||
<ClCompile Include="Thunk.cpp" />
|
||||
<ClCompile Include="Timer.cpp" />
|
||||
<ClCompile Include="Version.cpp" />
|
||||
<ClCompile Include="x64Analyzer.cpp" />
|
||||
<ClCompile Include="x64Emitter.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="ABI.h" />
|
||||
<ClInclude Include="Atomics.h" />
|
||||
@@ -14,22 +13,14 @@
|
||||
<ClInclude Include="CommonTypes.h" />
|
||||
<ClInclude Include="ConsoleListener.h" />
|
||||
<ClInclude Include="CPUDetect.h" />
|
||||
<ClInclude Include="DebugInterface.h" />
|
||||
<ClInclude Include="ExtendedTrace.h" />
|
||||
<ClInclude Include="FifoQueue.h" />
|
||||
<ClInclude Include="FileSearch.h" />
|
||||
<ClInclude Include="FileUtil.h" />
|
||||
<ClInclude Include="FixedSizeQueue.h" />
|
||||
<ClInclude Include="Hash.h" />
|
||||
<ClInclude Include="LinearDiskCache.h" />
|
||||
<ClInclude Include="Log.h" />
|
||||
<ClInclude Include="LogManager.h" />
|
||||
<ClInclude Include="MathUtil.h" />
|
||||
<ClInclude Include="MemArena.h" />
|
||||
<ClInclude Include="MemoryUtil.h" />
|
||||
<ClInclude Include="MsgHandler.h" />
|
||||
<ClInclude Include="scmrev.h" />
|
||||
<ClInclude Include="Setup.h" />
|
||||
<ClInclude Include="StdConditionVariable.h" />
|
||||
<ClInclude Include="StdMutex.h" />
|
||||
<ClInclude Include="StdThread.h" />
|
||||
@@ -40,7 +31,6 @@
|
||||
<ClInclude Include="x64Analyzer.h" />
|
||||
<ClInclude Include="x64Emitter.h" />
|
||||
<ClInclude Include="ArmEmitter.h" />
|
||||
<ClInclude Include="FixedSizeUnorderedSet.h" />
|
||||
<ClInclude Include="ThreadPools.h" />
|
||||
<ClInclude Include="Crypto\md5.h">
|
||||
<Filter>Crypto</Filter>
|
||||
@@ -57,10 +47,7 @@
|
||||
<ClCompile Include="ABI.cpp" />
|
||||
<ClCompile Include="ConsoleListener.cpp" />
|
||||
<ClCompile Include="CPUDetect.cpp" />
|
||||
<ClCompile Include="ExtendedTrace.cpp" />
|
||||
<ClCompile Include="FileSearch.cpp" />
|
||||
<ClCompile Include="FileUtil.cpp" />
|
||||
<ClCompile Include="Hash.cpp" />
|
||||
<ClCompile Include="LogManager.cpp" />
|
||||
<ClCompile Include="MathUtil.cpp" />
|
||||
<ClCompile Include="MemArena.cpp" />
|
||||
@@ -71,7 +58,6 @@
|
||||
<ClCompile Include="Thread.cpp" />
|
||||
<ClCompile Include="Thunk.cpp" />
|
||||
<ClCompile Include="Timer.cpp" />
|
||||
<ClCompile Include="Version.cpp" />
|
||||
<ClCompile Include="x64Analyzer.cpp" />
|
||||
<ClCompile Include="x64Emitter.cpp" />
|
||||
<ClCompile Include="ArmEmitter.cpp" />
|
||||
|
||||
@@ -17,12 +17,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SLEEP(x) Sleep(x)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define SLEEP(x) usleep(x*1000)
|
||||
#endif
|
||||
|
||||
#if defined(IOS) || defined(MIPS)
|
||||
#include <signal.h>
|
||||
@@ -31,13 +25,6 @@
|
||||
template <bool> struct CompileTimeAssert;
|
||||
template<> struct CompileTimeAssert<true> {};
|
||||
|
||||
#define b2(x) ( (x) | ( (x) >> 1) )
|
||||
#define b4(x) ( b2(x) | ( b2(x) >> 2) )
|
||||
#define b8(x) ( b4(x) | ( b4(x) >> 4) )
|
||||
#define b16(x) ( b8(x) | ( b8(x) >> 8) )
|
||||
#define b32(x) (b16(x) | (b16(x) >>16) )
|
||||
#define ROUND_UP_POW2(x) (b32(x - 1) + 1)
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
+1
-38
@@ -66,53 +66,16 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Dirs in both User and Sys
|
||||
#define EUR_DIR "EUR"
|
||||
#define USA_DIR "USA"
|
||||
#define JAP_DIR "JAP"
|
||||
|
||||
// Subdirs in the User dir returned by GetUserPath(D_USER_IDX)
|
||||
#define GC_USER_DIR "GC"
|
||||
#define WII_USER_DIR "Wii"
|
||||
#define CONFIG_DIR "Config"
|
||||
#define GAMECONFIG_DIR "GameConfig"
|
||||
#define MAPS_DIR "Maps"
|
||||
#define CACHE_DIR "Cache"
|
||||
#define SHADERCACHE_DIR "ShaderCache"
|
||||
#define STATESAVES_DIR "StateSaves"
|
||||
#define SCREENSHOTS_DIR "ScreenShots"
|
||||
#define OPENCL_DIR "OpenCL"
|
||||
#define LOAD_DIR "Load"
|
||||
#define HIRES_TEXTURES_DIR LOAD_DIR DIR_SEP "Textures"
|
||||
#define DUMP_DIR "Dump"
|
||||
#define DUMP_TEXTURES_DIR DUMP_DIR DIR_SEP "Textures"
|
||||
#define DUMP_FRAMES_DIR DUMP_DIR DIR_SEP "Frames"
|
||||
#define DUMP_AUDIO_DIR DUMP_DIR DIR_SEP "Audio"
|
||||
#define DUMP_DSP_DIR DUMP_DIR DIR_SEP "DSP"
|
||||
#define SCREENSHOTS_DIR "ScreenShots"
|
||||
#define LOGS_DIR "Logs"
|
||||
#define MAIL_LOGS_DIR LOGS_DIR DIR_SEP "Mail"
|
||||
#define SHADERS_DIR "Shaders"
|
||||
#define WII_SYSCONF_DIR "shared2" DIR_SEP "sys"
|
||||
|
||||
// Filenames
|
||||
// Files in the directory returned by GetUserPath(D_CONFIG_IDX)
|
||||
#define CONFIG_FILE "ppsspp.ini"
|
||||
#define LOGGER_CONFIG "Logger.ini"
|
||||
|
||||
// Files in the directory returned by GetUserPath(D_LOGS_IDX)
|
||||
#define MAIN_LOG "ppsspp.log"
|
||||
|
||||
// Sys files
|
||||
#define TOTALDB "totaldb.dsy"
|
||||
|
||||
#define FONT_ANSI "font_ansi.bin"
|
||||
#define FONT_SJIS "font_sjis.bin"
|
||||
|
||||
#define DSP_IROM "dsp_rom.bin"
|
||||
#define DSP_COEF "dsp_coef.bin"
|
||||
|
||||
// Subdirs in Sys
|
||||
#define GC_SYS_DIR "GC"
|
||||
#define WII_SYS_DIR "Wii"
|
||||
|
||||
#endif // _COMMON_PATHS_H_
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#include <algorithm> // min
|
||||
#include <string> // System: To be able to add strings with "+"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#ifdef _WIN32
|
||||
#include "CommonWindows.h"
|
||||
@@ -30,7 +29,6 @@
|
||||
#include "thread/threadutil.h"
|
||||
#include "util/text/utf8.h"
|
||||
#include "Common.h"
|
||||
#include "LogManager.h" // Common
|
||||
#include "ConsoleListener.h" // Common
|
||||
#include "Atomics.h"
|
||||
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
// Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
|
||||
// Licensed under the terms of the GNU GPL, version 2
|
||||
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../Common.h"
|
||||
#include "tools.h"
|
||||
|
||||
/*static void bn_print(char *name, u8 *a, u32 n)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
printf("%s = ", name);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
printf("%02x", a[i]);
|
||||
|
||||
printf("\n");
|
||||
}*/
|
||||
|
||||
static void bn_zero(u8 *d, u32 n)
|
||||
{
|
||||
memset(d, 0, n);
|
||||
}
|
||||
|
||||
static void bn_copy(u8 *d, u8 *a, u32 n)
|
||||
{
|
||||
memcpy(d, a, n);
|
||||
}
|
||||
|
||||
int bn_compare(u8 *a, u8 *b, u32 n)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (a[i] < b[i])
|
||||
return -1;
|
||||
if (a[i] > b[i])
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bn_sub_modulus(u8 *a, u8 *N, u32 n)
|
||||
{
|
||||
u32 i;
|
||||
u32 dig;
|
||||
u8 c;
|
||||
|
||||
c = 0;
|
||||
for (i = n - 1; i < n; i--) {
|
||||
dig = N[i] + c;
|
||||
c = (a[i] < dig);
|
||||
a[i] -= dig;
|
||||
}
|
||||
}
|
||||
|
||||
void bn_add(u8 *d, u8 *a, u8 *b, u8 *N, u32 n)
|
||||
{
|
||||
u32 i;
|
||||
u32 dig;
|
||||
u8 c;
|
||||
|
||||
c = 0;
|
||||
for (i = n - 1; i < n; i--) {
|
||||
dig = a[i] + b[i] + c;
|
||||
c = (dig >= 0x100);
|
||||
d[i] = dig;
|
||||
}
|
||||
|
||||
if (c)
|
||||
bn_sub_modulus(d, N, n);
|
||||
|
||||
if (bn_compare(d, N, n) >= 0)
|
||||
bn_sub_modulus(d, N, n);
|
||||
}
|
||||
|
||||
void bn_mul(u8 *d, u8 *a, u8 *b, u8 *N, u32 n)
|
||||
{
|
||||
u32 i;
|
||||
u8 mask;
|
||||
|
||||
bn_zero(d, n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
for (mask = 0x80; mask != 0; mask >>= 1) {
|
||||
bn_add(d, d, d, N, n);
|
||||
if ((a[i] & mask) != 0)
|
||||
bn_add(d, d, b, N, n);
|
||||
}
|
||||
}
|
||||
|
||||
void bn_exp(u8 *d, u8 *a, u8 *N, u32 n, u8 *e, u32 en)
|
||||
{
|
||||
u8 t[512];
|
||||
u32 i;
|
||||
u8 mask;
|
||||
|
||||
bn_zero(d, n);
|
||||
d[n-1] = 1;
|
||||
for (i = 0; i < en; i++)
|
||||
for (mask = 0x80; mask != 0; mask >>= 1) {
|
||||
bn_mul(t, d, d, N, n);
|
||||
if ((e[i] & mask) != 0)
|
||||
bn_mul(d, t, a, N, n);
|
||||
else
|
||||
bn_copy(d, t, n);
|
||||
}
|
||||
}
|
||||
|
||||
// only for prime N -- stupid but lazy, see if I care
|
||||
void bn_inv(u8 *d, u8 *a, u8 *N, u32 n)
|
||||
{
|
||||
u8 t[512], s[512];
|
||||
|
||||
bn_copy(t, N, n);
|
||||
bn_zero(s, n);
|
||||
s[n-1] = 2;
|
||||
bn_sub_modulus(t, s, n);
|
||||
bn_exp(d, a, N, n, t, n);
|
||||
}
|
||||
@@ -1,400 +0,0 @@
|
||||
// Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
|
||||
// Licensed under the terms of the GNU GPL, version 2
|
||||
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "tools.h"
|
||||
// y**2 + x*y = x**3 + x + b
|
||||
/*
|
||||
static u8 ec_b[30] =
|
||||
{0x00,0x66,0x64,0x7e,0xde,0x6c,0x33,0x2c,0x7f,0x8c,0x09,0x23,0xbb,0x58,0x21
|
||||
,0x3b,0x33,0x3b,0x20,0xe9,0xce,0x42,0x81,0xfe,0x11,0x5f,0x7d,0x8f,0x90,0xad};
|
||||
*/
|
||||
|
||||
// order of the addition group of points
|
||||
static u8 ec_N[30] =
|
||||
{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
,0x13,0xe9,0x74,0xe7,0x2f,0x8a,0x69,0x22,0x03,0x1d,0x26,0x03,0xcf,0xe0,0xd7};
|
||||
|
||||
// base point
|
||||
static u8 ec_G[60] =
|
||||
{0x00,0xfa,0xc9,0xdf,0xcb,0xac,0x83,0x13,0xbb,0x21,0x39,0xf1,0xbb,0x75,0x5f
|
||||
,0xef,0x65,0xbc,0x39,0x1f,0x8b,0x36,0xf8,0xf8,0xeb,0x73,0x71,0xfd,0x55,0x8b
|
||||
,0x01,0x00,0x6a,0x08,0xa4,0x19,0x03,0x35,0x06,0x78,0xe5,0x85,0x28,0xbe,0xbf
|
||||
,0x8a,0x0b,0xef,0xf8,0x67,0xa7,0xca,0x36,0x71,0x6f,0x7e,0x01,0xf8,0x10,0x52};
|
||||
|
||||
/*static void elt_print(char *name, u8 *a)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
printf("%s = ", name);
|
||||
|
||||
for (i = 0; i < 30; i++)
|
||||
printf("%02x", a[i]);
|
||||
|
||||
printf("\n");
|
||||
}*/
|
||||
|
||||
static void elt_copy(u8 *d, u8 *a)
|
||||
{
|
||||
memcpy(d, a, 30);
|
||||
}
|
||||
|
||||
static void elt_zero(u8 *d)
|
||||
{
|
||||
memset(d, 0, 30);
|
||||
}
|
||||
|
||||
static int elt_is_zero(u8 *d)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < 30; i++)
|
||||
if (d[i] != 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void elt_add(u8 *d, u8 *a, u8 *b)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < 30; i++)
|
||||
d[i] = a[i] ^ b[i];
|
||||
}
|
||||
|
||||
static void elt_mul_x(u8 *d, u8 *a)
|
||||
{
|
||||
u8 carry, x, y;
|
||||
u32 i;
|
||||
|
||||
carry = a[0] & 1;
|
||||
|
||||
x = 0;
|
||||
for (i = 0; i < 29; i++) {
|
||||
y = a[i + 1];
|
||||
d[i] = x ^ (y >> 7);
|
||||
x = y << 1;
|
||||
}
|
||||
d[29] = x ^ carry;
|
||||
|
||||
d[20] ^= carry << 2;
|
||||
}
|
||||
|
||||
static void elt_mul(u8 *d, u8 *a, u8 *b)
|
||||
{
|
||||
u32 i, n;
|
||||
u8 mask;
|
||||
|
||||
elt_zero(d);
|
||||
|
||||
i = 0;
|
||||
mask = 1;
|
||||
for (n = 0; n < 233; n++) {
|
||||
elt_mul_x(d, d);
|
||||
|
||||
if ((a[i] & mask) != 0)
|
||||
elt_add(d, d, b);
|
||||
|
||||
mask >>= 1;
|
||||
if (mask == 0) {
|
||||
mask = 0x80;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const u8 square[16] =
|
||||
{0x00,0x01,0x04,0x05,0x10,0x11,0x14,0x15,0x40,0x41,0x44,0x45,0x50,0x51,0x54,0x55};
|
||||
|
||||
static void elt_square_to_wide(u8 *d, u8 *a)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
d[2*i] = square[a[i] >> 4];
|
||||
d[2*i + 1] = square[a[i] & 15];
|
||||
}
|
||||
}
|
||||
|
||||
static void wide_reduce(u8 *d)
|
||||
{
|
||||
u32 i;
|
||||
u8 x;
|
||||
|
||||
for (i = 0; i < 30; i++) {
|
||||
x = d[i];
|
||||
|
||||
d[i + 19] ^= x >> 7;
|
||||
d[i + 20] ^= x << 1;
|
||||
|
||||
d[i + 29] ^= x >> 1;
|
||||
d[i + 30] ^= x << 7;
|
||||
}
|
||||
|
||||
x = d[30] & ~1;
|
||||
|
||||
d[49] ^= x >> 7;
|
||||
d[50] ^= x << 1;
|
||||
|
||||
d[59] ^= x >> 1;
|
||||
|
||||
d[30] &= 1;
|
||||
}
|
||||
|
||||
static void elt_square(u8 *d, u8 *a)
|
||||
{
|
||||
u8 wide[60];
|
||||
|
||||
elt_square_to_wide(wide, a);
|
||||
wide_reduce(wide);
|
||||
|
||||
elt_copy(d, wide + 30);
|
||||
}
|
||||
|
||||
static void itoh_tsujii(u8 *d, u8 *a, u8 *b, u32 j)
|
||||
{
|
||||
u8 t[30];
|
||||
|
||||
elt_copy(t, a);
|
||||
while (j--) {
|
||||
elt_square(d, t);
|
||||
elt_copy(t, d);
|
||||
}
|
||||
|
||||
elt_mul(d, t, b);
|
||||
}
|
||||
|
||||
static void elt_inv(u8 *d, u8 *a)
|
||||
{
|
||||
u8 t[30];
|
||||
u8 s[30];
|
||||
|
||||
itoh_tsujii(t, a, a, 1);
|
||||
itoh_tsujii(s, t, a, 1);
|
||||
itoh_tsujii(t, s, s, 3);
|
||||
itoh_tsujii(s, t, a, 1);
|
||||
itoh_tsujii(t, s, s, 7);
|
||||
itoh_tsujii(s, t, t, 14);
|
||||
itoh_tsujii(t, s, a, 1);
|
||||
itoh_tsujii(s, t, t, 29);
|
||||
itoh_tsujii(t, s, s, 58);
|
||||
itoh_tsujii(s, t, t, 116);
|
||||
elt_square(d, s);
|
||||
}
|
||||
|
||||
/*static int point_is_on_curve(u8 *p)
|
||||
{
|
||||
u8 s[30], t[30];
|
||||
u8 *x, *y;
|
||||
|
||||
x = p;
|
||||
y = p + 30;
|
||||
|
||||
elt_square(t, x);
|
||||
elt_mul(s, t, x);
|
||||
|
||||
elt_add(s, s, t);
|
||||
|
||||
elt_square(t, y);
|
||||
elt_add(s, s, t);
|
||||
|
||||
elt_mul(t, x, y);
|
||||
elt_add(s, s, t);
|
||||
|
||||
elt_add(s, s, ec_b);
|
||||
|
||||
return elt_is_zero(s);
|
||||
}
|
||||
*/
|
||||
static int point_is_zero(u8 *p)
|
||||
{
|
||||
return elt_is_zero(p) && elt_is_zero(p + 30);
|
||||
}
|
||||
|
||||
static void point_double(u8 *r, u8 *p)
|
||||
{
|
||||
u8 s[30], t[30];
|
||||
u8 *px, *py, *rx, *ry;
|
||||
|
||||
px = p;
|
||||
py = p + 30;
|
||||
rx = r;
|
||||
ry = r + 30;
|
||||
|
||||
if (elt_is_zero(px)) {
|
||||
elt_zero(rx);
|
||||
elt_zero(ry);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
elt_inv(t, px);
|
||||
elt_mul(s, py, t);
|
||||
elt_add(s, s, px);
|
||||
|
||||
elt_square(t, px);
|
||||
|
||||
elt_square(rx, s);
|
||||
elt_add(rx, rx, s);
|
||||
rx[29] ^= 1;
|
||||
|
||||
elt_mul(ry, s, rx);
|
||||
elt_add(ry, ry, rx);
|
||||
elt_add(ry, ry, t);
|
||||
}
|
||||
|
||||
static void point_add(u8 *r, u8 *p, u8 *q)
|
||||
{
|
||||
u8 s[30], t[30], u[30];
|
||||
u8 *px, *py, *qx, *qy, *rx, *ry;
|
||||
|
||||
px = p;
|
||||
py = p + 30;
|
||||
qx = q;
|
||||
qy = q + 30;
|
||||
rx = r;
|
||||
ry = r + 30;
|
||||
|
||||
if (point_is_zero(p)) {
|
||||
elt_copy(rx, qx);
|
||||
elt_copy(ry, qy);
|
||||
return;
|
||||
}
|
||||
|
||||
if (point_is_zero(q)) {
|
||||
elt_copy(rx, px);
|
||||
elt_copy(ry, py);
|
||||
return;
|
||||
}
|
||||
|
||||
elt_add(u, px, qx);
|
||||
|
||||
if (elt_is_zero(u)) {
|
||||
elt_add(u, py, qy);
|
||||
if (elt_is_zero(u))
|
||||
point_double(r, p);
|
||||
else {
|
||||
elt_zero(rx);
|
||||
elt_zero(ry);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
elt_inv(t, u);
|
||||
elt_add(u, py, qy);
|
||||
elt_mul(s, t, u);
|
||||
|
||||
elt_square(t, s);
|
||||
elt_add(t, t, s);
|
||||
elt_add(t, t, qx);
|
||||
t[29] ^= 1;
|
||||
|
||||
elt_mul(u, s, t);
|
||||
elt_add(s, u, py);
|
||||
elt_add(rx, t, px);
|
||||
elt_add(ry, s, rx);
|
||||
}
|
||||
|
||||
static void point_mul(u8 *d, u8 *a, u8 *b) // a is bignum
|
||||
{
|
||||
u32 i;
|
||||
u8 mask;
|
||||
|
||||
elt_zero(d);
|
||||
elt_zero(d + 30);
|
||||
|
||||
for (i = 0; i < 30; i++)
|
||||
for (mask = 0x80; mask != 0; mask >>= 1) {
|
||||
point_double(d, d);
|
||||
if ((a[i] & mask) != 0)
|
||||
point_add(d, d, b);
|
||||
}
|
||||
}
|
||||
|
||||
void silly_random(u8 * rndArea, u8 count)
|
||||
{
|
||||
u16 i;
|
||||
srand((unsigned) (time(NULL)));
|
||||
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
rndArea[i]=rand();
|
||||
}
|
||||
}
|
||||
|
||||
void generate_ecdsa(u8 *R, u8 *S, u8 *k, u8 *hash)
|
||||
{
|
||||
u8 e[30];
|
||||
u8 kk[30];
|
||||
u8 m[30];
|
||||
u8 minv[30];
|
||||
u8 mG[60];
|
||||
//FILE *fp;
|
||||
|
||||
elt_zero(e);
|
||||
memcpy(e + 10, hash, 20);
|
||||
|
||||
//Changing random number generator to a lame one...
|
||||
silly_random(m, sizeof(m));
|
||||
//fp = fopen("/dev/random", "rb");
|
||||
//if (fread(m, sizeof m, 1, fp) != 1)
|
||||
// fatal("reading random");
|
||||
//fclose(fp);
|
||||
m[0] = 0;
|
||||
|
||||
// R = (mG).x
|
||||
|
||||
point_mul(mG, m, ec_G);
|
||||
elt_copy(R, mG);
|
||||
if (bn_compare(R, ec_N, 30) >= 0)
|
||||
bn_sub_modulus(R, ec_N, 30);
|
||||
|
||||
// S = m**-1*(e + Rk) (mod N)
|
||||
|
||||
elt_copy(kk, k);
|
||||
if (bn_compare(kk, ec_N, 30) >= 0)
|
||||
bn_sub_modulus(kk, ec_N, 30);
|
||||
bn_mul(S, R, kk, ec_N, 30);
|
||||
bn_add(kk, S, e, ec_N, 30);
|
||||
bn_inv(minv, m, ec_N, 30);
|
||||
bn_mul(S, minv, kk, ec_N, 30);
|
||||
}
|
||||
|
||||
int check_ecdsa(u8 *Q, u8 *R, u8 *S, u8 *hash)
|
||||
{
|
||||
u8 Sinv[30];
|
||||
u8 e[30];
|
||||
u8 w1[30], w2[30];
|
||||
u8 r1[60], r2[60];
|
||||
|
||||
bn_inv(Sinv, S, ec_N, 30);
|
||||
|
||||
elt_zero(e);
|
||||
memcpy(e + 10, hash, 20);
|
||||
|
||||
bn_mul(w1, e, Sinv, ec_N, 30);
|
||||
bn_mul(w2, R, Sinv, ec_N, 30);
|
||||
|
||||
point_mul(r1, w1, ec_G);
|
||||
point_mul(r2, w2, Q);
|
||||
|
||||
point_add(r1, r1, r2);
|
||||
|
||||
if (bn_compare(r1, ec_N, 30) >= 0)
|
||||
bn_sub_modulus(r1, ec_N, 30);
|
||||
|
||||
return (bn_compare(r1, R, 30) == 0);
|
||||
}
|
||||
|
||||
void ec_priv_to_pub(u8 *k, u8 *Q)
|
||||
{
|
||||
point_mul(Q, k, ec_G);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef _DEBUGINTERFACE_H
|
||||
#define _DEBUGINTERFACE_H
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
class DebugInterface
|
||||
{
|
||||
protected:
|
||||
virtual ~DebugInterface() {}
|
||||
|
||||
public:
|
||||
virtual void disasm(unsigned int /*address*/, char *dest, int /*max_size*/) {strcpy(dest, "NODEBUGGER");}
|
||||
virtual void getRawMemoryString(int /*memory*/, unsigned int /*address*/, char *dest, int /*max_size*/) {strcpy(dest, "NODEBUGGER");}
|
||||
virtual int getInstructionSize(int /*instruction*/) {return 1;}
|
||||
virtual bool isAlive() {return true;}
|
||||
virtual bool isBreakpoint(unsigned int /*address*/) {return false;}
|
||||
virtual void setBreakpoint(unsigned int /*address*/){}
|
||||
virtual void clearBreakpoint(unsigned int /*address*/){}
|
||||
virtual void clearAllBreakpoints() {}
|
||||
virtual void toggleBreakpoint(unsigned int /*address*/){}
|
||||
virtual bool isMemCheck(unsigned int /*address*/) {return false;}
|
||||
virtual void toggleMemCheck(unsigned int /*address*/){}
|
||||
virtual unsigned int readMemory(unsigned int /*address*/){return 0;}
|
||||
virtual void writeExtraMemory(int /*memory*/, unsigned int /*value*/, unsigned int /*address*/) {}
|
||||
virtual unsigned int readExtraMemory(int /*memory*/, unsigned int /*address*/){return 0;}
|
||||
virtual unsigned int readInstruction(unsigned int /*address*/){return 0;}
|
||||
virtual unsigned int getPC() {return 0;}
|
||||
virtual void setPC(unsigned int /*address*/) {}
|
||||
virtual void step() {}
|
||||
virtual void runToBreakpoint() {}
|
||||
virtual void breakNow() {}
|
||||
virtual void insertBLR(unsigned int /*address*/, unsigned int) {}
|
||||
virtual void showJitResults(unsigned int /*address*/) {};
|
||||
virtual int getColor(unsigned int /*address*/){return 0xFFFFFFFF;}
|
||||
virtual std::string getDescription(unsigned int /*address*/) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,436 +0,0 @@
|
||||
// --------------------------------------------------------------------------------------
|
||||
//
|
||||
// Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
|
||||
// For companies(Austin,TX): If you would like to get my resume, send an email.
|
||||
//
|
||||
// The source is free, but if you want to use it, mention my name and e-mail address
|
||||
//
|
||||
// History:
|
||||
// 1.0 Initial version Zoltan Csizmadia
|
||||
// 1.1 WhineCube version Masken
|
||||
// 1.2 Dolphin version Masken
|
||||
//
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#include "CommonWindows.h"
|
||||
#include <stdio.h>
|
||||
#include "ExtendedTrace.h"
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <tchar.h>
|
||||
#include <ImageHlp.h>
|
||||
|
||||
#define BUFFERSIZE 0x200
|
||||
#pragma warning(disable:4996)
|
||||
|
||||
// Unicode safe char* -> TCHAR* conversion
|
||||
void PCSTR2LPTSTR( PCSTR lpszIn, LPTSTR lpszOut )
|
||||
{
|
||||
#if defined(UNICODE)||defined(_UNICODE)
|
||||
ULONG index = 0;
|
||||
PCSTR lpAct = lpszIn;
|
||||
|
||||
for( ; ; lpAct++ )
|
||||
{
|
||||
lpszOut[index++] = (TCHAR)(*lpAct);
|
||||
if ( *lpAct == 0 )
|
||||
break;
|
||||
}
|
||||
#else
|
||||
// This is trivial :)
|
||||
strcpy( lpszOut, lpszIn );
|
||||
#endif
|
||||
}
|
||||
|
||||
// Let's figure out the path for the symbol files
|
||||
// Search path= ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;" + lpszIniPath
|
||||
// Note: There is no size check for lpszSymbolPath!
|
||||
static void InitSymbolPath( PSTR lpszSymbolPath, PCSTR lpszIniPath )
|
||||
{
|
||||
CHAR lpszPath[BUFFERSIZE];
|
||||
|
||||
// Creating the default path
|
||||
// ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;"
|
||||
strcpy( lpszSymbolPath, "." );
|
||||
|
||||
// environment variable _NT_SYMBOL_PATH
|
||||
if ( GetEnvironmentVariableA( "_NT_SYMBOL_PATH", lpszPath, BUFFERSIZE ) )
|
||||
{
|
||||
strcat( lpszSymbolPath, ";" );
|
||||
strcat( lpszSymbolPath, lpszPath );
|
||||
}
|
||||
|
||||
// environment variable _NT_ALTERNATE_SYMBOL_PATH
|
||||
if ( GetEnvironmentVariableA( "_NT_ALTERNATE_SYMBOL_PATH", lpszPath, BUFFERSIZE ) )
|
||||
{
|
||||
strcat( lpszSymbolPath, ";" );
|
||||
strcat( lpszSymbolPath, lpszPath );
|
||||
}
|
||||
|
||||
// environment variable SYSTEMROOT
|
||||
if ( GetEnvironmentVariableA( "SYSTEMROOT", lpszPath, BUFFERSIZE ) )
|
||||
{
|
||||
strcat( lpszSymbolPath, ";" );
|
||||
strcat( lpszSymbolPath, lpszPath );
|
||||
strcat( lpszSymbolPath, ";" );
|
||||
|
||||
// SYSTEMROOT\System32
|
||||
strcat( lpszSymbolPath, lpszPath );
|
||||
strcat( lpszSymbolPath, "\\System32" );
|
||||
}
|
||||
|
||||
// Add user defined path
|
||||
if ( lpszIniPath != NULL )
|
||||
if ( lpszIniPath[0] != '\0' )
|
||||
{
|
||||
strcat( lpszSymbolPath, ";" );
|
||||
strcat( lpszSymbolPath, lpszIniPath );
|
||||
}
|
||||
}
|
||||
|
||||
// Uninitialize the loaded symbol files
|
||||
BOOL UninitSymInfo() {
|
||||
return SymCleanup( GetCurrentProcess() );
|
||||
}
|
||||
|
||||
// Initializes the symbol files
|
||||
BOOL InitSymInfo( PCSTR lpszInitialSymbolPath )
|
||||
{
|
||||
CHAR lpszSymbolPath[BUFFERSIZE];
|
||||
DWORD symOptions = SymGetOptions();
|
||||
|
||||
symOptions |= SYMOPT_LOAD_LINES;
|
||||
symOptions &= ~SYMOPT_UNDNAME;
|
||||
SymSetOptions( symOptions );
|
||||
InitSymbolPath( lpszSymbolPath, lpszInitialSymbolPath );
|
||||
|
||||
return SymInitialize( GetCurrentProcess(), lpszSymbolPath, TRUE);
|
||||
}
|
||||
|
||||
// Get the module name from a given address
|
||||
static BOOL GetModuleNameFromAddress( UINT address, LPTSTR lpszModule )
|
||||
{
|
||||
BOOL ret = FALSE;
|
||||
IMAGEHLP_MODULE moduleInfo;
|
||||
|
||||
::ZeroMemory( &moduleInfo, sizeof(moduleInfo) );
|
||||
moduleInfo.SizeOfStruct = sizeof(moduleInfo);
|
||||
|
||||
if ( SymGetModuleInfo( GetCurrentProcess(), (DWORD)address, &moduleInfo ) )
|
||||
{
|
||||
// Got it!
|
||||
PCSTR2LPTSTR( moduleInfo.ModuleName, lpszModule );
|
||||
ret = TRUE;
|
||||
}
|
||||
else
|
||||
// Not found :(
|
||||
_tcscpy( lpszModule, _T("?") );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get function prototype and parameter info from ip address and stack address
|
||||
static BOOL GetFunctionInfoFromAddresses( ULONG fnAddress, ULONG stackAddress, LPTSTR lpszSymbol )
|
||||
{
|
||||
BOOL ret = FALSE;
|
||||
DWORD dwDisp = 0;
|
||||
DWORD dwSymSize = 10000;
|
||||
TCHAR lpszUnDSymbol[BUFFERSIZE]=_T("?");
|
||||
CHAR lpszNonUnicodeUnDSymbol[BUFFERSIZE]="?";
|
||||
LPTSTR lpszParamSep = NULL;
|
||||
LPTSTR lpszParsed = lpszUnDSymbol;
|
||||
PIMAGEHLP_SYMBOL pSym = (PIMAGEHLP_SYMBOL)GlobalAlloc( GMEM_FIXED, dwSymSize );
|
||||
|
||||
::ZeroMemory( pSym, dwSymSize );
|
||||
pSym->SizeOfStruct = dwSymSize;
|
||||
pSym->MaxNameLength = dwSymSize - sizeof(IMAGEHLP_SYMBOL);
|
||||
|
||||
// Set the default to unknown
|
||||
_tcscpy( lpszSymbol, _T("?") );
|
||||
|
||||
// Get symbol info for IP
|
||||
#ifndef _M_X64
|
||||
if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, &dwDisp, pSym ) )
|
||||
#else
|
||||
//makes it compile but hell im not sure if this works...
|
||||
if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, (PDWORD64)&dwDisp, pSym ) )
|
||||
#endif
|
||||
{
|
||||
// Make the symbol readable for humans
|
||||
UnDecorateSymbolName( pSym->Name, lpszNonUnicodeUnDSymbol, BUFFERSIZE,
|
||||
UNDNAME_COMPLETE |
|
||||
UNDNAME_NO_THISTYPE |
|
||||
UNDNAME_NO_SPECIAL_SYMS |
|
||||
UNDNAME_NO_MEMBER_TYPE |
|
||||
UNDNAME_NO_MS_KEYWORDS |
|
||||
UNDNAME_NO_ACCESS_SPECIFIERS );
|
||||
|
||||
// Symbol information is ANSI string
|
||||
PCSTR2LPTSTR( lpszNonUnicodeUnDSymbol, lpszUnDSymbol );
|
||||
|
||||
// I am just smarter than the symbol file :)
|
||||
if ( _tcscmp(lpszUnDSymbol, _T("_WinMain@16")) == 0 )
|
||||
_tcscpy(lpszUnDSymbol, _T("WinMain(HINSTANCE,HINSTANCE,LPCTSTR,int)"));
|
||||
else
|
||||
if ( _tcscmp(lpszUnDSymbol, _T("_main")) == 0 )
|
||||
_tcscpy(lpszUnDSymbol, _T("main(int,TCHAR * *)"));
|
||||
else
|
||||
if ( _tcscmp(lpszUnDSymbol, _T("_mainCRTStartup")) == 0 )
|
||||
_tcscpy(lpszUnDSymbol, _T("mainCRTStartup()"));
|
||||
else
|
||||
if ( _tcscmp(lpszUnDSymbol, _T("_wmain")) == 0 )
|
||||
_tcscpy(lpszUnDSymbol, _T("wmain(int,TCHAR * *,TCHAR * *)"));
|
||||
else
|
||||
if ( _tcscmp(lpszUnDSymbol, _T("_wmainCRTStartup")) == 0 )
|
||||
_tcscpy(lpszUnDSymbol, _T("wmainCRTStartup()"));
|
||||
|
||||
lpszSymbol[0] = _T('\0');
|
||||
|
||||
// Let's go through the stack, and modify the function prototype, and insert the actual
|
||||
// parameter values from the stack
|
||||
if ( _tcsstr( lpszUnDSymbol, _T("(void)") ) == NULL && _tcsstr( lpszUnDSymbol, _T("()") ) == NULL)
|
||||
{
|
||||
ULONG index = 0;
|
||||
for( ; ; index++ )
|
||||
{
|
||||
lpszParamSep = _tcschr( lpszParsed, _T(',') );
|
||||
if ( lpszParamSep == NULL )
|
||||
break;
|
||||
|
||||
*lpszParamSep = _T('\0');
|
||||
|
||||
_tcscat( lpszSymbol, lpszParsed );
|
||||
_stprintf( lpszSymbol + _tcslen(lpszSymbol), _T("=0x%08X,"), *((ULONG*)(stackAddress) + 2 + index) );
|
||||
|
||||
lpszParsed = lpszParamSep + 1;
|
||||
}
|
||||
|
||||
lpszParamSep = _tcschr( lpszParsed, _T(')') );
|
||||
if ( lpszParamSep != NULL )
|
||||
{
|
||||
*lpszParamSep = _T('\0');
|
||||
|
||||
_tcscat( lpszSymbol, lpszParsed );
|
||||
_stprintf( lpszSymbol + _tcslen(lpszSymbol), _T("=0x%08X)"), *((ULONG*)(stackAddress) + 2 + index) );
|
||||
|
||||
lpszParsed = lpszParamSep + 1;
|
||||
}
|
||||
}
|
||||
|
||||
_tcscat( lpszSymbol, lpszParsed );
|
||||
|
||||
ret = TRUE;
|
||||
}
|
||||
GlobalFree( pSym );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get source file name and line number from IP address
|
||||
// The output format is: "sourcefile(linenumber)" or
|
||||
// "modulename!address" or
|
||||
// "address"
|
||||
static BOOL GetSourceInfoFromAddress( UINT address, LPTSTR lpszSourceInfo )
|
||||
{
|
||||
BOOL ret = FALSE;
|
||||
IMAGEHLP_LINE lineInfo;
|
||||
DWORD dwDisp;
|
||||
TCHAR lpszFileName[BUFFERSIZE] = _T("");
|
||||
TCHAR lpModuleInfo[BUFFERSIZE] = _T("");
|
||||
|
||||
_tcscpy( lpszSourceInfo, _T("?(?)") );
|
||||
|
||||
::ZeroMemory( &lineInfo, sizeof( lineInfo ) );
|
||||
lineInfo.SizeOfStruct = sizeof( lineInfo );
|
||||
|
||||
if ( SymGetLineFromAddr( GetCurrentProcess(), address, &dwDisp, &lineInfo ) )
|
||||
{
|
||||
// Got it. Let's use "sourcefile(linenumber)" format
|
||||
PCSTR2LPTSTR( lineInfo.FileName, lpszFileName );
|
||||
TCHAR fname[_MAX_FNAME];
|
||||
TCHAR ext[_MAX_EXT];
|
||||
_tsplitpath(lpszFileName, NULL, NULL, fname, ext);
|
||||
_stprintf( lpszSourceInfo, _T("%s%s(%d)"), fname, ext, lineInfo.LineNumber );
|
||||
ret = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is no source file information. :(
|
||||
// Let's use the "modulename!address" format
|
||||
GetModuleNameFromAddress( address, lpModuleInfo );
|
||||
|
||||
if ( lpModuleInfo[0] == _T('?') || lpModuleInfo[0] == _T('\0'))
|
||||
// There is no modulename information. :((
|
||||
// Let's use the "address" format
|
||||
_stprintf( lpszSourceInfo, _T("0x%08X"), address );
|
||||
else
|
||||
_stprintf( lpszSourceInfo, _T("%s!0x%08X"), lpModuleInfo, address );
|
||||
|
||||
ret = FALSE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file )
|
||||
{
|
||||
STACKFRAME callStack;
|
||||
BOOL bResult;
|
||||
CONTEXT context;
|
||||
TCHAR symInfo[BUFFERSIZE] = _T("?");
|
||||
TCHAR srcInfo[BUFFERSIZE] = _T("?");
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
// If it's not this thread, let's suspend it, and resume it at the end
|
||||
if ( hThread != GetCurrentThread() )
|
||||
if ( SuspendThread( hThread ) == -1 )
|
||||
{
|
||||
// whaaat ?!
|
||||
etfprint(file, "Call stack info failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
::ZeroMemory( &context, sizeof(context) );
|
||||
context.ContextFlags = CONTEXT_FULL;
|
||||
|
||||
if ( !GetThreadContext( hThread, &context ) )
|
||||
{
|
||||
etfprint(file, "Call stack info failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
::ZeroMemory( &callStack, sizeof(callStack) );
|
||||
#ifndef _M_X64
|
||||
callStack.AddrPC.Offset = context.Eip;
|
||||
callStack.AddrStack.Offset = context.Esp;
|
||||
callStack.AddrFrame.Offset = context.Ebp;
|
||||
#else
|
||||
callStack.AddrPC.Offset = context.Rip;
|
||||
callStack.AddrStack.Offset = context.Rsp;
|
||||
callStack.AddrFrame.Offset = context.Rbp;
|
||||
#endif
|
||||
callStack.AddrPC.Mode = AddrModeFlat;
|
||||
callStack.AddrStack.Mode = AddrModeFlat;
|
||||
callStack.AddrFrame.Mode = AddrModeFlat;
|
||||
|
||||
etfprint(file, "Call stack info: \n");
|
||||
etfprint(file, lpszMessage);
|
||||
|
||||
GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
|
||||
GetSourceInfoFromAddress( (ULONG)callStack.AddrPC.Offset, srcInfo );
|
||||
etfprint(file, wstring(L" ") + srcInfo + L" : " + symInfo + L"\n");
|
||||
|
||||
for( ULONG index = 0; ; index++ )
|
||||
{
|
||||
bResult = StackWalk(
|
||||
IMAGE_FILE_MACHINE_I386,
|
||||
hProcess,
|
||||
hThread,
|
||||
&callStack,
|
||||
NULL,
|
||||
NULL,
|
||||
SymFunctionTableAccess,
|
||||
SymGetModuleBase,
|
||||
NULL);
|
||||
|
||||
if ( index == 0 )
|
||||
continue;
|
||||
|
||||
if( !bResult || callStack.AddrFrame.Offset == 0 )
|
||||
break;
|
||||
|
||||
GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
|
||||
GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo );
|
||||
etfprint(file, wstring(L" ") + srcInfo + L" : " + symInfo + L"\n");
|
||||
|
||||
}
|
||||
|
||||
if ( hThread != GetCurrentThread() )
|
||||
ResumeThread( hThread );
|
||||
}
|
||||
|
||||
void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp )
|
||||
{
|
||||
STACKFRAME callStack;
|
||||
BOOL bResult;
|
||||
TCHAR symInfo[BUFFERSIZE] = _T("?");
|
||||
TCHAR srcInfo[BUFFERSIZE] = _T("?");
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
// If it's not this thread, let's suspend it, and resume it at the end
|
||||
if ( hThread != GetCurrentThread() )
|
||||
if ( SuspendThread( hThread ) == -1 )
|
||||
{
|
||||
// whaaat ?!
|
||||
etfprint(file, "Call stack info failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
::ZeroMemory( &callStack, sizeof(callStack) );
|
||||
callStack.AddrPC.Offset = eip;
|
||||
callStack.AddrStack.Offset = esp;
|
||||
callStack.AddrFrame.Offset = ebp;
|
||||
callStack.AddrPC.Mode = AddrModeFlat;
|
||||
callStack.AddrStack.Mode = AddrModeFlat;
|
||||
callStack.AddrFrame.Mode = AddrModeFlat;
|
||||
|
||||
etfprint(file, "Call stack info: \n");
|
||||
etfprint(file, lpszMessage);
|
||||
|
||||
GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
|
||||
GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo );
|
||||
etfprint(file, wstring(L" ") + srcInfo + L" : " + symInfo + L"\n");
|
||||
|
||||
for( ULONG index = 0; ; index++ )
|
||||
{
|
||||
bResult = StackWalk(
|
||||
IMAGE_FILE_MACHINE_I386,
|
||||
hProcess,
|
||||
hThread,
|
||||
&callStack,
|
||||
NULL,
|
||||
NULL,
|
||||
SymFunctionTableAccess,
|
||||
SymGetModuleBase,
|
||||
NULL);
|
||||
|
||||
if ( index == 0 )
|
||||
continue;
|
||||
|
||||
if( !bResult || callStack.AddrFrame.Offset == 0 )
|
||||
break;
|
||||
|
||||
GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
|
||||
GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo );
|
||||
etfprint(file, wstring(L" ") + srcInfo + L" : " + symInfo + L"\n");
|
||||
}
|
||||
|
||||
if ( hThread != GetCurrentThread() )
|
||||
ResumeThread( hThread );
|
||||
}
|
||||
|
||||
char g_uefbuf[2048];
|
||||
|
||||
void etfprintf(FILE *file, const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int len = vsprintf(g_uefbuf, format, ap);
|
||||
fwrite(g_uefbuf, 1, len, file);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void etfprint(FILE *file, const std::string &text) {
|
||||
size_t len = text.length();
|
||||
fwrite(text.data(), 1, len, file);
|
||||
}
|
||||
|
||||
void etfprint(FILE *file, const std::wstring &text) {
|
||||
size_t len = text.length();
|
||||
fwrite(text.data(), sizeof(wchar_t), len, file);
|
||||
}
|
||||
|
||||
#endif //WIN32
|
||||
@@ -1,55 +0,0 @@
|
||||
// -----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
|
||||
// For companies(Austin,TX): If you would like to get my resume, send an email.
|
||||
//
|
||||
// The source is free, but if you want to use it, mention my name and e-mail address
|
||||
//
|
||||
// History:
|
||||
// 1.0 Initial version Zoltan Csizmadia
|
||||
// 1.1 WhineCube version Masken
|
||||
// 1.2 Dolphin version Masken
|
||||
//
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _EXTENDEDTRACE_H_INCLUDED_
|
||||
#define _EXTENDEDTRACE_H_INCLUDED_
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#include "CommonWindows.h"
|
||||
#include <tchar.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#pragma comment( lib, "imagehlp.lib" )
|
||||
|
||||
#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) InitSymInfo( IniSymbolPath )
|
||||
#define EXTENDEDTRACEUNINITIALIZE() UninitSymInfo()
|
||||
#define STACKTRACE(file) StackTrace( GetCurrentThread(), _T(""), file)
|
||||
#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), _T(""), file, eip, esp, ebp)
|
||||
// class File;
|
||||
|
||||
BOOL InitSymInfo( PCSTR );
|
||||
BOOL UninitSymInfo();
|
||||
void StackTrace( HANDLE, LPCTSTR, FILE *file);
|
||||
void StackTrace( HANDLE, LPCTSTR, FILE *file, DWORD eip, DWORD esp, DWORD ebp);
|
||||
void StackTrace( HANDLE hThread, wchar_t const* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp);
|
||||
|
||||
// functions by Masken
|
||||
void etfprintf(FILE *file, const char *format, ...);
|
||||
void etfprint(FILE *file, const std::string &text);
|
||||
void etfprint(FILE *file, const std::wstring &text);
|
||||
#define UEFBUFSIZE 2048
|
||||
extern char g_uefbuf[UEFBUFSIZE];
|
||||
|
||||
#else // not WIN32
|
||||
|
||||
#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) ((void)0)
|
||||
#define EXTENDEDTRACEUNINITIALIZE() ((void)0)
|
||||
#define STACKTRACE(file) ((void)0)
|
||||
#define STACKTRACE2(file, eip, esp, ebp) ((void)0)
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#endif // _EXTENDEDTRACE_H_INCLUDED_
|
||||
@@ -1,51 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
#ifndef FPU_ROUND_MODE_H_
|
||||
#define FPU_ROUND_MODE_H_
|
||||
#include "Common.h"
|
||||
|
||||
namespace FPURoundMode
|
||||
{
|
||||
enum RoundModes
|
||||
{
|
||||
ROUND_NEAR = 0,
|
||||
ROUND_CHOP,
|
||||
ROUND_UP,
|
||||
ROUND_DOWN
|
||||
};
|
||||
enum PrecisionModes {
|
||||
PREC_24 = 0,
|
||||
PREC_53,
|
||||
PREC_64
|
||||
};
|
||||
void SetRoundMode(u32 mode);
|
||||
|
||||
void SetPrecisionMode(u32 mode);
|
||||
|
||||
void SetSIMDMode(u32 mode);
|
||||
|
||||
/*
|
||||
There are two different flavors of float to int conversion:
|
||||
_mm_cvtps_epi32() and _mm_cvttps_epi32(). The first rounds
|
||||
according to the MXCSR rounding bits. The second one always
|
||||
uses round towards zero.
|
||||
*/
|
||||
void SaveSIMDState();
|
||||
void LoadSIMDState();
|
||||
void LoadDefaultSIMDState();
|
||||
}
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#include "FPURoundMode.h"
|
||||
|
||||
// Generic, do nothing
|
||||
namespace FPURoundMode
|
||||
{
|
||||
void SetRoundMode(u32 mode)
|
||||
{
|
||||
}
|
||||
void SetPrecisionMode(u32 mode)
|
||||
{
|
||||
}
|
||||
void SetSIMDMode(u32 mode)
|
||||
{
|
||||
}
|
||||
void SaveSIMDState()
|
||||
{
|
||||
}
|
||||
void LoadSIMDState()
|
||||
{
|
||||
}
|
||||
void LoadDefaultSIMDState()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#include "Common.h"
|
||||
#include "FPURoundMode.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
static const unsigned short FPU_ROUND_NEAR = 0 << 10;
|
||||
static const unsigned short FPU_ROUND_DOWN = 1 << 10;
|
||||
static const unsigned short FPU_ROUND_UP = 2 << 10;
|
||||
static const unsigned short FPU_ROUND_CHOP = 3 << 10;
|
||||
static const unsigned short FPU_ROUND_MASK = 3 << 10;
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
|
||||
const u32 MASKS = 0x1F80; // mask away the interrupts.
|
||||
const u32 DAZ = 0x40;
|
||||
const u32 FTZ = 0x8000;
|
||||
|
||||
namespace FPURoundMode
|
||||
{
|
||||
// Get the default SSE states here.
|
||||
static u32 saved_sse_state = _mm_getcsr();
|
||||
static const u32 default_sse_state = _mm_getcsr();
|
||||
|
||||
void SetRoundMode(u32 mode)
|
||||
{
|
||||
// Set FPU rounding mode to mimic the PowerPC's
|
||||
#ifdef _M_IX86
|
||||
// This shouldn't really be needed anymore since we use SSE
|
||||
#ifdef _WIN32
|
||||
const int table[4] =
|
||||
{
|
||||
_RC_NEAR,
|
||||
_RC_CHOP,
|
||||
_RC_UP,
|
||||
_RC_DOWN
|
||||
};
|
||||
_set_controlfp(_MCW_RC, table[mode]);
|
||||
#else
|
||||
const unsigned short table[4] =
|
||||
{
|
||||
FPU_ROUND_NEAR,
|
||||
FPU_ROUND_CHOP,
|
||||
FPU_ROUND_UP,
|
||||
FPU_ROUND_DOWN
|
||||
};
|
||||
unsigned short mode;
|
||||
asm ("fstcw %0" : "=m" (mode) : );
|
||||
mode = (mode & ~FPU_ROUND_MASK) | table[mode];
|
||||
asm ("fldcw %0" : : "m" (mode));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetPrecisionMode(u32 mode)
|
||||
{
|
||||
const char table[4] {
|
||||
0 << 8, // FPU_PREC_24
|
||||
2 << 8, // FPU_PREC_53
|
||||
3 << 8, // FPU_PREC_64
|
||||
3 << 8, // FPU_PREC_MASK
|
||||
};
|
||||
#ifdef _M_IX86
|
||||
// sets the floating-point lib to 53-bit
|
||||
// PowerPC has a 53bit floating pipeline only
|
||||
// eg: sscanf is very sensitive
|
||||
#ifdef _WIN32
|
||||
_control87(_PC_53, MCW_PC);
|
||||
#else
|
||||
unsigned short _mode;
|
||||
asm ("fstcw %0" : : "m" (_mode));
|
||||
_mode = (_mode & ~table[4]) | table[mode];
|
||||
asm ("fldcw %0" : : "m" (_mode));
|
||||
#endif
|
||||
#else
|
||||
//x64 doesn't need this - fpu is done with SSE
|
||||
//but still - set any useful sse options here
|
||||
#endif
|
||||
}
|
||||
void SetSIMDMode(u32 mode)
|
||||
{
|
||||
static const u32 ssetable[4] =
|
||||
{
|
||||
(0 << 13) | MASKS,
|
||||
(3 << 13) | MASKS,
|
||||
(2 << 13) | MASKS,
|
||||
(1 << 13) | MASKS,
|
||||
};
|
||||
u32 csr = ssetable[mode];
|
||||
_mm_setcsr(csr);
|
||||
}
|
||||
|
||||
void SaveSIMDState()
|
||||
{
|
||||
saved_sse_state = _mm_getcsr();
|
||||
}
|
||||
void LoadSIMDState()
|
||||
{
|
||||
_mm_setcsr(saved_sse_state);
|
||||
}
|
||||
void LoadDefaultSIMDState()
|
||||
{
|
||||
_mm_setcsr(default_sse_state);
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
|
||||
#ifndef _FIFO_QUEUE_H_
|
||||
#define _FIFO_QUEUE_H_
|
||||
|
||||
// a simple lockless thread-safe,
|
||||
// single reader, single writer queue
|
||||
|
||||
#include "Atomics.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
class FifoQueue
|
||||
{
|
||||
public:
|
||||
FifoQueue() : m_size(0)
|
||||
{
|
||||
m_write_ptr = m_read_ptr = new ElementPtr();
|
||||
}
|
||||
|
||||
~FifoQueue()
|
||||
{
|
||||
// this will empty out the whole queue
|
||||
delete m_read_ptr;
|
||||
}
|
||||
|
||||
u32 Size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
//return (m_read_ptr == m_write_ptr);
|
||||
return (0 == m_size);
|
||||
}
|
||||
|
||||
const T& Front() const
|
||||
{
|
||||
return *m_read_ptr->current;
|
||||
}
|
||||
|
||||
void Push(const T& t)
|
||||
{
|
||||
// create the element, add it to the queue
|
||||
m_write_ptr->current = new T(t);
|
||||
// set the next pointer to a new element ptr
|
||||
// then advance the write pointer
|
||||
m_write_ptr = m_write_ptr->next = new ElementPtr();
|
||||
Common::AtomicIncrement(m_size);
|
||||
}
|
||||
|
||||
void Pop()
|
||||
{
|
||||
Common::AtomicDecrement(m_size);
|
||||
ElementPtr *const tmpptr = m_read_ptr;
|
||||
// advance the read pointer
|
||||
m_read_ptr = m_read_ptr->next;
|
||||
// set the next element to NULL to stop the recursive deletion
|
||||
tmpptr->next = NULL;
|
||||
delete tmpptr; // this also deletes the element
|
||||
}
|
||||
|
||||
bool Pop(T& t)
|
||||
{
|
||||
if (Empty())
|
||||
return false;
|
||||
|
||||
t = Front();
|
||||
Pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// not thread-safe
|
||||
void Clear()
|
||||
{
|
||||
m_size = 0;
|
||||
delete m_read_ptr;
|
||||
m_write_ptr = m_read_ptr = new ElementPtr();
|
||||
}
|
||||
|
||||
private:
|
||||
// stores a pointer to element
|
||||
// and a pointer to the next ElementPtr
|
||||
class ElementPtr
|
||||
{
|
||||
public:
|
||||
ElementPtr() : current(NULL), next(NULL) {}
|
||||
|
||||
~ElementPtr()
|
||||
{
|
||||
if (current)
|
||||
{
|
||||
delete current;
|
||||
// recusion ftw
|
||||
if (next)
|
||||
delete next;
|
||||
}
|
||||
}
|
||||
|
||||
T *volatile current;
|
||||
ElementPtr *volatile next;
|
||||
};
|
||||
|
||||
ElementPtr *volatile m_write_ptr;
|
||||
ElementPtr *volatile m_read_ptr;
|
||||
volatile u32 m_size;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,123 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#include "Common.h"
|
||||
#include "CommonPaths.h"
|
||||
#ifndef _WIN32
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include "CommonWindows.h"
|
||||
#endif
|
||||
|
||||
// strcasecmp
|
||||
#ifdef __APPLE__
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "FileSearch.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
|
||||
CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories)
|
||||
{
|
||||
// Reverse the loop order for speed?
|
||||
for (size_t j = 0; j < _rSearchStrings.size(); j++)
|
||||
{
|
||||
for (size_t i = 0; i < _rDirectories.size(); i++)
|
||||
{
|
||||
FindFiles(_rSearchStrings[j], _rDirectories[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath)
|
||||
{
|
||||
std::string GCMSearchPath;
|
||||
BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
|
||||
#ifdef _WIN32
|
||||
WIN32_FIND_DATA findData;
|
||||
std::wstring searchPathW = ConvertUTF8ToWString(GCMSearchPath);
|
||||
HANDLE FindFirst = FindFirstFile(searchPathW.c_str(), &findData);
|
||||
|
||||
if (FindFirst != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
bool bkeepLooping = true;
|
||||
|
||||
while (bkeepLooping)
|
||||
{
|
||||
if (findData.cFileName[0] != '.')
|
||||
{
|
||||
std::string strFilename;
|
||||
BuildCompleteFilename(strFilename, _strPath, ConvertWStringToUTF8(findData.cFileName));
|
||||
m_FileNames.push_back(strFilename);
|
||||
}
|
||||
|
||||
bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
|
||||
}
|
||||
}
|
||||
FindClose(FindFirst);
|
||||
|
||||
|
||||
#else
|
||||
size_t dot_pos = _searchString.rfind(".");
|
||||
|
||||
if (dot_pos == std::string::npos)
|
||||
return;
|
||||
|
||||
std::string ext = _searchString.substr(dot_pos);
|
||||
DIR* dir = opendir(_strPath.c_str());
|
||||
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
dirent* dp;
|
||||
|
||||
while (true)
|
||||
{
|
||||
dp = readdir(dir);
|
||||
|
||||
if (!dp)
|
||||
break;
|
||||
|
||||
std::string s(dp->d_name);
|
||||
|
||||
if ( (!ext.compare(".*") && s.compare(".") && s.compare("..")) ||
|
||||
((s.size() > ext.size()) && (!strcasecmp(s.substr(s.size() - ext.size()).c_str(), ext.c_str())) ))
|
||||
{
|
||||
std::string full_name;
|
||||
if (strchr(DIR_SEP_CHRS, _strPath.c_str()[_strPath.size()-1]))
|
||||
full_name = _strPath + s;
|
||||
else
|
||||
full_name = _strPath + DIR_SEP + s;
|
||||
|
||||
m_FileNames.push_back(full_name);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
|
||||
{
|
||||
return m_FileNames;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#ifndef _FILESEARCH_H_
|
||||
#define _FILESEARCH_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CFileSearch
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string>XStringVector;
|
||||
|
||||
CFileSearch(const XStringVector& _rSearchStrings, const XStringVector& _rDirectories);
|
||||
const XStringVector& GetFileNames() const;
|
||||
|
||||
private:
|
||||
|
||||
void FindFiles(const std::string& _searchString, const std::string& _strPath);
|
||||
|
||||
XStringVector m_FileNames;
|
||||
};
|
||||
|
||||
#endif // _FILESEARCH_H_
|
||||
|
||||
+1
-32
@@ -15,7 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "CommonPaths.h"
|
||||
#include "FileUtil.h"
|
||||
#include "StringUtils.h"
|
||||
@@ -43,7 +42,6 @@
|
||||
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef S_ISDIR
|
||||
@@ -710,42 +708,13 @@ std::string &GetUserPath(const unsigned int DirIDX, const std::string &newPath)
|
||||
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
|
||||
paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
|
||||
paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
|
||||
paths[F_CONFIG_IDX] = paths[D_CONFIG_IDX] + CONFIG_FILE;
|
||||
paths[F_CONFIG_IDX] = paths[D_CONFIG_IDX] + CONFIG_FILE;
|
||||
paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
|
||||
}
|
||||
|
||||
return paths[DirIDX];
|
||||
}
|
||||
|
||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
||||
{
|
||||
FILE *f = OpenCFile(filename, text_file ? "w" : "wb");
|
||||
if (!f)
|
||||
return false;
|
||||
size_t len = str.size();
|
||||
if (len != fwrite(str.data(), 1, str.size(), f)) // TODO: string::data() may not be contiguous
|
||||
{
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
||||
{
|
||||
FILE *f = OpenCFile(filename, text_file ? "r" : "rb");
|
||||
if (!f)
|
||||
return false;
|
||||
size_t len = (size_t)GetSize(f);
|
||||
char *buf = new char[len + 1];
|
||||
buf[fread(buf, 1, len, f)] = 0;
|
||||
str = std::string(buf, len);
|
||||
fclose(f);
|
||||
delete [] buf;
|
||||
return true;
|
||||
}
|
||||
|
||||
IOFile::IOFile()
|
||||
: m_file(NULL), m_good(true)
|
||||
{}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Common.h"
|
||||
@@ -129,9 +128,6 @@ std::string GetBundleDirectory();
|
||||
std::string &GetExeDirectory();
|
||||
#endif
|
||||
|
||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename);
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str);
|
||||
|
||||
// simple wrapper for cstdlib file functions to
|
||||
// hopefully will make error checking easier
|
||||
// and make forgetting an fclose() harder
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Really stupid but much faster than a vector for keeping breakpoints in
|
||||
// and looking them up in debug mode. STL is SOOO SLOW in debug mode on Windows.
|
||||
|
||||
|
||||
template<class T, size_t maxCount>
|
||||
class FixedSizeUnorderedSet
|
||||
{
|
||||
public:
|
||||
bool insert(T item)
|
||||
{
|
||||
if (count_ < (int)maxCount - 1)
|
||||
{
|
||||
data_[count_++] = item;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool remove(T item)
|
||||
{
|
||||
for (int i = 0; i < count_; i++)
|
||||
{
|
||||
if (data_[i] == item)
|
||||
{
|
||||
if (i == count_ - 1)
|
||||
{
|
||||
count_--;
|
||||
}
|
||||
else
|
||||
{
|
||||
data_[i] = data_[count_ - 1];
|
||||
count_--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size()
|
||||
{
|
||||
return (size_t)count_;
|
||||
}
|
||||
|
||||
T &operator[](size_t index) {
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
const T &operator[](size_t index) const {
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
void clear() {
|
||||
count_ = 0;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return count_ != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
T data_[maxCount];
|
||||
int count_;
|
||||
};
|
||||
-529
@@ -1,529 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#include <algorithm>
|
||||
#include "Hash.h"
|
||||
#if _M_SSE >= 0x402
|
||||
#include "CPUDetect.h"
|
||||
#include <nmmintrin.h>
|
||||
#endif
|
||||
|
||||
static u64 (*ptrHashFunction)(const u8 *src, int len, u32 samples) = &GetMurmurHash3;
|
||||
|
||||
// uint32_t
|
||||
// WARNING - may read one more byte!
|
||||
// Implementation from Wikipedia.
|
||||
u32 HashFletcher(const u8* data_u8, size_t length)
|
||||
{
|
||||
const u16* data = (const u16*)data_u8; /* Pointer to the data to be summed */
|
||||
size_t len = (length + 1) / 2; /* Length in 16-bit words */
|
||||
u32 sum1 = 0xffff, sum2 = 0xffff;
|
||||
|
||||
while (len)
|
||||
{
|
||||
size_t tlen = len > 360 ? 360 : len;
|
||||
len -= tlen;
|
||||
|
||||
do {
|
||||
sum1 += *data++;
|
||||
sum2 += sum1;
|
||||
}
|
||||
while (--tlen);
|
||||
|
||||
sum1 = (sum1 & 0xffff) + (sum1 >> 16);
|
||||
sum2 = (sum2 & 0xffff) + (sum2 >> 16);
|
||||
}
|
||||
|
||||
// Second reduction step to reduce sums to 16 bits
|
||||
sum1 = (sum1 & 0xffff) + (sum1 >> 16);
|
||||
sum2 = (sum2 & 0xffff) + (sum2 >> 16);
|
||||
return(sum2 << 16 | sum1);
|
||||
}
|
||||
|
||||
|
||||
// Implementation from Wikipedia
|
||||
// Slightly slower than Fletcher above, but slighly more reliable.
|
||||
#define MOD_ADLER 65521
|
||||
// data: Pointer to the data to be summed; len is in bytes
|
||||
u32 HashAdler32(const u8* data, size_t len)
|
||||
{
|
||||
u32 a = 1, b = 0;
|
||||
|
||||
while (len)
|
||||
{
|
||||
size_t tlen = len > 5550 ? 5550 : len;
|
||||
len -= tlen;
|
||||
|
||||
do
|
||||
{
|
||||
a += *data++;
|
||||
b += a;
|
||||
}
|
||||
while (--tlen);
|
||||
|
||||
a = (a & 0xffff) + (a >> 16) * (65536 - MOD_ADLER);
|
||||
b = (b & 0xffff) + (b >> 16) * (65536 - MOD_ADLER);
|
||||
}
|
||||
|
||||
// It can be shown that a <= 0x1013a here, so a single subtract will do.
|
||||
if (a >= MOD_ADLER)
|
||||
{
|
||||
a -= MOD_ADLER;
|
||||
}
|
||||
|
||||
// It can be shown that b can reach 0xfff87 here.
|
||||
b = (b & 0xffff) + (b >> 16) * (65536 - MOD_ADLER);
|
||||
|
||||
if (b >= MOD_ADLER)
|
||||
{
|
||||
b -= MOD_ADLER;
|
||||
}
|
||||
|
||||
return((b << 16) | a);
|
||||
}
|
||||
|
||||
// Stupid hash - but can't go back now :)
|
||||
// Don't use for new things. At least it's reasonably fast.
|
||||
u32 HashEctor(const u8* ptr, int length)
|
||||
{
|
||||
u32 crc = 0;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
crc ^= ptr[i];
|
||||
crc = (crc << 3) | (crc >> 29);
|
||||
}
|
||||
|
||||
return(crc);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _M_X64
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Block read - if your platform needs to do endian-swapping or can only
|
||||
// handle aligned reads, do the conversion here
|
||||
|
||||
inline u64 getblock(const u64 * p, int i)
|
||||
{
|
||||
return p[i];
|
||||
}
|
||||
|
||||
//----------
|
||||
// Block mix - combine the key bits with the hash bits and scramble everything
|
||||
|
||||
inline void bmix64(u64 & h1, u64 & h2, u64 & k1, u64 & k2, u64 & c1, u64 & c2)
|
||||
{
|
||||
k1 *= c1;
|
||||
k1 = __rotl64(k1,23);
|
||||
k1 *= c2;
|
||||
h1 ^= k1;
|
||||
h1 += h2;
|
||||
|
||||
h2 = __rotl64(h2,41);
|
||||
|
||||
k2 *= c2;
|
||||
k2 = __rotl64(k2,23);
|
||||
k2 *= c1;
|
||||
h2 ^= k2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = h1*3+0x52dce729;
|
||||
h2 = h2*3+0x38495ab5;
|
||||
|
||||
c1 = c1*5+0x7b7d159c;
|
||||
c2 = c2*5+0x6bce6396;
|
||||
}
|
||||
|
||||
//----------
|
||||
// Finalization mix - avalanches all bits to within 0.05% bias
|
||||
|
||||
inline u64 fmix64(u64 k)
|
||||
{
|
||||
k ^= k >> 33;
|
||||
k *= 0xff51afd7ed558ccd;
|
||||
k ^= k >> 33;
|
||||
k *= 0xc4ceb9fe1a85ec53;
|
||||
k ^= k >> 33;
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
u64 GetMurmurHash3(const u8 *src, int len, u32 samples)
|
||||
{
|
||||
const u8 * data = (const u8*)src;
|
||||
const int nblocks = len / 16;
|
||||
u32 Step = (len / 8);
|
||||
if(samples == 0) samples = std::max(Step, 1u);
|
||||
Step = Step / samples;
|
||||
if(Step < 1) Step = 1;
|
||||
|
||||
u64 h1 = 0x9368e53c2f6af274;
|
||||
u64 h2 = 0x586dcd208f7cd3fd;
|
||||
|
||||
u64 c1 = 0x87c37b91114253d5;
|
||||
u64 c2 = 0x4cf5ad432745937f;
|
||||
|
||||
|
||||
//----------
|
||||
// body
|
||||
|
||||
const u64 * blocks = (const u64 *)(data);
|
||||
|
||||
for(int i = 0; i < nblocks; i+=Step)
|
||||
{
|
||||
u64 k1 = getblock(blocks,i*2+0);
|
||||
u64 k2 = getblock(blocks,i*2+1);
|
||||
|
||||
bmix64(h1,h2,k1,k2,c1,c2);
|
||||
}
|
||||
|
||||
//----------
|
||||
// tail
|
||||
|
||||
const u8 * tail = (const u8*)(data + nblocks*16);
|
||||
|
||||
u64 k1 = 0;
|
||||
u64 k2 = 0;
|
||||
|
||||
switch(len & 15)
|
||||
{
|
||||
case 15: k2 ^= u64(tail[14]) << 48;
|
||||
case 14: k2 ^= u64(tail[13]) << 40;
|
||||
case 13: k2 ^= u64(tail[12]) << 32;
|
||||
case 12: k2 ^= u64(tail[11]) << 24;
|
||||
case 11: k2 ^= u64(tail[10]) << 16;
|
||||
case 10: k2 ^= u64(tail[ 9]) << 8;
|
||||
case 9: k2 ^= u64(tail[ 8]) << 0;
|
||||
|
||||
case 8: k1 ^= u64(tail[ 7]) << 56;
|
||||
case 7: k1 ^= u64(tail[ 6]) << 48;
|
||||
case 6: k1 ^= u64(tail[ 5]) << 40;
|
||||
case 5: k1 ^= u64(tail[ 4]) << 32;
|
||||
case 4: k1 ^= u64(tail[ 3]) << 24;
|
||||
case 3: k1 ^= u64(tail[ 2]) << 16;
|
||||
case 2: k1 ^= u64(tail[ 1]) << 8;
|
||||
case 1: k1 ^= u64(tail[ 0]) << 0;
|
||||
bmix64(h1,h2,k1,k2,c1,c2);
|
||||
};
|
||||
|
||||
//----------
|
||||
// finalization
|
||||
|
||||
h2 ^= len;
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = fmix64(h1);
|
||||
h2 = fmix64(h2);
|
||||
|
||||
h1 += h2;
|
||||
|
||||
return h1;
|
||||
}
|
||||
|
||||
|
||||
// CRC32 hash using the SSE4.2 instruction
|
||||
u64 GetCRC32(const u8 *src, int len, u32 samples)
|
||||
{
|
||||
#if _M_SSE >= 0x402
|
||||
u64 h = len;
|
||||
u32 Step = (len / 8);
|
||||
const u64 *data = (const u64 *)src;
|
||||
const u64 *end = data + Step;
|
||||
if(samples == 0) samples = std::max(Step, 1u);
|
||||
Step = Step / samples;
|
||||
if(Step < 1) Step = 1;
|
||||
while(data < end)
|
||||
{
|
||||
h = _mm_crc32_u64(h, data[0]);
|
||||
data += Step;
|
||||
}
|
||||
|
||||
const u8 *data2 = (const u8*)end;
|
||||
return _mm_crc32_u64(h, u64(data2[0]));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* NOTE: This hash function is used for custom texture loading/dumping, so
|
||||
it should not be changed, which would require all custom textures to be
|
||||
recalculated for their new hash values. If the hashing function is
|
||||
changed, make sure this one is still used when the legacy parameter is
|
||||
true. */
|
||||
u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
|
||||
{
|
||||
const u64 m = 0xc6a4a7935bd1e995;
|
||||
u64 h = len * m;
|
||||
const int r = 47;
|
||||
u32 Step = (len / 8);
|
||||
const u64 *data = (const u64 *)src;
|
||||
const u64 *end = data + Step;
|
||||
if(samples == 0) samples = std::max(Step, 1u);
|
||||
Step = Step / samples;
|
||||
if(Step < 1) Step = 1;
|
||||
while(data < end)
|
||||
{
|
||||
u64 k = data[0];
|
||||
data+=Step;
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
h ^= k;
|
||||
h *= m;
|
||||
}
|
||||
|
||||
const u8 * data2 = (const u8*)end;
|
||||
|
||||
switch(len & 7)
|
||||
{
|
||||
case 7: h ^= u64(data2[6]) << 48;
|
||||
case 6: h ^= u64(data2[5]) << 40;
|
||||
case 5: h ^= u64(data2[4]) << 32;
|
||||
case 4: h ^= u64(data2[3]) << 24;
|
||||
case 3: h ^= u64(data2[2]) << 16;
|
||||
case 2: h ^= u64(data2[1]) << 8;
|
||||
case 1: h ^= u64(data2[0]);
|
||||
h *= m;
|
||||
};
|
||||
|
||||
h ^= h >> r;
|
||||
h *= m;
|
||||
h ^= h >> r;
|
||||
|
||||
return h;
|
||||
}
|
||||
#else
|
||||
// CRC32 hash using the SSE4.2 instruction
|
||||
u64 GetCRC32(const u8 *src, int len, u32 samples)
|
||||
{
|
||||
#if _M_SSE >= 0x402
|
||||
u32 h = len;
|
||||
u32 Step = (len/4);
|
||||
const u32 *data = (const u32 *)src;
|
||||
const u32 *end = data + Step;
|
||||
if(samples == 0) samples = std::max(Step, 1u);
|
||||
Step = Step / samples;
|
||||
if(Step < 1) Step = 1;
|
||||
while(data < end)
|
||||
{
|
||||
h = _mm_crc32_u32(h, data[0]);
|
||||
data += Step;
|
||||
}
|
||||
|
||||
const u8 *data2 = (const u8*)end;
|
||||
return (u64)_mm_crc32_u32(h, u32(data2[0]));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Block read - if your platform needs to do endian-swapping or can only
|
||||
// handle aligned reads, do the conversion here
|
||||
|
||||
inline u32 getblock(const u32 * p, int i)
|
||||
{
|
||||
return p[i];
|
||||
}
|
||||
|
||||
//----------
|
||||
// Finalization mix - force all bits of a hash block to avalanche
|
||||
|
||||
// avalanches all bits to within 0.25% bias
|
||||
|
||||
inline u32 fmix32(u32 h)
|
||||
{
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
inline void bmix32(u32 & h1, u32 & h2, u32 & k1, u32 & k2, u32 & c1, u32 & c2)
|
||||
{
|
||||
k1 *= c1;
|
||||
k1 = __rotl(k1,11);
|
||||
k1 *= c2;
|
||||
h1 ^= k1;
|
||||
h1 += h2;
|
||||
|
||||
h2 = __rotl(h2,17);
|
||||
|
||||
k2 *= c2;
|
||||
k2 = __rotl(k2,11);
|
||||
k2 *= c1;
|
||||
h2 ^= k2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = h1*3+0x52dce729;
|
||||
h2 = h2*3+0x38495ab5;
|
||||
|
||||
c1 = c1*5+0x7b7d159c;
|
||||
c2 = c2*5+0x6bce6396;
|
||||
}
|
||||
|
||||
//----------
|
||||
|
||||
u64 GetMurmurHash3(const u8* src, int len, u32 samples)
|
||||
{
|
||||
const u8 * data = (const u8*)src;
|
||||
u32 out[2];
|
||||
const int nblocks = len / 8;
|
||||
u32 Step = (len / 4);
|
||||
if(samples == 0) samples = std::max(Step, 1u);
|
||||
Step = Step / samples;
|
||||
if(Step < 1) Step = 1;
|
||||
|
||||
u32 h1 = 0x8de1c3ac;
|
||||
u32 h2 = 0xbab98226;
|
||||
|
||||
u32 c1 = 0x95543787;
|
||||
u32 c2 = 0x2ad7eb25;
|
||||
|
||||
//----------
|
||||
// body
|
||||
|
||||
const u32 * blocks = (const u32 *)(data + nblocks*8);
|
||||
|
||||
for(int i = -nblocks; i < 0; i+=Step)
|
||||
{
|
||||
u32 k1 = getblock(blocks,i*2+0);
|
||||
u32 k2 = getblock(blocks,i*2+1);
|
||||
|
||||
bmix32(h1,h2,k1,k2,c1,c2);
|
||||
}
|
||||
|
||||
//----------
|
||||
// tail
|
||||
|
||||
const u8 * tail = (const u8*)(data + nblocks*8);
|
||||
|
||||
u32 k1 = 0;
|
||||
u32 k2 = 0;
|
||||
|
||||
switch(len & 7)
|
||||
{
|
||||
case 7: k2 ^= tail[6] << 16;
|
||||
case 6: k2 ^= tail[5] << 8;
|
||||
case 5: k2 ^= tail[4] << 0;
|
||||
case 4: k1 ^= tail[3] << 24;
|
||||
case 3: k1 ^= tail[2] << 16;
|
||||
case 2: k1 ^= tail[1] << 8;
|
||||
case 1: k1 ^= tail[0] << 0;
|
||||
bmix32(h1,h2,k1,k2,c1,c2);
|
||||
};
|
||||
|
||||
//----------
|
||||
// finalization
|
||||
|
||||
h2 ^= len;
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = fmix32(h1);
|
||||
h2 = fmix32(h2);
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
out[0] = h1;
|
||||
out[1] = h2;
|
||||
|
||||
return *((u64 *)&out);
|
||||
}
|
||||
|
||||
/* FIXME: The old 32-bit version of this hash made different hashes than the
|
||||
64-bit version. Until someone can make a new version of the 32-bit one that
|
||||
makes identical hashes, this is just a c/p of the 64-bit one. */
|
||||
u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
|
||||
{
|
||||
const u64 m = 0xc6a4a7935bd1e995ULL;
|
||||
u64 h = len * m;
|
||||
const int r = 47;
|
||||
u32 Step = (len / 8);
|
||||
const u64 *data = (const u64 *)src;
|
||||
const u64 *end = data + Step;
|
||||
if(samples == 0) samples = std::max(Step, 1u);
|
||||
Step = Step / samples;
|
||||
if(Step < 1) Step = 1;
|
||||
while(data < end)
|
||||
{
|
||||
u64 k = data[0];
|
||||
data+=Step;
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
h ^= k;
|
||||
h *= m;
|
||||
}
|
||||
|
||||
const u8 * data2 = (const u8*)end;
|
||||
|
||||
switch(len & 7)
|
||||
{
|
||||
case 7: h ^= u64(data2[6]) << 48;
|
||||
case 6: h ^= u64(data2[5]) << 40;
|
||||
case 5: h ^= u64(data2[4]) << 32;
|
||||
case 4: h ^= u64(data2[3]) << 24;
|
||||
case 3: h ^= u64(data2[2]) << 16;
|
||||
case 2: h ^= u64(data2[1]) << 8;
|
||||
case 1: h ^= u64(data2[0]);
|
||||
h *= m;
|
||||
};
|
||||
|
||||
h ^= h >> r;
|
||||
h *= m;
|
||||
h ^= h >> r;
|
||||
|
||||
return h;
|
||||
}
|
||||
#endif
|
||||
|
||||
u64 GetHash64(const u8 *src, int len, u32 samples)
|
||||
{
|
||||
return ptrHashFunction(src, len, samples);
|
||||
}
|
||||
|
||||
// sets the hash function used for the texture cache
|
||||
void SetHash64Function(bool useHiresTextures)
|
||||
{
|
||||
if (useHiresTextures)
|
||||
{
|
||||
ptrHashFunction = &GetHashHiresTexture;
|
||||
}
|
||||
#if _M_SSE >= 0x402
|
||||
else if (cpu_info.bSSE4_2 && !useHiresTextures) // sse crc32 version
|
||||
{
|
||||
ptrHashFunction = &GetCRC32;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
ptrHashFunction = &GetMurmurHash3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#ifndef _HASH_H_
|
||||
#define _HASH_H_
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
u32 HashFletcher(const u8* data_u8, size_t length); // FAST. Length & 1 == 0.
|
||||
u32 HashAdler32(const u8* data, size_t len); // Fairly accurate, slightly slower
|
||||
u32 HashFNV(const u8* ptr, int length); // Another fast and decent hash
|
||||
u32 HashEctor(const u8* ptr, int length); // JUNK. DO NOT USE FOR NEW THINGS
|
||||
u64 GetCRC32(const u8 *src, int len, u32 samples); // SSE4.2 version of CRC32
|
||||
u64 GetHashHiresTexture(const u8 *src, int len, u32 samples);
|
||||
u64 GetMurmurHash3(const u8 *src, int len, u32 samples);
|
||||
u64 GetHash64(const u8 *src, int len, u32 samples);
|
||||
void SetHash64Function(bool useHiresTextures);
|
||||
#endif // _HASH_H_
|
||||
@@ -1,204 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#ifndef _LINEAR_DISKCACHE
|
||||
#define _LINEAR_DISKCACHE
|
||||
|
||||
#include "Common.h"
|
||||
#include <fstream>
|
||||
|
||||
// Increment this every time you change shader generation code.
|
||||
enum
|
||||
{
|
||||
LINEAR_DISKCACHE_VER = 6979
|
||||
};
|
||||
|
||||
// On disk format:
|
||||
//header{
|
||||
// u32 'DCAC';
|
||||
// u32 version; // svn_rev
|
||||
// u16 sizeof(key_type);
|
||||
// u16 sizeof(value_type);
|
||||
//}
|
||||
|
||||
//key_value_pair{
|
||||
// u32 value_size;
|
||||
// key_type key;
|
||||
// value_type[value_size] value;
|
||||
//}
|
||||
|
||||
template <typename K, typename V>
|
||||
class LinearDiskCacheReader
|
||||
{
|
||||
public:
|
||||
virtual void Read(const K &key, const V *value, u32 value_size) = 0;
|
||||
};
|
||||
|
||||
// Dead simple unsorted key-value store with append functionality.
|
||||
// No random read functionality, all reading is done in OpenAndRead.
|
||||
// Keys and values can contain any characters, including \0.
|
||||
//
|
||||
// Suitable for caching generated shader bytecode between executions.
|
||||
// Not tuned for extreme performance but should be reasonably fast.
|
||||
// Does not support keys or values larger than 2GB, which should be reasonable.
|
||||
// Keys must have non-zero length; values can have zero length.
|
||||
|
||||
// K and V are some POD type
|
||||
// K : the key type
|
||||
// V : value array type
|
||||
template <typename K, typename V>
|
||||
class LinearDiskCache
|
||||
{
|
||||
public:
|
||||
// return number of read entries
|
||||
u32 OpenAndRead(const char *filename, LinearDiskCacheReader<K, V> &reader)
|
||||
{
|
||||
using std::ios_base;
|
||||
|
||||
// close any currently opened file
|
||||
Close();
|
||||
m_num_entries = 0;
|
||||
|
||||
// try opening for reading/writing
|
||||
m_file.open(filename, ios_base::in | ios_base::out | ios_base::binary);
|
||||
|
||||
m_file.seekg(0, std::ios::end);
|
||||
std::fstream::pos_type end_pos = m_file.tellg();
|
||||
m_file.seekg(0, std::ios::beg);
|
||||
std::fstream::pos_type start_pos = m_file.tellg();
|
||||
std::streamoff file_size = end_pos - start_pos;
|
||||
|
||||
if (m_file.is_open() && ValidateHeader())
|
||||
{
|
||||
// good header, read some key/value pairs
|
||||
K key;
|
||||
|
||||
V *value = NULL;
|
||||
u32 value_size;
|
||||
u32 entry_number;
|
||||
|
||||
std::fstream::pos_type last_pos = m_file.tellg();
|
||||
|
||||
while (Read(&value_size))
|
||||
{
|
||||
std::streamoff next_extent = (last_pos - start_pos) + sizeof(value_size) + value_size;
|
||||
if (next_extent > file_size)
|
||||
break;
|
||||
|
||||
delete[] value;
|
||||
value = new V[value_size];
|
||||
|
||||
// read key/value and pass to reader
|
||||
if (Read(&key) &&
|
||||
Read(value, value_size) &&
|
||||
Read(&entry_number) &&
|
||||
entry_number == m_num_entries+1)
|
||||
{
|
||||
reader.Read(key, value, value_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
m_num_entries++;
|
||||
last_pos = m_file.tellg();
|
||||
}
|
||||
m_file.seekp(last_pos);
|
||||
m_file.clear();
|
||||
|
||||
delete[] value;
|
||||
return m_num_entries;
|
||||
}
|
||||
|
||||
// failed to open file for reading or bad header
|
||||
// close and recreate file
|
||||
Close();
|
||||
m_file.open(filename, ios_base::out | ios_base::trunc | ios_base::binary);
|
||||
WriteHeader();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sync()
|
||||
{
|
||||
m_file.flush();
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
if (m_file.is_open())
|
||||
m_file.close();
|
||||
// clear any error flags
|
||||
m_file.clear();
|
||||
}
|
||||
|
||||
// Appends a key-value pair to the store.
|
||||
void Append(const K &key, const V *value, u32 value_size)
|
||||
{
|
||||
// TODO: Should do a check that we don't already have "key"? (I think each caller does that already.)
|
||||
Write(&value_size);
|
||||
Write(&key);
|
||||
Write(value, value_size);
|
||||
m_num_entries++;
|
||||
Write(&m_num_entries);
|
||||
}
|
||||
|
||||
private:
|
||||
void WriteHeader()
|
||||
{
|
||||
Write(&m_header);
|
||||
}
|
||||
|
||||
bool ValidateHeader()
|
||||
{
|
||||
char file_header[sizeof(Header)];
|
||||
|
||||
return (Read(file_header, sizeof(Header))
|
||||
&& !memcmp((const char*)&m_header, file_header, sizeof(Header)));
|
||||
}
|
||||
|
||||
template <typename D>
|
||||
bool Write(const D *data, u32 count = 1)
|
||||
{
|
||||
return m_file.write((const char*)data, count * sizeof(D)).good();
|
||||
}
|
||||
|
||||
template <typename D>
|
||||
bool Read(const D *data, u32 count = 1)
|
||||
{
|
||||
return m_file.read((char*)data, count * sizeof(D)).good();
|
||||
}
|
||||
|
||||
struct Header
|
||||
{
|
||||
Header()
|
||||
: id(*(u32*)"DCAC")
|
||||
, ver(LINEAR_DISKCACHE_VER)
|
||||
, key_t_size(sizeof(K))
|
||||
, value_t_size(sizeof(V))
|
||||
{}
|
||||
|
||||
const u32 id, ver;
|
||||
const u16 key_t_size, value_t_size;
|
||||
|
||||
} m_header;
|
||||
|
||||
std::fstream m_file;
|
||||
u32 m_num_entries;
|
||||
};
|
||||
|
||||
#endif // _LINEAR_DISKCACHE
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "LogManager.h"
|
||||
#include "ConsoleListener.h"
|
||||
#include "Timer.h"
|
||||
#include "Thread.h"
|
||||
#include "FileUtil.h"
|
||||
#include "../Core/Config.h"
|
||||
#ifdef __SYMBIAN32__
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "file/ini_file.h"
|
||||
|
||||
#include <set>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_MESSAGES 8000
|
||||
#define MAX_MSGLEN 1024
|
||||
|
||||
@@ -15,257 +15,8 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "MathUtil.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <numeric>
|
||||
|
||||
namespace {
|
||||
#ifdef USE_SSE
|
||||
static u32 saved_sse_state = _mm_getcsr();
|
||||
static const u32 default_sse_state = _mm_getcsr();
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace MathUtil
|
||||
{
|
||||
|
||||
u32 ClassifyDouble(double dvalue)
|
||||
{
|
||||
// TODO: Optimize the below to be as fast as possible.
|
||||
IntDouble value;
|
||||
value.d = dvalue;
|
||||
u64 sign = value.i & DOUBLE_SIGN;
|
||||
u64 exp = value.i & DOUBLE_EXP;
|
||||
if (exp > DOUBLE_ZERO && exp < DOUBLE_EXP)
|
||||
{
|
||||
// Nice normalized number.
|
||||
return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
|
||||
}
|
||||
else
|
||||
{
|
||||
u64 mantissa = value.i & DOUBLE_FRAC;
|
||||
if (mantissa)
|
||||
{
|
||||
if (exp)
|
||||
{
|
||||
return PPC_FPCLASS_QNAN;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Denormalized number.
|
||||
return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
|
||||
}
|
||||
}
|
||||
else if (exp)
|
||||
{
|
||||
//Infinite
|
||||
return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Zero
|
||||
return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 ClassifyFloat(float fvalue)
|
||||
{
|
||||
// TODO: Optimize the below to be as fast as possible.
|
||||
IntFloat value;
|
||||
value.f = fvalue;
|
||||
u32 sign = value.i & FLOAT_SIGN;
|
||||
u32 exp = value.i & FLOAT_EXP;
|
||||
if (exp > FLOAT_ZERO && exp < FLOAT_EXP)
|
||||
{
|
||||
// Nice normalized number.
|
||||
return sign ? PPC_FPCLASS_NN : PPC_FPCLASS_PN;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 mantissa = value.i & FLOAT_FRAC;
|
||||
if (mantissa)
|
||||
{
|
||||
if (exp)
|
||||
{
|
||||
return PPC_FPCLASS_QNAN; // Quiet NAN
|
||||
}
|
||||
else
|
||||
{
|
||||
// Denormalized number.
|
||||
return sign ? PPC_FPCLASS_ND : PPC_FPCLASS_PD;
|
||||
}
|
||||
}
|
||||
else if (exp)
|
||||
{
|
||||
// Infinite
|
||||
return sign ? PPC_FPCLASS_NINF : PPC_FPCLASS_PINF;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Zero
|
||||
return sign ? PPC_FPCLASS_NZ : PPC_FPCLASS_PZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
void LoadDefaultSSEState()
|
||||
{
|
||||
#ifdef USE_SSE
|
||||
_mm_setcsr(default_sse_state);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void LoadSSEState()
|
||||
{
|
||||
#ifdef USE_SSE
|
||||
_mm_setcsr(saved_sse_state);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void SaveSSEState()
|
||||
{
|
||||
#ifdef USE_SSE
|
||||
saved_sse_state = _mm_getcsr();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void MatrixMul(int n, const float *a, const float *b, float *result)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
for (int j = 0; j < n; ++j)
|
||||
{
|
||||
float temp = 0;
|
||||
for (int k = 0; k < n; ++k)
|
||||
{
|
||||
temp += a[i * n + k] * b[k * n + j];
|
||||
}
|
||||
result[i * n + j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate sum of a float list
|
||||
float MathFloatVectorSum(const std::vector<float>& Vec)
|
||||
{
|
||||
return std::accumulate(Vec.begin(), Vec.end(), 0.0f);
|
||||
}
|
||||
|
||||
void Matrix33::LoadIdentity(Matrix33 &mtx)
|
||||
{
|
||||
memset(mtx.data, 0, sizeof(mtx.data));
|
||||
mtx.data[0] = 1.0f;
|
||||
mtx.data[4] = 1.0f;
|
||||
mtx.data[8] = 1.0f;
|
||||
}
|
||||
|
||||
void Matrix33::RotateX(Matrix33 &mtx, float rad)
|
||||
{
|
||||
float s = sin(rad);
|
||||
float c = cos(rad);
|
||||
memset(mtx.data, 0, sizeof(mtx.data));
|
||||
mtx.data[0] = 1;
|
||||
mtx.data[4] = c;
|
||||
mtx.data[5] = -s;
|
||||
mtx.data[7] = s;
|
||||
mtx.data[8] = c;
|
||||
}
|
||||
void Matrix33::RotateY(Matrix33 &mtx, float rad)
|
||||
{
|
||||
float s = sin(rad);
|
||||
float c = cos(rad);
|
||||
memset(mtx.data, 0, sizeof(mtx.data));
|
||||
mtx.data[0] = c;
|
||||
mtx.data[2] = s;
|
||||
mtx.data[4] = 1;
|
||||
mtx.data[6] = -s;
|
||||
mtx.data[8] = c;
|
||||
}
|
||||
|
||||
void Matrix33::Multiply(const Matrix33 &a, const Matrix33 &b, Matrix33 &result)
|
||||
{
|
||||
MatrixMul(3, a.data, b.data, result.data);
|
||||
}
|
||||
|
||||
void Matrix33::Multiply(const Matrix33 &a, const float vec[3], float result[3])
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
result[i] = 0;
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
result[i] += a.data[i * 3 + k] * vec[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix44::LoadIdentity(Matrix44 &mtx)
|
||||
{
|
||||
memset(mtx.data, 0, sizeof(mtx.data));
|
||||
mtx.data[0] = 1.0f;
|
||||
mtx.data[5] = 1.0f;
|
||||
mtx.data[10] = 1.0f;
|
||||
mtx.data[15] = 1.0f;
|
||||
}
|
||||
|
||||
void Matrix44::LoadMatrix33(Matrix44 &mtx, const Matrix33 &m33)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
mtx.data[i * 4 + j] = m33.data[i * 3 + j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
mtx.data[i * 4 + 3] = 0;
|
||||
mtx.data[i + 12] = 0;
|
||||
}
|
||||
mtx.data[15] = 1.0f;
|
||||
}
|
||||
|
||||
void Matrix44::Set(Matrix44 &mtx, const float mtxArray[16])
|
||||
{
|
||||
for(int i = 0; i < 16; ++i)
|
||||
{
|
||||
mtx.data[i] = mtxArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix44::Translate(Matrix44 &mtx, const float vec[3])
|
||||
{
|
||||
LoadIdentity(mtx);
|
||||
mtx.data[3] = vec[0];
|
||||
mtx.data[7] = vec[1];
|
||||
mtx.data[11] = vec[2];
|
||||
}
|
||||
|
||||
void Matrix44::Multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &result)
|
||||
{
|
||||
MatrixMul(4, a.data, b.data, result.data);
|
||||
}
|
||||
|
||||
int Pow2roundup(int x)
|
||||
{
|
||||
if (x < 0)
|
||||
return 0;
|
||||
--x;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
return x+1;
|
||||
}
|
||||
|
||||
int GetPow2(int x)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -18,192 +18,6 @@
|
||||
#ifndef _MATH_UTIL_H_
|
||||
#define _MATH_UTIL_H_
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#if !defined(ARM) && !defined(MIPS)
|
||||
#define USE_SSE
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSE
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace MathUtil
|
||||
{
|
||||
|
||||
static const u64 DOUBLE_SIGN = 0x8000000000000000ULL,
|
||||
DOUBLE_EXP = 0x7FF0000000000000ULL,
|
||||
DOUBLE_FRAC = 0x000FFFFFFFFFFFFFULL,
|
||||
DOUBLE_ZERO = 0x0000000000000000ULL;
|
||||
|
||||
static const u32 FLOAT_SIGN = 0x80000000,
|
||||
FLOAT_EXP = 0x7F800000,
|
||||
FLOAT_FRAC = 0x007FFFFF,
|
||||
FLOAT_ZERO = 0x00000000;
|
||||
|
||||
union IntDouble {
|
||||
double d;
|
||||
u64 i;
|
||||
};
|
||||
union IntFloat {
|
||||
float f;
|
||||
u32 i;
|
||||
};
|
||||
|
||||
inline bool IsNAN(double d)
|
||||
{
|
||||
IntDouble x; x.d = d;
|
||||
return ( ((x.i & DOUBLE_EXP) == DOUBLE_EXP) &&
|
||||
((x.i & DOUBLE_FRAC) != DOUBLE_ZERO) );
|
||||
}
|
||||
|
||||
inline bool IsQNAN(double d)
|
||||
{
|
||||
IntDouble x; x.d = d;
|
||||
return ( ((x.i & DOUBLE_EXP) == DOUBLE_EXP) &&
|
||||
((x.i & 0x0007fffffffffffULL) == 0x000000000000000ULL) &&
|
||||
((x.i & 0x000800000000000ULL) == 0x000800000000000ULL) );
|
||||
}
|
||||
|
||||
inline bool IsSNAN(double d)
|
||||
{
|
||||
IntDouble x; x.d = d;
|
||||
return( ((x.i & DOUBLE_EXP) == DOUBLE_EXP) &&
|
||||
((x.i & DOUBLE_FRAC) != DOUBLE_ZERO) &&
|
||||
((x.i & 0x0008000000000000ULL) == DOUBLE_ZERO) );
|
||||
}
|
||||
|
||||
inline float FlushToZero(float f)
|
||||
{
|
||||
IntFloat x; x.f = f;
|
||||
if ((x.i & FLOAT_EXP) == 0)
|
||||
x.i &= FLOAT_SIGN; // turn into signed zero
|
||||
return x.f;
|
||||
}
|
||||
|
||||
inline double FlushToZeroAsFloat(double d)
|
||||
{
|
||||
IntDouble x; x.d = d;
|
||||
if ((x.i & DOUBLE_EXP) < 0x3800000000000000ULL)
|
||||
x.i &= DOUBLE_SIGN; // turn into signed zero
|
||||
return x.d;
|
||||
}
|
||||
|
||||
enum PPCFpClass
|
||||
{
|
||||
PPC_FPCLASS_QNAN = 0x11,
|
||||
PPC_FPCLASS_NINF = 0x9,
|
||||
PPC_FPCLASS_NN = 0x8,
|
||||
PPC_FPCLASS_ND = 0x18,
|
||||
PPC_FPCLASS_NZ = 0x12,
|
||||
PPC_FPCLASS_PZ = 0x2,
|
||||
PPC_FPCLASS_PD = 0x14,
|
||||
PPC_FPCLASS_PN = 0x4,
|
||||
PPC_FPCLASS_PINF = 0x5,
|
||||
};
|
||||
|
||||
// Uses PowerPC conventions for the return value, so it can be easily
|
||||
// used directly in CPU emulation.
|
||||
u32 ClassifyDouble(double dvalue);
|
||||
// More efficient float version.
|
||||
u32 ClassifyFloat(float fvalue);
|
||||
|
||||
template<class T>
|
||||
struct Rectangle
|
||||
{
|
||||
T left;
|
||||
T top;
|
||||
T right;
|
||||
T bottom;
|
||||
|
||||
Rectangle()
|
||||
{ }
|
||||
|
||||
Rectangle(T theLeft, T theTop, T theRight, T theBottom)
|
||||
: left(theLeft), top(theTop), right(theRight), bottom(theBottom)
|
||||
{ }
|
||||
|
||||
T GetWidth() const { return abs(right - left); }
|
||||
T GetHeight() const { return abs(bottom - top); }
|
||||
|
||||
// If the rectangle is in a coordinate system with a lower-left origin, use
|
||||
// this Clamp.
|
||||
void ClampLL(T x1, T y1, T x2, T y2)
|
||||
{
|
||||
if (left < x1) left = x1;
|
||||
if (right > x2) right = x2;
|
||||
if (top > y1) top = y1;
|
||||
if (bottom < y2) bottom = y2;
|
||||
}
|
||||
|
||||
// If the rectangle is in a coordinate system with an upper-left origin,
|
||||
// use this Clamp.
|
||||
void ClampUL(T x1, T y1, T x2, T y2)
|
||||
{
|
||||
if (left < x1) left = x1;
|
||||
if (right > x2) right = x2;
|
||||
if (top < y1) top = y1;
|
||||
if (bottom > y2) bottom = y2;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace MathUtil
|
||||
|
||||
inline float pow2f(float x) {return x * x;}
|
||||
inline double pow2(double x) {return x * x;}
|
||||
int Pow2roundup(int x);
|
||||
int GetPow2(int x);
|
||||
|
||||
|
||||
/*
|
||||
There are two different flavors of float to int conversion:
|
||||
_mm_cvtps_epi32() and _mm_cvttps_epi32(). The first rounds
|
||||
according to the MXCSR rounding bits. The second one always
|
||||
uses round towards zero.
|
||||
*/
|
||||
|
||||
void SaveSSEState();
|
||||
void LoadSSEState();
|
||||
void LoadDefaultSSEState();
|
||||
float MathFloatVectorSum(const std::vector<float>&);
|
||||
|
||||
#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
#define ROUND_DOWN(x, a) ((x) & ~((a) - 1))
|
||||
|
||||
// Tiny matrix/vector library.
|
||||
// Used for things like Free-Look in the gfx backend.
|
||||
|
||||
class Matrix33
|
||||
{
|
||||
public:
|
||||
static void LoadIdentity(Matrix33 &mtx);
|
||||
|
||||
// set mtx to be a rotation matrix around the x axis
|
||||
static void RotateX(Matrix33 &mtx, float rad);
|
||||
// set mtx to be a rotation matrix around the y axis
|
||||
static void RotateY(Matrix33 &mtx, float rad);
|
||||
|
||||
// set result = a x b
|
||||
static void Multiply(const Matrix33 &a, const Matrix33 &b, Matrix33 &result);
|
||||
static void Multiply(const Matrix33 &a, const float vec[3], float result[3]);
|
||||
|
||||
float data[9];
|
||||
};
|
||||
|
||||
class Matrix44
|
||||
{
|
||||
public:
|
||||
static void LoadIdentity(Matrix44 &mtx);
|
||||
static void LoadMatrix33(Matrix44 &mtx, const Matrix33 &m33);
|
||||
static void Set(Matrix44 &mtx, const float mtxArray[16]);
|
||||
|
||||
static void Translate(Matrix44 &mtx, const float vec[3]);
|
||||
|
||||
static void Multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &result);
|
||||
|
||||
float data[16];
|
||||
};
|
||||
|
||||
#endif // _MATH_UTIL_H_
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
|
||||
#include <stdio.h> // System
|
||||
|
||||
#include "Common.h" // Local
|
||||
#include "StringUtils.h"
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#ifndef _SETUP_H_
|
||||
#define _SETUP_H_
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// File description:
|
||||
// Compilation settings. I avoid placing this in Common.h or some place where lots of files needs
|
||||
// to be rebuilt if any of these settings are changed. I'd rather have it in as few files as possible.
|
||||
// This file can be kept on the ignore list in your SVN program. It allows local optional settings
|
||||
// depending on what works on your computer.
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// Settings:
|
||||
|
||||
// This may remove sound artifacts in Wario Land Shake It and perhaps other games
|
||||
//#define SETUP_AVOID_SOUND_ARTIFACTS
|
||||
|
||||
// Build with playback rerecording options
|
||||
//#define RERECORDING
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
|
||||
#endif // _SETUP_H_
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "CommonPaths.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
long parseHexLong(std::string s) {
|
||||
@@ -88,16 +84,4 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
|
||||
*_pExtension = full_path.substr(fname_end);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, const std::string& _Filename)
|
||||
{
|
||||
_CompleteFilename = _Path;
|
||||
|
||||
// check for seperator
|
||||
if (!strchr(DIR_SEP_CHRS, *_CompleteFilename.rbegin()))
|
||||
_CompleteFilename += DIR_SEP;
|
||||
|
||||
// add the filename
|
||||
_CompleteFilename += _Filename;
|
||||
}
|
||||
@@ -52,11 +52,7 @@ std::string ThousandSeparate(I value, int spaces = 0)
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string TabsToSpaces(int tab_size, const std::string &in);
|
||||
|
||||
// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe"
|
||||
bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension);
|
||||
|
||||
void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, const std::string& _Filename);
|
||||
|
||||
#endif // _STRINGUTIL_H_
|
||||
@@ -15,7 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Setup.h"
|
||||
#include "Thread.h"
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#define _THREAD_H_
|
||||
|
||||
#include "StdThread.h"
|
||||
#include "StdMutex.h"
|
||||
#include "StdConditionVariable.h"
|
||||
|
||||
// Don't include common.h here as it will break LogManager
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "Common.h"
|
||||
#include "x64Emitter.h"
|
||||
#include "MemoryUtil.h"
|
||||
#include "ABI.h"
|
||||
#include "Thunk.h"
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "Common.h"
|
||||
#include "Timer.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// 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/
|
||||
|
||||
#include "Common.h"
|
||||
#include "scmrev.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define BUILD_TYPE_STR "Debug "
|
||||
#elif defined DEBUGFAST
|
||||
#define BUILD_TYPE_STR "DebugFast "
|
||||
#else
|
||||
#define BUILD_TYPE_STR ""
|
||||
#endif
|
||||
|
||||
const char *scm_rev_str = "Dolphin "
|
||||
#if !SCM_IS_MASTER
|
||||
"[" SCM_BRANCH_STR "] "
|
||||
#endif
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
BUILD_TYPE_STR SCM_DESC_STR "-ICC";
|
||||
#else
|
||||
BUILD_TYPE_STR SCM_DESC_STR;
|
||||
#endif
|
||||
|
||||
#ifdef _M_X64
|
||||
#define NP_ARCH "x64"
|
||||
#else
|
||||
#define NP_ARCH "x86"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
const char *netplay_dolphin_ver = SCM_DESC_STR " W" NP_ARCH;
|
||||
#elif __APPLE__
|
||||
const char *netplay_dolphin_ver = SCM_DESC_STR " M" NP_ARCH;
|
||||
#else
|
||||
const char *netplay_dolphin_ver = SCM_DESC_STR " L" NP_ARCH;
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
#define SCM_REV_STR "722480cb2e864ea7dd03427e509470ec09ce6f40"
|
||||
#define SCM_DESC_STR "3.0-589-dirty"
|
||||
#define SCM_BRANCH_STR "master"
|
||||
#define SCM_IS_MASTER 1
|
||||
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Including SDKDDKVer.h defines the highest available Windows platform.
|
||||
|
||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||
|
||||
#include <SDKDDKVer.h>
|
||||
@@ -15,7 +15,6 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include "x64Emitter.h"
|
||||
#include "ABI.h"
|
||||
#include "CPUDetect.h"
|
||||
|
||||
@@ -30,11 +30,7 @@ win32 {
|
||||
}
|
||||
|
||||
SOURCES += ../Common/ConsoleListener.cpp \
|
||||
../Common/ExtendedTrace.cpp \
|
||||
../Common/FPURoundModeGeneric.cpp \
|
||||
../Common/FileSearch.cpp \
|
||||
../Common/FileUtil.cpp \
|
||||
../Common/Hash.cpp \
|
||||
../Common/LogManager.cpp \
|
||||
../Common/KeyMap.cpp \
|
||||
../Common/MathUtil.cpp \
|
||||
@@ -46,14 +42,10 @@ SOURCES += ../Common/ConsoleListener.cpp \
|
||||
../Common/Thread.cpp \
|
||||
../Common/ThreadPools.cpp \
|
||||
../Common/Timer.cpp \
|
||||
../Common/Version.cpp \
|
||||
../Common/Crypto/*.cpp
|
||||
HEADERS += ../Common/ChunkFile.h \
|
||||
../Common/ConsoleListener.h \
|
||||
../Common/ExtendedTrace.h \
|
||||
../Common/FileSearch.h \
|
||||
../Common/FileUtil.h \
|
||||
../Common/Hash.h \
|
||||
../Common/LogManager.h \
|
||||
../Common/KeyMap.h \
|
||||
../Common/MathUtil.h \
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "headless/Compare.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "file/file_util.h"
|
||||
#include "Core/Host.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -250,7 +250,7 @@ bool CompareOutput(const std::string &bootFilename, const std::string &output, b
|
||||
printf("%s", output.c_str());
|
||||
printf("============== expected output:\n");
|
||||
std::string fullExpected;
|
||||
if (File::ReadFileToString(true, expect_filename.c_str(), fullExpected))
|
||||
if (readFileToString(true, expect_filename.c_str(), fullExpected))
|
||||
printf("%s", fullExpected.c_str());
|
||||
printf("===============================\n");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user