diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-21 11:39:19 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-21 11:39:31 -0400 |
commit | a5d7e8446bdc488be9d52cede7f49ad9910cc127 (patch) | |
tree | ab50fcaa8dd8009ef892ac9a27505b3facbe49e3 | |
parent | 63b39677241a6dc07c1426554b6e2da6d9712d94 (diff) |
merge all mingw and msvc specific code for FPU information into libs/pbd/fpu.cc and remove msvc-specific version
-rw-r--r-- | libs/pbd/fpu.cc | 35 | ||||
-rw-r--r-- | libs/pbd/msvc/fpu.cc | 111 | ||||
-rw-r--r-- | libs/pbd/wscript | 4 |
3 files changed, 29 insertions, 121 deletions
diff --git a/libs/pbd/fpu.cc b/libs/pbd/fpu.cc index 0998f43bdc..c297d2dd07 100644 --- a/libs/pbd/fpu.cc +++ b/libs/pbd/fpu.cc @@ -16,7 +16,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if !(defined (COMPILER_MSVC) || defined (COMPILER_MINGW)) + #include "libpbd-config.h" #define _XOPEN_SOURCE 600 @@ -43,7 +43,24 @@ FPU::FPU () return; #else -#ifndef _LP64 //USE_X86_64_ASM +#ifdef PLATFORM_WINDOWS + +#ifndef USE_X86_64_ASM + /* no 32 bit version of assembler for windows */ + return; +#else + // Get CPU flags using Microsoft function + // It works for both 64 and 32 bit systems + // no need to use assembler for getting info from register, this function does this for us + int cpuInfo[4]; + __cpuid (cpuInfo, 1); + cpuflags = cpuInfo[3]; +#endif + +#else + +#ifndef USE_X86_64_ASM /* *nix; 32 bit version */ + asm volatile ( "mov $1, %%eax\n" "pushl %%ebx\n" @@ -55,7 +72,7 @@ FPU::FPU () : "%eax", "%ecx", "%edx" ); -#else +#else /* *nix; 64 bit version */ /* asm notes: although we explicitly save&restore rbx, we must tell gcc that ebx,rbx is clobbered so that it doesn't try to use it as an intermediate @@ -75,6 +92,7 @@ FPU::FPU () ); #endif /* USE_X86_64_ASM */ +#endif /* PLATFORM_WINDOWS */ if (cpuflags & (1<<25)) { _flags = Flags (_flags | (HasSSE|HasFlushToZero)); @@ -112,12 +130,19 @@ FPU::FPU () memset (*fxbuf, 0, 512); +#ifdef COMPILER_MSVC + __asm { + mov eax, fxbuf + fxsave [eax] + }; +#else asm volatile ( "fxsave (%0)" : : "r" (*fxbuf) : "memory" ); +#endif uint32_t mxcsr_mask = *((uint32_t*) &((*fxbuf)[28])); @@ -140,7 +165,3 @@ FPU::FPU () FPU::~FPU () { } - -#else // COMPILER_MSVC - const char* pbd_fpu = "pbd/msvc/fpu.cc takes precedence over this file"; -#endif // COMPILER_MSVC diff --git a/libs/pbd/msvc/fpu.cc b/libs/pbd/msvc/fpu.cc deleted file mode 100644 index 2ade2ad511..0000000000 --- a/libs/pbd/msvc/fpu.cc +++ /dev/null @@ -1,111 +0,0 @@ -// Added by JE - 05-12-2009. Inline assembler instructions -// have been changed to Intel format and (in the case of -// cpuid) was replaced by the equivalent VC++ system call). - -#if defined (COMPILER_MSVC) || defined (COMPILER_MINGW) - -#define _XOPEN_SOURCE 600 -#include <cstdlib> -#include <stdint.h> -#include <intrin.h> // Added by JE - 05-12-2009 -#include <assert.h> - -#include <pbd/fpu.h> -#include <pbd/error.h> - -#include "i18n.h" - -using namespace PBD; -using namespace std; - -FPU::FPU () -{ - unsigned long cpuflags = 0; - - _flags = (Flags)0; - -#ifndef USE_X86_64_ASM - return; -#endif - - // Get CPU lfags using Microsof function - // It works for both 64 and 32 bit systems - // no need to use assembler for getting info from register, this function does this for us - int cpuInfo[4]; - __cpuid (cpuInfo, 1); - cpuflags = cpuInfo[3]; - - if (cpuflags & (1<<25)) { - _flags = Flags (_flags | (HasSSE|HasFlushToZero) ); - } - - if (cpuflags & (1<<26)) { - _flags = Flags (_flags | HasSSE2); - } - - if (cpuflags & (1 << 24)) { - char** fxbuf = 0; - - // allocate alligned buffer - fxbuf = (char **) malloc (sizeof (char *)); - assert (fxbuf); - *fxbuf = (char *) malloc (512); - assert (*fxbuf); - - // Verify that fxbuf is correctly aligned - unsigned long long buf_addr = (unsigned long long)(void*)fxbuf; - if ((0 == buf_addr) || (buf_addr % 16)) - error << _("cannot allocate 16 byte aligned buffer for h/w feature detection") << endmsg; - else - { - memset(*fxbuf, 0, 512); // Initialize the buffer !!! Added by JE - 12-12-2009 - -#if defined (COMPILER_MINGW) - asm volatile ( - "fxsave (%0)" - : - : "r" (*fxbuf) - : "memory" - ); -/* - asm( ".intel_syntax noprefix\n" ); - - asm volatile ( - "mov eax, fxbuf\n" - "fxsave [eax]\n" - ); - - asm( ".att_syntax prefix\n" ); -*/ - -#elif defined (COMPILER_MSVC) - __asm { - mov eax, fxbuf - fxsave [eax] - }; -#endif - uint32_t mxcsr_mask = *((uint32_t*) &fxbuf[28]); - - /* if the mask is zero, set its default value (from intel specs) */ - - if (mxcsr_mask == 0) { - mxcsr_mask = 0xffbf; - } - - if (mxcsr_mask & (1<<6)) { - _flags = Flags (_flags | HasDenormalsAreZero); - } - - free (*fxbuf); - free (fxbuf); - } - } -} - -FPU::~FPU () -{ -} - -#else // !COMPILER_MSVC - const char* pbd_fpu = "original pbd/fpu.cc takes precedence over this file"; -#endif // COMPILER_MSVC diff --git a/libs/pbd/wscript b/libs/pbd/wscript index e20131b068..eff38d7b8b 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -48,6 +48,7 @@ libpbd_sources = [ 'error.cc', 'ffs.cc', 'file_utils.cc', + 'fpu.cc', 'glib_semaphore.cc', 'id.cc', 'locale_guard.cc', @@ -152,10 +153,7 @@ def build(bld): obj.defines += [ 'USE_X86_64_ASM' ] obj.defines += ['NO_POSIX_MEMALIGN' ] obj.source += [ 'windows_special_dirs.cc' ] - obj.source += [ 'msvc/fpu.cc' ] obj.uselib += ' OLE' - else: - obj.source += [ 'fpu.cc' ] if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'): # Unit tests |