This commit is contained in:
twinaphex 2020-09-14 10:15:42 +02:00
parent 4ab8759468
commit 89cc1d6a7f
4 changed files with 80 additions and 95 deletions

View File

@ -3,7 +3,7 @@
#include "mednafen-types.h"
#include "git.h"
#include "settings-driver.h"
#include "settings-common.h"
#include "mednafen-driver.h"
#include "mempatcher-driver.h"

View File

@ -11,51 +11,50 @@
static INLINE uint16 LoadU16_RBO(const uint16 *a)
{
#ifdef ARCH_POWERPC
uint16 tmp;
#ifdef ARCH_POWERPC
uint16 tmp;
__asm__ ("lhbrx %0, %y1" : "=r"(tmp) : "Z"(*a));
__asm__ ("lhbrx %0, %y1" : "=r"(tmp) : "Z"(*a));
return(tmp);
return(tmp);
#else
uint16 tmp = *a;
return((tmp << 8) | (tmp >> 8));
#endif
#else
return((*a << 8) | (*a >> 8));
#endif
}
static INLINE uint32 LoadU32_RBO(const uint32 *a)
{
#ifdef ARCH_POWERPC
uint32 tmp;
#ifdef ARCH_POWERPC
uint32 tmp;
__asm__ ("lwbrx %0, %y1" : "=r"(tmp) : "Z"(*a));
__asm__ ("lwbrx %0, %y1" : "=r"(tmp) : "Z"(*a));
return(tmp);
#else
uint32 tmp = *a;
return((tmp << 24) | ((tmp & 0xFF00) << 8) | ((tmp >> 8) & 0xFF00) | (tmp >> 24));
#endif
return(tmp);
#else
uint32 tmp = *a;
return((tmp << 24) | ((tmp & 0xFF00) << 8) | ((tmp >> 8) & 0xFF00) | (tmp >> 24));
#endif
}
static INLINE void StoreU16_RBO(uint16 *a, const uint16 v)
{
#ifdef ARCH_POWERPC
__asm__ ("sthbrx %0, %y1" : : "r"(v), "Z"(*a));
#else
uint16 tmp = (v << 8) | (v >> 8);
*a = tmp;
#endif
#ifdef ARCH_POWERPC
__asm__ ("sthbrx %0, %y1" : : "r"(v), "Z"(*a));
#else
uint16 tmp = (v << 8) | (v >> 8);
*a = tmp;
#endif
}
static INLINE void StoreU32_RBO(uint32 *a, const uint32 v)
{
#ifdef ARCH_POWERPC
__asm__ ("stwbrx %0, %y1" : : "r"(v), "Z"(*a));
#else
uint32 tmp = (v << 24) | ((v & 0xFF00) << 8) | ((v >> 8) & 0xFF00) | (v >> 24);
*a = tmp;
#endif
#ifdef ARCH_POWERPC
__asm__ ("stwbrx %0, %y1" : : "r"(v), "Z"(*a));
#else
uint32 tmp = (v << 24) | ((v & 0xFF00) << 8) | ((v >> 8) & 0xFF00) | (v >> 24);
*a = tmp;
#endif
}
static INLINE uint16 LoadU16_LE(const uint16 *a)
@ -79,18 +78,18 @@ static INLINE uint32 LoadU32_LE(const uint32 *a)
static INLINE void StoreU16_LE(uint16 *a, const uint16 v)
{
#ifdef MSB_FIRST
StoreU16_RBO(a, v);
StoreU16_RBO(a, v);
#else
*a = v;
*a = v;
#endif
}
static INLINE void StoreU32_LE(uint32 *a, const uint32 v)
{
#ifdef MSB_FIRST
StoreU32_RBO(a, v);
StoreU32_RBO(a, v);
#else
*a = v;
*a = v;
#endif
}

View File

@ -10,72 +10,72 @@
//
static INLINE unsigned MDFN_lzcount32(uint32 v)
{
#if defined(__GNUC__) || defined(__clang__) || defined(__ICC) || defined(__INTEL_COMPILER)
return v ? __builtin_clz(v) : 32;
#elif defined(_MSC_VER)
unsigned long idx;
#if defined(__GNUC__) || defined(__clang__) || defined(__ICC) || defined(__INTEL_COMPILER)
return v ? __builtin_clz(v) : 32;
#elif defined(_MSC_VER)
unsigned long idx;
if(!v)
return 32;
if(!v)
return 32;
_BitScanReverse(&idx, v);
_BitScanReverse(&idx, v);
return 31 - idx;
#else
unsigned ret = 0;
return 31 - idx;
#else
unsigned ret = 0;
if(!v)
return(32);
if(!v)
return(32);
if(!(v & 0xFFFF0000))
{
v <<= 16;
ret += 16;
}
if(!(v & 0xFFFF0000))
{
v <<= 16;
ret += 16;
}
if(!(v & 0xFF000000))
{
v <<= 8;
ret += 8;
}
if(!(v & 0xFF000000))
{
v <<= 8;
ret += 8;
}
if(!(v & 0xF0000000))
{
v <<= 4;
ret += 4;
}
if(!(v & 0xF0000000))
{
v <<= 4;
ret += 4;
}
if(!(v & 0xC0000000))
{
v <<= 2;
ret += 2;
}
if(!(v & 0xC0000000))
{
v <<= 2;
ret += 2;
}
if(!(v & 0x80000000))
{
v <<= 1;
ret += 1;
}
if(!(v & 0x80000000))
{
v <<= 1;
ret += 1;
}
return(ret);
#endif
return(ret);
#endif
}
// Source: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
// Rounds up to the nearest power of 2.
static INLINE uint32 round_up_pow2(uint32 v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
v += (v == 0);
v += (v == 0);
return(v);
return(v);
}
// Some compilers' optimizers and some platforms might fubar the generated code from these macros,

View File

@ -1,14 +0,0 @@
#ifndef _MDFN_SETTINGS_DRIVER_H
#define _MDFN_SETTINGS_DRIVER_H
#include <boolean.h>
#include "settings-common.h"
bool MDFNI_SetSetting(const char *name, const char *value, bool NetplayOverride = false);
bool MDFNI_SetSettingB(const char *name, bool value);
bool MDFNI_SetSettingUI(const char *name, uint64_t value);
bool MDFNI_DumpSettingsDef(const char *path);
#endif