1 #include "libpbd-config.h"
3 #define _XOPEN_SOURCE 600
4 #include <cstring> // for memset
10 #include "pbd/error.h"
19 unsigned long cpuflags = 0;
23 #if !( (defined __x86_64__) || (defined __i386__) ) // !ARCH_X86
28 #ifndef _LP64 //USE_X86_64_ASM
37 : "%eax", "%ecx", "%edx"
42 /* asm notes: although we explicitly save&restore rbx, we must tell
43 gcc that ebx,rbx is clobbered so that it doesn't try to use it as an intermediate
44 register when storing rbx. gcc 4.3 didn't make this "mistake", but gcc 4.4
45 does, at least on x86_64.
56 : "%rax", "%rbx", "%rcx", "%rdx"
59 #endif /* USE_X86_64_ASM */
61 if (cpuflags & (1<<25)) {
62 _flags = Flags (_flags | (HasSSE|HasFlushToZero));
65 if (cpuflags & (1<<26)) {
66 _flags = Flags (_flags | HasSSE2);
69 if (cpuflags & (1 << 24)) {
73 /* DAZ wasn't available in the first version of SSE. Since
74 setting a reserved bit in MXCSR causes a general protection
75 fault, we need to be able to check the availability of this
76 feature without causing problems. To do this, one needs to
77 set up a 512-byte area of memory to save the SSE state to,
78 using fxsave, and then one needs to inspect bytes 28 through
79 31 for the MXCSR_MASK value. If bit 6 is set, DAZ is
80 supported, otherwise, it isn't.
83 #ifndef HAVE_POSIX_MEMALIGN
84 fxbuf = (char **) malloc (sizeof (char *));
86 *fxbuf = (char *) malloc (512);
89 posix_memalign ((void **) &fxbuf, 16, sizeof (char *));
91 posix_memalign ((void **) fxbuf, 16, 512);
95 memset (*fxbuf, 0, 512);
104 uint32_t mxcsr_mask = *((uint32_t*) &((*fxbuf)[28]));
106 /* if the mask is zero, set its default value (from intel specs) */
108 if (mxcsr_mask == 0) {
112 if (mxcsr_mask & (1<<6)) {
113 _flags = Flags (_flags | HasDenormalsAreZero);