monitor send gets access to the (shared) pannable of the track/bus, thus ensuring...
[ardour2.git] / libs / pbd / fpu.cc
bloba004d8a83977b3c733f3d5a59ed7c0772372d553
1 #include "libpbd-config.h"
3 #define _XOPEN_SOURCE 600
4 #include <cstring> // for memset
5 #include <cstdlib>
6 #include <stdint.h>
8 #include "pbd/fpu.h"
9 #include "pbd/error.h"
11 #include "i18n.h"
13 using namespace PBD;
14 using namespace std;
16 FPU::FPU ()
18 unsigned long cpuflags = 0;
20 _flags = Flags (0);
22 #ifndef ARCH_X86
23 return;
24 #endif
27 #ifndef USE_X86_64_ASM
28 asm volatile (
29 "mov $1, %%eax\n"
30 "pushl %%ebx\n"
31 "cpuid\n"
32 "movl %%edx, %0\n"
33 "popl %%ebx\n"
34 : "=r" (cpuflags)
36 : "%eax", "%ecx", "%edx"
39 #else
41 /* asm notes: although we explicitly save&restore rbx, we must tell
42 gcc that ebx,rbx is clobbered so that it doesn't try to use it as an intermediate
43 register when storing rbx. gcc 4.3 didn't make this "mistake", but gcc 4.4
44 does, at least on x86_64.
47 asm volatile (
48 "pushq %%rbx\n"
49 "movq $1, %%rax\n"
50 "cpuid\n"
51 "movq %%rdx, %0\n"
52 "popq %%rbx\n"
53 : "=r" (cpuflags)
55 : "%rax", "%rbx", "%rcx", "%rdx"
58 #endif /* USE_X86_64_ASM */
60 if (cpuflags & (1<<25)) {
61 _flags = Flags (_flags | (HasSSE|HasFlushToZero));
64 if (cpuflags & (1<<26)) {
65 _flags = Flags (_flags | HasSSE2);
68 if (cpuflags & (1 << 24)) {
70 char* fxbuf = 0;
72 #ifdef NO_POSIX_MEMALIGN
73 if ((fxbuf = (char *) malloc(512)) == 0)
74 #else
75 if (posix_memalign ((void**)&fxbuf, 16, 512))
76 #endif
78 error << _("cannot allocate 16 byte aligned buffer for h/w feature detection") << endmsg;
79 } else {
81 memset (fxbuf, 0, 512);
83 asm volatile (
84 "fxsave (%0)"
86 : "r" (fxbuf)
87 : "memory"
90 uint32_t mxcsr_mask = *((uint32_t*) &fxbuf[28]);
92 /* if the mask is zero, set its default value (from intel specs) */
94 if (mxcsr_mask == 0) {
95 mxcsr_mask = 0xffbf;
98 if (mxcsr_mask & (1<<6)) {
99 _flags = Flags (_flags | HasDenormalsAreZero);
102 free (fxbuf);
107 FPU::~FPU ()