From 596ba557f1d81685b4926c11511d419870711e7c Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Fri, 6 Jan 2017 16:30:51 +0100 Subject: [PATCH] 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 --- src/Include/config_cmake.h.in | 1 + src/Main/bootstrap.cxx | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Include/config_cmake.h.in b/src/Include/config_cmake.h.in index 9989badf2..31f2cf2a1 100644 --- a/src/Include/config_cmake.h.in +++ b/src/Include/config_cmake.h.in @@ -3,6 +3,7 @@ #cmakedefine FG_NDEBUG #cmakedefine FG_NIGHTLY +#cmakedefine ENABLE_SIMD #cmakedefine ENABLE_SP_FDM #cmakedefine JSBSIM_USE_GROUNDREACTIONS diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index e389f457e..e0ade22dd 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -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 +# define get_cpuid(a,b) __cpuid(a,b) +# else +# include +# 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. @@ -162,7 +190,7 @@ int main ( int argc, char **argv ) signal(SIGPIPE, SIG_IGN); #endif - _bootstrap_OSInit = 0; + _bootstrap_OSInit = 0; #if defined(HAVE_CRASHRPT) // Define CrashRpt configuration parameters