GregMiscellaneous:

* Buffer overflow (32bits unicode)
* Improve asm mem_cpy qwc (little faster)


git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@3651 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut@gmail.com 2010-08-17 11:47:37 +00:00
parent 9bb6736068
commit 2283ed93ab
2 changed files with 17 additions and 14 deletions

View File

@ -173,11 +173,13 @@ static __ri void format_that_ascii_mess( SafeArray<char>& buffer, uint writepos,
static __ri void format_that_unicode_mess( SafeArray<char>& buffer, uint writepos, const wxChar* fmt, va_list argptr)
{
const int WX_CHAR_SIZE = sizeof(wxChar);
while( true )
{
int size = buffer.GetLength()/2;
int size = buffer.GetLength()/WX_CHAR_SIZE;
int len = wxVsnprintf((wxChar*)buffer.GetPtr(writepos), size-writepos, fmt, argptr);
// some implementations of vsnprintf() don't NUL terminate
// the string if there is not enough space for it so
// always do it manually
@ -194,7 +196,7 @@ static __ri void format_that_unicode_mess( SafeArray<char>& buffer, uint writepo
len += writepos;
if (len < size) break;
buffer.ExactAlloc( (len + 31) * 2 );
buffer.ExactAlloc( (len + 31) * WX_CHAR_SIZE );
};
// performing an assertion or log of a truncated string is unsafe, so let's not; even
@ -233,10 +235,11 @@ FastFormatUnicode::~FastFormatUnicode() throw()
FastFormatUnicode& FastFormatUnicode::WriteV( const char* fmt, va_list argptr )
{
const int WX_CHAR_SIZE = sizeof(wxChar);
wxString converted( fromUTF8(FastFormatAscii().WriteV( fmt, argptr )) );
uint inspos = wxStrlen((wxChar*)m_dest->GetPtr());
m_dest->MakeRoomFor((inspos + converted.Length() + 31)*2);
m_dest->MakeRoomFor((inspos + converted.Length() + 31)*WX_CHAR_SIZE);
wxStrcpy( &((wxChar*)m_dest->GetPtr())[inspos], converted );
return *this;

View File

@ -183,11 +183,11 @@ __fi void memcpy_vibes(void * dest, const void * src, int size) {
__asm__ __volatile__
(
".intel_syntax noprefix\n"
"mov eax, %[qwc]\n" // keep a copy of count for looping
"shr eax, 1\n"
"jz memcpy_qwc_1_%=\n" // only one 16 byte block to copy?
"sub %[qwc], 1\n" // dec the counter to ease the count of 16bytes block later (optimization)
// Note after this line, real value of the counter is %[qwc] + 1
"jle memcpy_qwc_1_%=\n" // only one 16 byte block to copy? Or nothing.
"cmp eax, 64\n" // "IN_CACHE_COPY/32"
"cmp %[qwc], 127\n" // "IN_CACHE_COPY/16"
"jb memcpy_qwc_loop1_%=\n" // small copies should be cached (definite speedup --air)
"memcpy_qwc_loop2_%=:\n" // 32-byte blocks, uncached copy
@ -204,8 +204,8 @@ __fi void memcpy_vibes(void * dest, const void * src, int size) {
"add %[src],32\n" // update source pointer
"add %[dest],32\n" // update destination pointer
"sub eax,1\n"
"jnz memcpy_qwc_loop2_%=\n" // last 64-byte block?
"sub %[qwc],2\n"
"jg memcpy_qwc_loop2_%=\n" // last 64-byte block?
"sfence\n" // flush the write buffer
"jmp memcpy_qwc_1_%=\n"
@ -227,12 +227,12 @@ __fi void memcpy_vibes(void * dest, const void * src, int size) {
"add %[src],32\n" // update source pointer
"add %[dest],32\n" // update destination pointer
"sub eax,1\n"
"jnz memcpy_qwc_loop1_%=\n" // last 64-byte block?
"sub %[qwc],2\n"
"jg memcpy_qwc_loop2_%=\n" // last 64-byte block?
"memcpy_qwc_1_%=:\n"
"test %[qwc],1\n"
"jz memcpy_qwc_final_%=\n"
"cmp %[qwc],0\n"
"jne memcpy_qwc_final_%=\n"
"movq mm0,[%[src]]\n"
"movq mm1,[%[src]+8]\n"
"movq [%[dest]], mm0\n"
@ -243,7 +243,7 @@ __fi void memcpy_vibes(void * dest, const void * src, int size) {
".att_syntax\n"
: "=&r"(dest), "=&r"(src), "=&r"(qwc)
: [dest]"0"(dest), [src]"1"(src), [qwc]"2"(qwc)
: "memory", "eax", "mm0", "mm1", "mm2", "mm3"
: "memory", "mm0", "mm1", "mm2", "mm3"
);
}
#endif