Merge branch 'intrinsic-cleanup'

This commit is contained in:
Gregory Hainaut 2016-07-17 11:33:06 +02:00
commit e680a90e90
16 changed files with 58 additions and 87 deletions

View File

@ -33,11 +33,7 @@
#include "Pcsx2Types.h"
#ifdef _MSC_VER
# include <intrin.h>
#else
# include <intrin_x86.h>
#endif
#include "x86emitter/x86_intrin.h"
// Renamed ARRAYSIZE to ArraySize -- looks nice and gets rid of Windows.h conflicts (air)
// Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with
@ -46,33 +42,6 @@
# define ArraySize(x) (sizeof(x)/sizeof((x)[0]))
#endif
// --------------------------------------------------------------------------------------
// jASSUME - give hints to the optimizer [obsolete, use pxAssume() instead]
// --------------------------------------------------------------------------------------
// This is primarily useful for the default case switch optimizer, which enables VC to
// generate more compact switches.
//
// Note: When using the PCSX2 Utilities library, this is deprecated. Use pxAssert instead,
// which itself optimizes to an __assume() hint in release mode builds.
//
#ifndef jASSUME
# ifdef NDEBUG
# define jBREAKPOINT() ((void) 0)
# ifdef _MSC_VER
# define jASSUME(exp) (__assume(exp))
# else
# define jASSUME(exp) do { if(!(exp)) __builtin_unreachable(); } while(0)
# endif
# else
# define jBREAKPOINT() __debugbreak();
# ifdef wxASSERT
# define jASSUME(exp) wxASSERT(exp)
# else
# define jASSUME(exp) do { if(!(exp)) jBREAKPOINT(); } while(0)
# endif
# endif
#endif
// --------------------------------------------------------------------------------------
// Dev / Debug conditionals - Consts for using if() statements instead of uglier #ifdef.
// --------------------------------------------------------------------------------------

View File

@ -25,7 +25,7 @@ static __fi void memset32( T& obj )
// If the data length is not a factor of 32 bits, the C++ optimizing compiler will
// probably just generate mysteriously broken code in Release builds. ;)
jASSUME( (sizeof(T) & 0x3) == 0 );
pxAssume((sizeof(T) & 0x3) == 0);
u32* dest = (u32*)&obj;
for( int i=sizeof(T)>>2; i; --i, ++dest )

View File

