diff --git a/common/build/Utilities/utilities.vcxproj b/common/build/Utilities/utilities.vcxproj index f621e3db21..69bd5b5e98 100644 --- a/common/build/Utilities/utilities.vcxproj +++ b/common/build/Utilities/utilities.vcxproj @@ -95,7 +95,6 @@ - @@ -196,4 +195,4 @@ - \ No newline at end of file + diff --git a/common/build/Utilities/utilities.vcxproj.filters b/common/build/Utilities/utilities.vcxproj.filters index d27c7ccf93..d37d0f1308 100644 --- a/common/build/Utilities/utilities.vcxproj.filters +++ b/common/build/Utilities/utilities.vcxproj.filters @@ -23,9 +23,6 @@ - - Source Files - Source Files @@ -228,4 +225,4 @@ Source Files\Linux - \ No newline at end of file + diff --git a/common/build/Utilities/utilities_vs2012.vcxproj b/common/build/Utilities/utilities_vs2012.vcxproj index 5ce5bdca18..b991aac030 100644 --- a/common/build/Utilities/utilities_vs2012.vcxproj +++ b/common/build/Utilities/utilities_vs2012.vcxproj @@ -99,7 +99,6 @@ - @@ -200,4 +199,4 @@ - \ No newline at end of file + diff --git a/common/build/Utilities/utilities_vs2012.vcxproj.filters b/common/build/Utilities/utilities_vs2012.vcxproj.filters index d27c7ccf93..d37d0f1308 100644 --- a/common/build/Utilities/utilities_vs2012.vcxproj.filters +++ b/common/build/Utilities/utilities_vs2012.vcxproj.filters @@ -23,9 +23,6 @@ - - Source Files - Source Files @@ -228,4 +225,4 @@ Source Files\Linux - \ No newline at end of file + diff --git a/common/build/Utilities/utilities_vs2013.vcxproj b/common/build/Utilities/utilities_vs2013.vcxproj index 74d5a82243..621c47c779 100644 --- a/common/build/Utilities/utilities_vs2013.vcxproj +++ b/common/build/Utilities/utilities_vs2013.vcxproj @@ -99,7 +99,6 @@ - @@ -200,4 +199,4 @@ - \ No newline at end of file + diff --git a/common/build/Utilities/utilities_vs2013.vcxproj.filters b/common/build/Utilities/utilities_vs2013.vcxproj.filters index 7d2d5e84a3..1bc92b68ab 100644 --- a/common/build/Utilities/utilities_vs2013.vcxproj.filters +++ b/common/build/Utilities/utilities_vs2013.vcxproj.filters @@ -23,9 +23,6 @@ - - Source Files - Source Files @@ -228,4 +225,4 @@ Source Files\Linux - \ No newline at end of file + diff --git a/common/include/Utilities/General.h b/common/include/Utilities/General.h index 54e0afd373..a1a37997f8 100644 --- a/common/include/Utilities/General.h +++ b/common/include/Utilities/General.h @@ -235,7 +235,7 @@ namespace HostSys extern void MemProtect( void* baseaddr, size_t size, const PageProtectionMode& mode ); - extern void Munmap( void* base, size_t size ); + extern void Munmap( void* base, size_t size ) { Munmap( (uptr)base, size); } template< uint size > void MemProtectStatic( u8 (&arr)[size], const PageProtectionMode& mode ) diff --git a/common/include/Utilities/HashMap.h b/common/include/Utilities/HashMap.h index 808138e4c7..cf28157252 100644 --- a/common/include/Utilities/HashMap.h +++ b/common/include/Utilities/HashMap.h @@ -15,8 +15,6 @@ #pragma once -#include - namespace HashTools { /// diff --git a/common/include/Utilities/MemcpyFast.h b/common/include/Utilities/MemcpyFast.h index 837554953d..c81572311a 100644 --- a/common/include/Utilities/MemcpyFast.h +++ b/common/include/Utilities/MemcpyFast.h @@ -35,9 +35,6 @@ #endif -// Only used in the Windows version of memzero.h. But it's in Misc.cpp for some reason. -void _memset16_unaligned( void* dest, u16 data, size_t size ); - // MemcpyVibes.cpp functions extern void memcpy_vibes(void * dest, const void * src, int size); extern void gen_memcpy_vibes(); diff --git a/common/include/Utilities/RedtapeWindows.h b/common/include/Utilities/RedtapeWindows.h index 6b07c66d2d..4a686052ba 100644 --- a/common/include/Utilities/RedtapeWindows.h +++ b/common/include/Utilities/RedtapeWindows.h @@ -31,7 +31,7 @@ #ifdef _WIN32 -// Force availability of to WinNT APIs (change to 0x600 to enable XP-specific APIs) +// Force availability of to WinNT APIs (change to 0x600 to disable XP-specific APIs) #ifndef WINVER #define WINVER 0x0501 #define _WIN32_WINNT 0x0501 diff --git a/common/include/Utilities/ScopedAlloc.h b/common/include/Utilities/ScopedAlloc.h index 9437495e19..98d01459a5 100644 --- a/common/include/Utilities/ScopedAlloc.h +++ b/common/include/Utilities/ScopedAlloc.h @@ -48,16 +48,31 @@ #define safe_aligned_free( ptr ) \ ((void) ( _aligned_free( ptr ), (ptr) = NULL )) +#if !defined(_MSC_VER) +// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15) +static __forceinline void* _aligned_malloc(size_t size, size_t alignment) { + void *result=0; + posix_memalign(&result, alignment, size); + return result; +} -extern void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align); -extern void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align); -extern void pcsx2_aligned_free(void* pmem); +void* __fastcall _aligned_realloc(void* handle, size_t size, size_t align) +{ + pxAssert( align < 0x10000 ); -// aligned_malloc: Implement/declare linux equivalents here! -#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC) -# define _aligned_malloc pcsx2_aligned_malloc -# define _aligned_free pcsx2_aligned_free -# define _aligned_realloc pcsx2_aligned_realloc + void* newbuf = _aligned_malloc( size, align ); + + if( handle != NULL ) + { + memcpy_fast( newbuf, handle, size ); + free( handle ); + } + return newbuf; +} + +static __forceinline void _aligned_free(void* p) { + free(p); +} #endif // -------------------------------------------------------------------------------------- diff --git a/common/include/Utilities/StringHelpers.h b/common/include/Utilities/StringHelpers.h index f3e19fb2d4..c2c82a9277 100644 --- a/common/include/Utilities/StringHelpers.h +++ b/common/include/Utilities/StringHelpers.h @@ -250,6 +250,3 @@ extern void ssprintf(std::string& dest, const char* fmt, ...); extern void ssappendf(std::string& dest, const char* format, ...); extern void vssprintf(std::string& dest, const char* format, va_list args); extern void vssappendf(std::string& dest, const char* format, va_list args); - -extern std::string fmt_string( const char* fmt, ... ); -extern std::string vfmt_string( const char* fmt, va_list args ); diff --git a/common/include/Utilities/lnx_memzero.h b/common/include/Utilities/lnx_memzero.h index c7dba5a76b..1366379165 100644 --- a/common/include/Utilities/lnx_memzero.h +++ b/common/include/Utilities/lnx_memzero.h @@ -16,8 +16,7 @@ #ifndef _LNX_MEMZERO_H_ #define _LNX_MEMZERO_H_ -// This header contains non-optimized implementation of memzero_ptr and memset8, -// memset16, etc. +// This header contains non-optimized implementation of memzero_ptr and memset8, etc template< u32 data, typename T > static __fi void memset32( T& obj ) @@ -57,18 +56,6 @@ static __fi void memset8( T& obj ) } } -template< u16 data, typename T > -static __fi void memset16( T& obj ) -{ - if( (sizeof(T) & 0x3) != 0 ) - _memset16_unaligned( &obj, data, sizeof( T ) ); - else { - const u32 data32 = data + (data<<16); - memset32( obj ); - } -} - - // An optimized memset for 8 bit destination data. template< u8 data, size_t bytes > static __fi void memset_8( void *dest ) diff --git a/common/include/Utilities/win_memzero.h b/common/include/Utilities/win_memzero.h index a941032a3c..d9e8d12188 100644 --- a/common/include/Utilities/win_memzero.h +++ b/common/include/Utilities/win_memzero.h @@ -373,94 +373,6 @@ static __fi void memset_8( void *dest ) } } -template< u16 data, size_t _bytes > -static __fi void memset_16( void *dest ) -{ - if( MZFbytes == 0 ) return; - - // Assertion: data length must be a multiple of 16 or 32 bits - pxAssume( (MZFbytes & 0x1) == 0 ); - - if( (MZFbytes & 0x3) != 0 ) - { - // Unaligned data length. No point in doing an optimized inline version (too complicated with - // remainders and such). - - _memset16_unaligned( dest, data, MZFbytes ); - return; - } - - //u64 _xmm_backup[2]; - - // This function only works on 32-bit alignments of data copied. - pxAssume( (MZFbytes & 0x3) == 0 ); - - enum - { - remdat = MZFbytes >> 2, - data32 = data + (data<<16) - }; - - // macro to execute the x86/32 "stosd" copies. - switch( remdat ) - { - case 1: - *(u32*)dest = data32; - return; - - case 2: - ((u32*)dest)[0] = data32; - ((u32*)dest)[1] = data32; - return; - - case 3: - __asm - { - mov edi, dest; - mov eax, data32; - stosd; - stosd; - stosd; - } - return; - - case 4: - __asm - { - mov edi, dest; - mov eax, data32; - stosd; - stosd; - stosd; - stosd; - } - return; - - case 5: - __asm - { - mov edi, dest; - mov eax, data32; - stosd; - stosd; - stosd; - stosd; - stosd; - } - return; - - default: - __asm - { - mov ecx, remdat; - mov edi, dest; - mov eax, data32; - rep stosd; - } - return - } -} - template< u32 data, size_t MZFbytes > static __fi void memset_32( void *dest ) { @@ -559,13 +471,6 @@ static __fi void memset8( T& object ) memset_8( &object ); } -// This method clears an object with the given 16 bit value. -template< u16 data, typename T > -static __fi void memset16( T& object ) -{ - memset_16( &object ); -} - // This method clears an object with the given 32 bit value. template< u32 data, typename T > static __fi void memset32( T& object ) diff --git a/common/src/Utilities/AlignedMalloc.cpp b/common/src/Utilities/AlignedMalloc.cpp deleted file mode 100644 index 285317b2e0..0000000000 --- a/common/src/Utilities/AlignedMalloc.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 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 for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -// This module contains implementations of _aligned_malloc for platforms that don't have -// it built into their CRT/libc. - -#include "PrecompiledHeader.h" - -struct AlignedMallocHeader -{ - u32 size; // size of the allocated buffer (minus alignment and header) - void* baseptr; // offset of the original allocated pointer -}; - -static const uint headsize = sizeof(AlignedMallocHeader); - -void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align) -{ - pxAssert( align < 0x10000 ); - -#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9 - return aligned_alloc(align, size); -#else - u8* p = (u8*)malloc(size+align+headsize); - - // start alignment calculations from past the header. - uptr pasthead = (uptr)(p+headsize); - uptr aligned = (pasthead + align-1) & ~(align-1); - - AlignedMallocHeader* header = (AlignedMallocHeader*)(aligned-headsize); - pxAssert( (uptr)header >= (uptr)p ); - - header->baseptr = p; - header->size = size; - - return (void*)aligned; -#endif -} - -void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align) -{ - pxAssert( align < 0x10000 ); - - void* newbuf = pcsx2_aligned_malloc( size, align ); - - if( handle != NULL ) - { -#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9 - memcpy_fast( newbuf, handle, size ); - free( handle ); -#else - AlignedMallocHeader* header = (AlignedMallocHeader*)((uptr)handle - headsize); - memcpy_fast( newbuf, handle, std::min( size, header->size ) ); - free( header->baseptr ); -#endif - } - return newbuf; -} - -__fi void pcsx2_aligned_free(void* pmem) -{ -#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9 - free(pmem); -#else - if( pmem == NULL ) return; - AlignedMallocHeader* header = (AlignedMallocHeader*)((uptr)pmem - headsize); - free( header->baseptr ); -#endif -} - -// ---------------------------------------------------------------------------- -// And for lack of a better home ... - - -// Special unaligned memset used when all other optimized memsets fail (it's called from -// memzero_obj and stuff). -__fi void _memset16_unaligned( void* dest, u16 data, size_t size ) -{ - pxAssume( (size & 0x1) == 0 ); - - u16* dst = (u16*)dest; - for(int i=size; i; --i, ++dst ) - *dst = data; -} - -__fi void HostSys::Munmap( void* base, size_t size ) -{ - Munmap( (uptr)base, size ); -} diff --git a/common/src/Utilities/CMakeLists.txt b/common/src/Utilities/CMakeLists.txt index 4bc3b7d0b4..f1f7202216 100644 --- a/common/src/Utilities/CMakeLists.txt +++ b/common/src/Utilities/CMakeLists.txt @@ -85,9 +85,8 @@ endif(CMAKE_BUILD_TYPE STREQUAL Release) set(UtilitiesSources ../../include/Utilities/FixedPointTypes.inl ../../include/Utilities/EventSource.inl - ../../include/Utilities/SafeArray.inl - ../../include/Utilities/TlsVariable.inl - AlignedMalloc.cpp + ../../include/Utilities/SafeArray.inl + ../../include/Utilities/TlsVariable.inl CheckedStaticBox.cpp Console.cpp EventSource.cpp diff --git a/common/src/Utilities/vssprintf.cpp b/common/src/Utilities/vssprintf.cpp index 79452c8b01..31b18b580d 100644 --- a/common/src/Utilities/vssprintf.cpp +++ b/common/src/Utilities/vssprintf.cpp @@ -815,22 +815,3 @@ void ssprintf(std::string& str, const char* fmt, ...) vssprintf(str, fmt, args); va_end(args); } - -// See ssprintf for usage details and differences from sprintf formatting. -std::string fmt_string( const char* fmt, ... ) -{ - std::string retval; - va_list args; - va_start( args, fmt ); - vssprintf( retval, fmt, args ); - va_end( args ); - - return retval; -} - -std::string vfmt_string( const char* fmt, va_list args ) -{ - std::string retval; - vssprintf( retval, fmt, args ); - return retval; -} diff --git a/plugins/GSdx/stdafx.cpp b/plugins/GSdx/stdafx.cpp index 6cc39e5e57..c27feab72f 100644 --- a/plugins/GSdx/stdafx.cpp +++ b/plugins/GSdx/stdafx.cpp @@ -103,28 +103,3 @@ void vmfree(void* ptr, size_t size) #endif -#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC) - -// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15) - -#if !defined(__USE_ISOC11) || defined(ASAN_WORKAROUND) - -void* _aligned_malloc(size_t size, size_t alignment) -{ - ASSERT(alignment <= 0x8000); - size_t r = (size_t)malloc(size + --alignment + 2); - size_t o = (r + 2 + alignment) & ~(size_t)alignment; - if(!r) return NULL; - ((uint16*)o)[-1] = (uint16)(o-r); - return (void*)o; -} - -void _aligned_free(void* p) -{ - if(!p) return; - free((void*)((size_t)p-((uint16*)p)[-1])); -} - -#endif - -#endif diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 78c7dfd49a..eefc65d296 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -357,18 +357,15 @@ struct aligned_free_second {template void operator()(T& p) {_aligned_fr #undef abs #if !defined(_MSC_VER) + static inline void _aligned_malloc(size, a) { + void* ret; + posix_memalign(&return, a, size); + return ret; + } - #if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9 - - #define _aligned_malloc(size, a) aligned_alloc(a, size) - static inline void _aligned_free(void* p) { free(p); } - - #elif !defined(HAVE_ALIGNED_MALLOC) - - extern void* _aligned_malloc(size_t size, size_t alignment); - extern void _aligned_free(void* p); - - #endif + static inline void _aligned_free(void* p) { + free(p); + } // http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/mingw32/intrin_x86.h?view=markup diff --git a/plugins/zerogs/opengl/GS.h b/plugins/zerogs/opengl/GS.h index 86b350619b..d52da0f81c 100644 --- a/plugins/zerogs/opengl/GS.h +++ b/plugins/zerogs/opengl/GS.h @@ -69,32 +69,17 @@ extern std::string s_strIniPath; extern u32 THR_KeyEvent; // value for passing out key events beetwen threads extern bool THR_bShift; -#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC) - -// declare linux equivalents -static __forceinline void* pcsx2_aligned_malloc(size_t size, size_t align) -{ - assert( align < 0x10000 ); - char* p = (char*)malloc(size+align); - int off = 2+align - ((int)(uptr)(p+2) % align); - - p += off; - *(u16*)(p-2) = off; - - return p; +#if !defined(_MSC_VER) +// declare linux equivalents (alignment must be power of 2 (1,2,4...2^15) +static __forceinline void* _aligned_malloc(size_t size, size_t alignment) { + void *result=0; + posix_memalign(&result, alignment, size); + return result; } -static __forceinline void pcsx2_aligned_free(void* pmem) -{ - if( pmem != NULL ) { - char* p = (char*)pmem; - free(p - (int)*(u16*)(p-2)); - } +static __forceinline void _aligned_free(void* p) { + free(p); } - -#define _aligned_malloc pcsx2_aligned_malloc -#define _aligned_free pcsx2_aligned_free - #endif #include // ftime(), struct timeb diff --git a/plugins/zerospu2/misc.h b/plugins/zerospu2/misc.h index 0241ec1a0f..89f1d8aeee 100644 --- a/plugins/zerospu2/misc.h +++ b/plugins/zerospu2/misc.h @@ -63,26 +63,15 @@ inline u64 GetMicroTime() #endif } -#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC) - -#include - +#if !defined(_MSC_VER) // declare linux equivalents (alignment must be power of 2 (1,2,4...2^15) -static __forceinline void* pcsx2_aligned_malloc(size_t size, size_t alignment) { - assert(alignment <= 0x8000); - uptr r = (uptr)malloc(size + --alignment + 2); - uptr o = (r + 2 + alignment) & ~(uptr)alignment; - if (!r) return NULL; - ((u16*)o)[-1] = (u16)(o-r); - return (void*)o; +static __forceinline void* _aligned_malloc(size_t size, size_t alignment) { + void *result=0; + posix_memalign(&result, alignment, size); + return result; } -static __forceinline void pcsx2_aligned_free(void* p) { - if (!p) return; - free((void*)((uptr)p-((u16*)p)[-1])); +static __forceinline void _aligned_free(void* p) { + free(p); } - - -#define _aligned_malloc pcsx2_aligned_malloc -#define _aligned_free pcsx2_aligned_free #endif