commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
63
include/platform/memory/endian.cpp
Normal file
63
include/platform/memory/endian.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "memory/endian.h"
|
||||
#include "platform_config.h"
|
||||
#include "log/log.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Endian {
|
||||
|
||||
static Config g_host_endian = Undefined;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SwapBytes(void *in_p, size_t n)
|
||||
{
|
||||
if (n == 1)
|
||||
return;
|
||||
|
||||
__ASSERT__(!(n & 1));
|
||||
|
||||
char *p = (char *)in_p;
|
||||
for (size_t c = 0; c < n / 2; ++c)
|
||||
{
|
||||
char tmp = p[c];
|
||||
p[c] = p[n - c - 1];
|
||||
p[n - c - 1] = tmp;
|
||||
}
|
||||
}
|
||||
Config GetHostConfiguration()
|
||||
{
|
||||
if (g_host_endian == Undefined)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint i;
|
||||
char c[4];
|
||||
} bint = { 0x01020304 };
|
||||
|
||||
g_host_endian = bint.c[0] == 1 ? Big : Little;
|
||||
|
||||
if (g_host_endian == Big)
|
||||
__LOG__ << "Memory configuration: Big endian.\n";
|
||||
else __LOG__ << "Memory configuration: Little endian.\n";
|
||||
}
|
||||
return g_host_endian;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void *ToHost(void *p, size_t size, Config source_endian)
|
||||
{
|
||||
if (GetHostConfiguration() != source_endian)
|
||||
SwapBytes(p, size);
|
||||
return p;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
116
include/platform/memory/memory.cpp
Normal file
116
include/platform/memory/memory.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "memory/memory.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
uchar Memory::GetBitCount(int v)
|
||||
{
|
||||
uchar n;
|
||||
for (n = 0; v; ++n)
|
||||
v &= (v - 1);
|
||||
return n;
|
||||
}
|
||||
uchar Memory::GetShiftCount(int v)
|
||||
{
|
||||
uchar n;
|
||||
for (n = 0; !(v & 1) && (n < 32); ++n)
|
||||
v >>= 1;
|
||||
return n;
|
||||
}
|
||||
uchar Memory::CountSetBit(int v)
|
||||
{
|
||||
uchar count = 0;
|
||||
for (int n = 0; n < 32; ++n)
|
||||
{
|
||||
count += v & 1;
|
||||
v >>= 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Memory::WriteBit(uchar *mem , uint bitoffset, uint bitcount, uint v)
|
||||
{
|
||||
mem += bitoffset >> 3;
|
||||
bitoffset &= 7;
|
||||
|
||||
while (bitcount--)
|
||||
{
|
||||
mem[0] |= ((v >> bitcount) & 1) << bitoffset;
|
||||
|
||||
if (bitoffset == 7)
|
||||
{
|
||||
bitoffset = 0;
|
||||
mem++;
|
||||
}
|
||||
else
|
||||
++bitoffset;
|
||||
}
|
||||
}
|
||||
uint Memory::ReadBit(uchar *base, uint offsetbit, uint nbit)
|
||||
{
|
||||
base += offsetbit >> 3;
|
||||
offsetbit &= 7;
|
||||
|
||||
uint v = 0;
|
||||
while (nbit--)
|
||||
{
|
||||
v += v;
|
||||
if (base[0] & (1 << offsetbit))
|
||||
v |= 1;
|
||||
if (offsetbit == 7) {offsetbit = 0; base++;} else offsetbit++;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Memory::Compare(const void *a, const void *b, size_t n)
|
||||
{
|
||||
if (!a || !b)
|
||||
return true;
|
||||
|
||||
// 8 bit padding.
|
||||
uchar *ba = (uchar *)a, *bb = (uchar *)b;
|
||||
for (uint c = n & 3; c; --c)
|
||||
if (*ba++ != *bb++)
|
||||
return true;
|
||||
|
||||
// 32 bit compare.
|
||||
uint *la = (uint *)ba, *lb = (uint *)bb;
|
||||
for (uint l = n >> 2; l; --l)
|
||||
if (*la++ != *lb++)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
void Memory::Copy(void *d, const void *s, size_t n)
|
||||
{ memcpy(d, s, n); }
|
||||
void Memory::Set(void *a, char v, size_t s)
|
||||
{ memset(a, v, s); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Memory::Fill(void *p, const char *pattern, size_t s)
|
||||
{
|
||||
size_t p_l = 0;
|
||||
for ( ; pattern[p_l] != 0; ++p_l) {}
|
||||
|
||||
char *out = (char *)p;
|
||||
for (; s >= p_l; s -= p_l)
|
||||
{
|
||||
Copy((void *)out, pattern, p_l);
|
||||
out += p_l;
|
||||
}
|
||||
Copy((void *)out, pattern, s);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user