@ -67,29 +67,3 @@ static __inline__ __attribute__((always_inline)) s64 _InterlockedExchange64(vola
__sync_synchronize();
return __sync_lock_test_and_set(Target, Value);
}
/*** System information ***/
static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
{
__asm__ __volatile__("cpuid": "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
}
static __inline__ __attribute__((always_inline)) void __cpuidex(int CPUInfo[], const int level, const int count)
{
__asm__ __volatile__("cpuid": "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (level), "c" (count));
}
static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index)
{
unsigned int eax, edx;
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
return ((unsigned long long)edx << 32) | eax;
}
/*** Interrupts ***/
#ifndef __linux__
static __inline__ __attribute__((always_inline)) void __debugbreak(void)
{
__asm__("int $3");
}
#endif

View File

@ -31,6 +31,34 @@
#endif
// CPU information support
#if defined(_WIN32)
#define cpuid __cpuid
#define cpuidex __cpuidex
#else
#include <cpuid.h>
static __inline__ __attribute__((always_inline)) void cpuidex(int CPUInfo[], const int InfoType, const int count) {
__cpuid_count(InfoType, count, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
}
static __inline__ __attribute__((always_inline)) void cpuid(int CPUInfo[], const int InfoType) {
__cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
}
static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index)
{
unsigned int eax, edx;
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
return ((unsigned long long)edx << 32) | eax;
}
#endif
// Rotate instruction
#if defined(__clang__)
// Seriously what is so complicated to provided this bunch of intrinsics in clangs.
static unsigned int _rotr(unsigned int x, int s)

View File

@ -149,7 +149,7 @@ void x86capabilities::CountCores()
s32 regs[ 4 ];
u32 cmds;
__cpuid( regs, 0x80000000 );
cpuid( regs, 0x80000000 );
cmds = regs[ 0 ];
// detect multicore for AMD cpu
@ -191,7 +191,7 @@ void x86capabilities::Identify()
#endif
memzero( VendorName );
__cpuid( regs, 0 );
cpuid( regs, 0 );
cmds = regs[ 0 ];
((u32*)VendorName)[ 0 ] = regs[ 1 ];
@ -211,7 +211,7 @@ void x86capabilities::Identify()
if ( cmds >= 0x00000001 )
{
__cpuid( regs, 0x00000001 );
cpuid( regs, 0x00000001 );
StepID = regs[ 0 ] & 0xf;
Model = (regs[ 0 ] >> 4) & 0xf;
@ -227,16 +227,16 @@ void x86capabilities::Identify()
if ( cmds >= 0x00000007 )
{
// Note: ECX must be 0 for AVX2 detection.
__cpuidex( regs, 0x00000007, 0 );
cpuidex( regs, 0x00000007, 0 );
SEFlag = regs[ 1 ];
}
__cpuid( regs, 0x80000000 );
cpuid( regs, 0x80000000 );
cmds = regs[ 0 ];
if ( cmds >= 0x80000001 )
{
__cpuid( regs, 0x80000001 );
cpuid( regs, 0x80000001 );
#ifdef __x86_64__
x86_64_12BITBRANDID = regs[1] & 0xfff;
@ -246,9 +246,9 @@ void x86capabilities::Identify()
}
memzero( FamilyName );
__cpuid( (int*)FamilyName, 0x80000002);
__cpuid( (int*)(FamilyName+16), 0x80000003);
__cpuid( (int*)(FamilyName+32), 0x80000004);
cpuid( (int*)FamilyName, 0x80000002);
cpuid( (int*)(FamilyName+16), 0x80000003);
cpuid( (int*)(FamilyName+32), 0x80000004);
hasFloatingPointUnit = ( Flags >> 0 ) & 1;
hasVirtual8086ModeEnhancements = ( Flags >> 1 ) & 1;

View File

@ -54,7 +54,7 @@ static int GetLinearSrAr( uint SrAr )
bool V_ADSR::Calculate()
{
jASSUME( Phase != 0 );
pxAssume( Phase != 0 );
if(Releasing && (Phase < 5))
Phase = 5;

View File

@ -69,8 +69,8 @@ protected:
fprintf(stderr,"* SPU2-X:Iz in your external callback.\n");
AlsaMod *data = (AlsaMod*)snd_async_handler_get_callback_private( pcm_call );
jASSUME( data != NULL );
//jASSUME( data->handle == snd_async_handler_get_pcm(pcm_call) );
pxAssume( data != NULL );
//pxAssume( data->handle == snd_async_handler_get_pcm(pcm_call) );
// Not sure if we just need an assert, or something like this:
if (data->handle != snd_async_handler_get_pcm(pcm_call))

View File

@ -398,7 +398,7 @@ static __forceinline void CalculateADSR( V_Core& thiscore, uint voiceidx )
vc.Stop();
}
jASSUME( vc.ADSR.Value >= 0 ); // ADSR should never be negative...
pxAssume( vc.ADSR.Value >= 0 ); // ADSR should never be negative...
}
/*
@ -529,7 +529,7 @@ static __forceinline s32 GetNoiseValues( V_Core& thiscore, uint voiceidx )
// GetNoiseValues can't set the phase zero on us unexpectedly
// like GetVoiceValues can. Better assert just in case though..
jASSUME( vc.ADSR.Phase != 0 );
pxAssume( vc.ADSR.Phase != 0 );
return retval;
}
@ -554,7 +554,7 @@ static __forceinline void spu2M_WriteFast( u32 addr, s16 value )
}
// throw an assertion if the memory range is invalid:
#ifndef DEBUG_FAST
jASSUME( addr < SPU2_DYN_MEMLINE );
pxAssume( addr < SPU2_DYN_MEMLINE );
#endif
*GetMemPtr( addr ) = value;
}

View File

@ -671,7 +671,7 @@ EXPORT_C_(int) SPU2setupRecording(int start, void* pData)
EXPORT_C_(s32) SPU2freeze(int mode, freezeData *data)
{
jASSUME( data != NULL );
pxAssume( data != NULL );
if ( !data )
{
printf("SPU2-X savestate null pointer!\n");
@ -684,7 +684,7 @@ EXPORT_C_(s32) SPU2freeze(int mode, freezeData *data)
return 0;
}
jASSUME( mode == FREEZE_LOAD || mode == FREEZE_SAVE );
pxAssume( mode == FREEZE_LOAD || mode == FREEZE_SAVE );
if( data->data == NULL )
{

View File

@ -262,7 +262,7 @@ template<typename T> void SndBuffer::ReadSamples(T* bData)
int quietSamples;
if( CheckUnderrunStatus( nSamples, quietSamples ) )
{
jASSUME( nSamples <= SndOutPacketSize );
pxAssume( nSamples <= SndOutPacketSize );
// WARNING: This code assumes there's only ONE reading process.
int b1 = m_size - m_rpos;

View File

@ -458,7 +458,7 @@ static void CvtPacketToFloat( StereoOut32* srcdest )
// Parameter note: Size should always be a multiple of 128, thanks!
static void CvtPacketToInt( StereoOut32* srcdest, uint size )
{
//jASSUME( (size & 127) == 0 );
//pxAssume( (size & 127) == 0 );
const StereoOutFloat* src = (StereoOutFloat*)srcdest;
StereoOut32* dest = srcdest;

View File

@ -476,7 +476,7 @@ BOOL CALLBACK DSound::ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam
BOOL CALLBACK DSound::DSEnumCallback( LPGUID lpGuid, LPCTSTR lpcstrDescription, LPCTSTR lpcstrModule, LPVOID lpContext )
{
jASSUME( DSoundOut != NULL );
pxAssume( DSoundOut != NULL );
return DS._DSEnumCallback( lpGuid, lpcstrDescription, lpcstrModule, lpContext );
}

View File

@ -241,7 +241,7 @@ public:
{
HRESULT hr;
jASSUME(pXAudio2 == NULL);
pxAssume(pXAudio2 == NULL);
xAudio2DLL = LoadLibraryEx(XAUDIO2_DLL, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (xAudio2DLL == nullptr)

View File

@ -243,7 +243,7 @@ public:
{
HRESULT hr;
jASSUME( pXAudio2 == NULL );
pxAssume( pXAudio2 == NULL );
// On some systems XAudio2.7 can unload itself and cause PCSX2 to crash.
// Maintain an extra library reference so it can't do so. Does not
@ -291,7 +291,7 @@ public:
}
// Any windows driver should support stereo at the software level, I should think!
jASSUME( deviceDetails.OutputFormat.Format.nChannels > 1 );
pxAssume( deviceDetails.OutputFormat.Format.nChannels > 1 );
//
// Create a mastering voice

View File

@ -99,7 +99,7 @@ public:
speakerConfig = 2; // better not mess with this in wavout :p (rama)
// Any windows driver should support stereo at the software level, I should think!
jASSUME( speakerConfig > 1 );
pxAssume( speakerConfig > 1 );
LPTHREAD_START_ROUTINE threadproc;
switch( speakerConfig )

View File

@ -57,7 +57,7 @@ __forceinline s16* GetMemPtr(u32 addr)
#ifndef DEBUG_FAST
// In case you're wondering, this assert is the reason SPU2-X
// runs so incrediously slow in Debug mode. :P
jASSUME( addr < 0x100000 );
pxAssume( addr < 0x100000 );
#endif
return (_spu2mem+addr);
}
@ -491,7 +491,7 @@ void V_VolumeSlide::RegSet( u16 src )
void V_Core::WriteRegPS1( u32 mem, u16 value )
{
jASSUME( Index == 0 ); // Valid on Core 0 only!
pxAssume( Index == 0 ); // Valid on Core 0 only!
bool show = true;
u32 reg = mem & 0xffff;
@ -641,7 +641,7 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
u16 V_Core::ReadRegPS1(u32 mem)
{
jASSUME( Index == 0 ); // Valid on Core 0 only!
pxAssume( Index == 0 ); // Valid on Core 0 only!
bool show=true;
u16 value = spu2Ru16(mem);