From 8af992c449b895ec8be638049fd2510388f23ddd Mon Sep 17 00:00:00 2001 From: Greg Zharun Date: Wed, 8 Apr 2015 16:29:33 +0300 Subject: [Summary] Added SSE sound processing functions support for Windows. Version 1. Conflicts: wscript --- libs/pbd/fpu.cc | 6 +-- libs/pbd/msvc/fpu.cc | 105 ++++++++++++++++++++++----------------------------- libs/pbd/wscript | 11 +++++- 3 files changed, 57 insertions(+), 65 deletions(-) (limited to 'libs/pbd') diff --git a/libs/pbd/fpu.cc b/libs/pbd/fpu.cc index b12d341366..0998f43bdc 100644 --- a/libs/pbd/fpu.cc +++ b/libs/pbd/fpu.cc @@ -16,7 +16,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef COMPILER_MSVC +#if !(defined (COMPILER_MSVC) || defined (COMPILER_MINGW)) #include "libpbd-config.h" #define _XOPEN_SOURCE 600 @@ -39,10 +39,6 @@ FPU::FPU () _flags = Flags (0); -#if defined(__MINGW64__) // Vkamyshniy: under __MINGW64__ the assembler code below is not compiled - return; -#endif - #if !( (defined __x86_64__) || (defined __i386__) ) // !ARCH_X86 return; #else diff --git a/libs/pbd/msvc/fpu.cc b/libs/pbd/msvc/fpu.cc index 6997405928..2ade2ad511 100644 --- a/libs/pbd/msvc/fpu.cc +++ b/libs/pbd/msvc/fpu.cc @@ -1,10 +1,14 @@ -#ifdef COMPILER_MSVC // 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). +// 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 #include #include // Added by JE - 05-12-2009 +#include #include #include @@ -20,47 +24,19 @@ FPU::FPU () _flags = (Flags)0; -#ifndef ARCH_X86 - return; - -#else - #ifndef USE_X86_64_ASM -int cpuInfo[4]; + 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]; -/* - __asm { // This is how the original section would look if converted to Intel syntax. - // However, I have grave doubts about whether it's doing the right thing. - // It seems as if the intention was to retrieve feature information from - // the processor. However, feature information is returned in the ebx register - // (if you believe Wikipedia) or in edx (if you believe Microsoft). Unfortunately, - // both registers get ignored in the original code!! Confused?? Join the club!! - mov eax, 1 - push ebx - cpuid - mov edx, 0 - pop ebx - mov cpuflags, ecx // This can't be right, surely??? - }; */ -#else -// Note that this syntax is currently still in AT&T format ! - asm volatile ( - "pushq %%rbx\n" - "movq $1, %%rax\n" - "cpuid\n" - "movq %%rdx, %0\n" - "popq %%rbx\n" - : "=r" (cpuflags) - : - : "%rax", "%rcx", "%rdx", "memory" - ); - -#endif /* USE_X86_64_ASM */ if (cpuflags & (1<<25)) { - _flags = Flags (_flags | (HasSSE|HasFlushToZero)); + _flags = Flags (_flags | (HasSSE|HasFlushToZero) ); } if (cpuflags & (1<<26)) { @@ -68,32 +44,46 @@ int cpuInfo[4]; } if (cpuflags & (1 << 24)) { - bool aligned_malloc = false; // Added by JE - 05-12-2009 - char* fxbuf = 0; -// This section changed by JE - 05-12-2009 -#ifdef NO_POSIX_MEMALIGN -#if defined(COMPILER_MSVC) || defined(COMPILER_MINGW) // All of these support '_aligned_malloc()' - fxbuf = (char *) _aligned_malloc(512, 16); // (note that they all need at least MSVC runtime 7.0) - aligned_malloc = true; -#else - fxbuf = (char *) malloc(512); -#endif -#else - fxbuf = posix_memalign ((void**)&fxbuf, 16, 512); -#endif + 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 buf_addr = (unsigned long)(void*)fxbuf; + 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 + 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) */ @@ -106,13 +96,10 @@ int cpuInfo[4]; _flags = Flags (_flags | HasDenormalsAreZero); } - if (aligned_malloc) - _aligned_free (fxbuf); - else - free (fxbuf); + free (*fxbuf); + free (fxbuf); } } -#endif // ARCH_X86 } FPU::~FPU () diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 8f947fbb26..e20131b068 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -48,7 +48,6 @@ libpbd_sources = [ 'error.cc', 'ffs.cc', 'file_utils.cc', - 'fpu.cc', 'glib_semaphore.cc', 'id.cc', 'locale_guard.cc', @@ -145,8 +144,18 @@ def build(bld): if bld.env['build_target'] == 'x86_64': obj.defines += [ 'USE_X86_64_ASM' ] if bld.env['build_target'] == 'mingw': + import re + import platform as PLATFORM + u = PLATFORM.uname () + cpu = u[4] + if re.search ("(x86_64|AMD64)", cpu) != None: + 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 -- cgit v1.2.3