1
0
Fork 0

Detect the absence of SSE2 hardware as soon as possible and bail out if it is not found but FligthGear is compiled with SSE2 support

This commit is contained in:
Erik Hofman 2017-01-06 16:30:51 +01:00
parent 2408a3a28a
commit 596ba557f1
2 changed files with 30 additions and 1 deletions

View file

@ -3,6 +3,7 @@
#cmakedefine FG_NDEBUG
#cmakedefine FG_NIGHTLY
#cmakedefine ENABLE_SIMD
#cmakedefine ENABLE_SP_FDM
#cmakedefine JSBSIM_USE_GROUNDREACTIONS

View file

@ -141,11 +141,39 @@ static void fg_terminate()
flightgear::fatalMessageBox("Fatal exception", "Uncaught exception on some thread");
}
// Detect SSE2 support for x86, it is always available for x86_64
#if defined(__i386__)
# if defined(SG_WINDOWS)
# include <intrin.h>
# define get_cpuid(a,b) __cpuid(a,b)
# else
# include <cpuid.h>
# define get_cpuid(a,b) __cpuid(b,a[0],a[1],a[2],a[3])
# endif
# define CPUID_GETFEATURES 1
# define CPUID_FEAT_EDX_SSE2 (1 << 26)
bool detectSIMD()
{
static int regs[4] = {0,0,0,0};
get_cpuid(regs, CPUID_GETFEATURES);
return (regs[3] & CPUID_FEAT_EDX_SSE2);
}
#else
bool detectSIMD() { return true; }
#endif
int _bootstrap_OSInit;
// Main entry point; catch any exceptions that have made it this far.
int main ( int argc, char **argv )
{
#ifdef ENABLE_SIMD
if (!detectSIMD()) {
flightgear::fatalMessageBox("Fatal error","SSE2 support not detetcted but this version of FlightGear requires SSE2 hardware support.");
return -1;
}
#endif
#if defined(SG_WINDOWS)
// Don't show blocking "no disk in drive" error messages on Windows 7,
// silently return errors to application instead.