commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
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