1 #ifdef COMPILER_MSVC // Added by JE - 05-12-2009. Inline assembler instructions
2 // have been changed to Intel format and (in the case of
3 // cpuid) was replaced by the equivalent VC++ system call).
4 #define _XOPEN_SOURCE 600
7 #include <intrin.h> // Added by JE - 05-12-2009
10 #include <pbd/error.h>
19 unsigned long cpuflags = 0;
28 #ifndef USE_X86_64_ASM
32 cpuflags = cpuInfo[3];
34 __asm { // This is how the original section would look if converted to Intel syntax.
35 // However, I have grave doubts about whether it's doing the right thing.
36 // It seems as if the intention was to retrieve feature information from
37 // the processor. However, feature information is returned in the ebx register
38 // (if you believe Wikipedia) or in edx (if you believe Microsoft). Unfortunately,
39 // both registers get ignored in the original code!! Confused?? Join the club!!
45 mov cpuflags, ecx // This can't be right, surely???
48 // Note that this syntax is currently still in AT&T format !
57 : "%rax", "%rcx", "%rdx", "memory"
60 #endif /* USE_X86_64_ASM */
62 if (cpuflags & (1<<25)) {
63 _flags = Flags (_flags | (HasSSE|HasFlushToZero));
66 if (cpuflags & (1<<26)) {
67 _flags = Flags (_flags | HasSSE2);
70 if (cpuflags & (1 << 24)) {
71 bool aligned_malloc = false; // Added by JE - 05-12-2009
73 // This section changed by JE - 05-12-2009
74 #ifdef NO_POSIX_MEMALIGN
75 #if defined(COMPILER_MSVC) || defined(COMPILER_MINGW) // All of these support '_aligned_malloc()'
76 fxbuf = (char *) _aligned_malloc(512, 16); // (note that they all need at least MSVC runtime 7.0)
77 aligned_malloc = true;
79 fxbuf = (char *) malloc(512);
82 fxbuf = posix_memalign ((void**)&fxbuf, 16, 512);
84 // Verify that fxbuf is correctly aligned
85 unsigned long buf_addr = (unsigned long)(void*)fxbuf;
86 if ((0 == buf_addr) || (buf_addr % 16))
87 error << _("cannot allocate 16 byte aligned buffer for h/w feature detection") << endmsg;
90 memset(fxbuf, 0, 512); // Initialize the buffer !!! Added by JE - 12-12-2009
97 uint32_t mxcsr_mask = *((uint32_t*) &fxbuf[28]);
99 /* if the mask is zero, set its default value (from intel specs) */
101 if (mxcsr_mask == 0) {
105 if (mxcsr_mask & (1<<6)) {
106 _flags = Flags (_flags | HasDenormalsAreZero);
110 _aligned_free (fxbuf);
122 #else // !COMPILER_MSVC
123 const char* pbd_fpu = "original pbd/fpu.cc takes precedence over this file";
124 #endif // COMPILER_MSVC