Add tests for SSE3 capability

This commit is contained in:
Vinnie Falco
2013-07-31 07:02:28 -07:00
parent 1a8e161c19
commit daf08bbde0
6 changed files with 55 additions and 62 deletions

View File

@@ -262,14 +262,8 @@ String SystemStats::getUserRegion() { return AndroidStatsHelpers::getLocale
String SystemStats::getDisplayLanguage() { return getUserLanguage(); }
//==============================================================================
SystemStats::CPUFlags::CPUFlags()
void CPUInformation::initialise() noexcept
{
// TODO
hasMMX = false;
hasSSE = false;
hasSSE2 = false;
has3DNow = false;
numCpus = bmax (1, sysconf (_SC_NPROCESSORS_ONLN));
}

View File

@@ -127,12 +127,13 @@ String SystemStats::getUserRegion() { return getLocaleValue (_NL_IDENTIFICA
String SystemStats::getDisplayLanguage() { return getUserLanguage(); }
//==============================================================================
SystemStats::CPUFlags::CPUFlags()
void CPUInformation::initialise() noexcept
{
const String flags (LinuxStatsHelpers::getCpuInfo ("flags"));
hasMMX = flags.contains ("mmx");
hasSSE = flags.contains ("sse");
hasSSE2 = flags.contains ("sse2");
hasMMX = flags.contains ("mmx");
hasSSE = flags.contains ("sse");
hasSSE2 = flags.contains ("sse2");
hasSSE3 = flags.contains ("sse3");
has3DNow = flags.contains ("3dnow");
numCpus = LinuxStatsHelpers::getCpuInfo ("processor").getIntValue() + 1;

View File

@@ -64,21 +64,17 @@ namespace SystemStatsHelpers
}
//==============================================================================
SystemStats::CPUFlags::CPUFlags()
void CPUInformation::initialise() noexcept
{
#if BEAST_INTEL && ! BEAST_NO_INLINE_ASM
uint32 familyModel = 0, extFeatures = 0, features = 0, dummy = 0;
SystemStatsHelpers::doCPUID (familyModel, extFeatures, dummy, features, 1);
uint32 a = 0, b = 0, d = 0, c = 0;
SystemStatsHelpers::doCPUID (a, b, c, d, 1);
hasMMX = (features & (1u << 23)) != 0;
hasSSE = (features & (1u << 25)) != 0;
hasSSE2 = (features & (1u << 26)) != 0;
has3DNow = (extFeatures & (1u << 31)) != 0;
#else
hasMMX = false;
hasSSE = false;
hasSSE2 = false;
has3DNow = false;
hasMMX = (d & (1u << 23)) != 0;
hasSSE = (d & (1u << 25)) != 0;
hasSSE2 = (d & (1u << 26)) != 0;
has3DNow = (b & (1u << 31)) != 0;
hasSSE3 = (c & (1u << 0)) != 0;
#endif
#if BEAST_IOS || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)

View File

@@ -99,16 +99,13 @@ String SystemStats::getCpuVendor()
//==============================================================================
SystemStats::CPUFlags::CPUFlags()
void CPUInformation::initialise() noexcept
{
hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
#ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
#else
has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
#endif
hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
hasSSE3 = IsProcessorFeaturePresent (13 /*PF_SSE3_INSTRUCTIONS_AVAILABLE*/) != 0;
has3DNow = IsProcessorFeaturePresent (7 /*PF_AMD3D_INSTRUCTIONS_AVAILABLE*/) != 0;
SYSTEM_INFO systemInfo;
GetNativeSystemInfo (&systemInfo);

View File

@@ -21,12 +21,6 @@
*/
//==============================================================================
const SystemStats::CPUFlags& SystemStats::getCPUFlags()
{
static CPUFlags cpuFlags;
return cpuFlags;
}
String SystemStats::getBeastVersion()
{
// Some basic tests, to keep an eye on things and make sure these types work ok
@@ -62,6 +56,34 @@ String SystemStats::getBeastVersion()
static BeastVersionPrinter beastVersionPrinter;
#endif
//==============================================================================
struct CPUInformation
{
CPUInformation() noexcept
: numCpus (0), hasMMX (false), hasSSE (false),
hasSSE2 (false), hasSSE3 (false), has3DNow (false)
{
initialise();
}
void initialise() noexcept;
int numCpus;
bool hasMMX, hasSSE, hasSSE2, hasSSE3, has3DNow;
};
static const CPUInformation& getCPUInformation() noexcept
{
static CPUInformation info;
return info;
}
int SystemStats::getNumCpus() noexcept { return getCPUInformation().numCpus; }
bool SystemStats::hasMMX() noexcept { return getCPUInformation().hasMMX; }
bool SystemStats::hasSSE() noexcept { return getCPUInformation().hasSSE; }
bool SystemStats::hasSSE2() noexcept { return getCPUInformation().hasSSE2; }
bool SystemStats::hasSSE3() noexcept { return getCPUInformation().hasSSE3; }
bool SystemStats::has3DNow() noexcept { return getCPUInformation().has3DNow; }
//==============================================================================
String SystemStats::getStackBacktrace()

View File

@@ -121,8 +121,8 @@ public:
//==============================================================================
// CPU and memory information..
/** Returns the number of CPUs. */
static int getNumCpus() noexcept { return getCPUFlags().numCpus; }
/** Returns the number of CPU cores. */
static int getNumCpus() noexcept;
/** Returns the approximate CPU speed.
@returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on
@@ -135,17 +135,11 @@ public:
*/
static String getCpuVendor();
/** Checks whether Intel MMX instructions are available. */
static bool hasMMX() noexcept { return getCPUFlags().hasMMX; }
/** Checks whether Intel SSE instructions are available. */
static bool hasSSE() noexcept { return getCPUFlags().hasSSE; }
/** Checks whether Intel SSE2 instructions are available. */
static bool hasSSE2() noexcept { return getCPUFlags().hasSSE2; }
/** Checks whether AMD 3DNOW instructions are available. */
static bool has3DNow() noexcept { return getCPUFlags().has3DNow; }
static bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */
static bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */
static bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */
static bool hasSSE3() noexcept; /**< Returns true if Intel SSE2 instructions are available. */
static bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */
//==============================================================================
/** Finds out how much RAM is in the machine.
@@ -179,19 +173,8 @@ public:
private:
//==============================================================================
struct CPUFlags
{
CPUFlags();
int numCpus;
bool hasMMX : 1;
bool hasSSE : 1;
bool hasSSE2 : 1;
bool has3DNow : 1;
};
SystemStats();
static const CPUFlags& getCPUFlags();
};