1 #include "libpbd-config.h"
3 #define _XOPEN_SOURCE 600
4 #include <cstring> // for memset
18 unsigned long cpuflags = 0;
22 #if !( (defined __x86_64__) || (defined __i386__) ) // !ARCH_X86
27 #ifndef _LP64 //USE_X86_64_ASM
36 : "%eax", "%ecx", "%edx"
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.
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)) {
72 /* DAZ wasn't available in the first version of SSE. Since
73 setting a reserved bit in MXCSR causes a general protection
74 fault, we need to be able to check the availability of this
75 feature without causing problems. To do this, one needs to
76 set up a 512-byte area of memory to save the SSE state to,
77 using fxsave, and then one needs to inspect bytes 28 through
78 31 for the MXCSR_MASK value. If bit 6 is set, DAZ is
79 supported, otherwise, it isn't.
82 #ifdef NO_POSIX_MEMALIGN
83 if ((fxbuf = (char *) malloc(512)) == 0)
85 if (posix_memalign ((void**)&fxbuf, 16, 512))
88 error << _("cannot allocate 16 byte aligned buffer for h/w feature detection") << endmsg;
91 memset (fxbuf, 0, 512);
100 uint32_t mxcsr_mask = *((uint32_t*) &fxbuf[28]);
102 /* if the mask is zero, set its default value (from intel specs) */
104 if (mxcsr_mask == 0) {
108 if (mxcsr_mask & (1<<6)) {
109 _flags = Flags (_flags | HasDenormalsAreZero);