0
|
1 /*
|
|
2 * Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
|
|
3 *
|
|
4 * This file is free software; you can redistribute it and/or modify it
|
|
5 * under the terms of the GNU General Public License as published by the
|
|
6 * Free Software Foundation; either version 3, or (at your option) any
|
|
7 * later version.
|
|
8 *
|
|
9 * This file is distributed in the hope that it will be useful, but
|
|
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 * General Public License for more details.
|
|
13 *
|
|
14 * Under Section 7 of GPL version 3, you are granted additional
|
|
15 * permissions described in the GCC Runtime Library Exception, version
|
|
16 * 3.1, as published by the Free Software Foundation.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License and
|
|
19 * a copy of the GCC Runtime Library Exception along with this program;
|
|
20 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
21 * <http://www.gnu.org/licenses/>.
|
|
22 */
|
|
23
|
|
24 #define MXCSR_DAZ (1 << 6) /* Enable denormals are zero mode */
|
|
25 #define MXCSR_FTZ (1 << 15) /* Enable flush to zero mode */
|
|
26
|
|
27 #ifndef __x86_64__
|
|
28 /* All 64-bit targets have SSE and DAZ;
|
|
29 only check them explicitly for 32-bit ones. */
|
|
30 #include "cpuid.h"
|
|
31 #endif
|
|
32
|
|
33 static void __attribute__((constructor))
|
|
34 #ifndef __x86_64__
|
|
35 /* The i386 ABI only requires 4-byte stack alignment, so this is necessary
|
|
36 to make sure the fxsave struct gets correct alignment.
|
|
37 See PR27537 and PR28621. */
|
|
38 __attribute__ ((force_align_arg_pointer))
|
|
39 #endif
|
|
40 set_fast_math (void)
|
|
41 {
|
|
42 #ifndef __x86_64__
|
|
43 unsigned int eax, ebx, ecx, edx;
|
|
44
|
|
45 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
|
|
46 return;
|
|
47
|
|
48 if (edx & bit_SSE)
|
|
49 {
|
|
50 unsigned int mxcsr = __builtin_ia32_stmxcsr ();
|
|
51
|
|
52 mxcsr |= MXCSR_FTZ;
|
|
53
|
|
54 if (edx & bit_FXSAVE)
|
|
55 {
|
|
56 /* Check if DAZ is available. */
|
|
57 struct
|
|
58 {
|
|
59 unsigned short int cwd;
|
|
60 unsigned short int swd;
|
|
61 unsigned short int twd;
|
|
62 unsigned short int fop;
|
|
63 long int fip;
|
|
64 long int fcs;
|
|
65 long int foo;
|
|
66 long int fos;
|
|
67 long int mxcsr;
|
|
68 long int mxcsr_mask;
|
|
69 long int st_space[32];
|
|
70 long int xmm_space[32];
|
|
71 long int padding[56];
|
|
72 } __attribute__ ((aligned (16))) fxsave;
|
|
73
|
|
74 __builtin_memset (&fxsave, 0, sizeof (fxsave));
|
|
75
|
|
76 asm volatile ("fxsave %0" : "=m" (fxsave) : "m" (fxsave));
|
|
77
|
|
78 if (fxsave.mxcsr_mask & MXCSR_DAZ)
|
|
79 mxcsr |= MXCSR_DAZ;
|
|
80 }
|
|
81
|
|
82 __builtin_ia32_ldmxcsr (mxcsr);
|
|
83 }
|
|
84 #else
|
|
85 unsigned int mxcsr = __builtin_ia32_stmxcsr ();
|
|
86 mxcsr |= MXCSR_DAZ | MXCSR_FTZ;
|
|
87 __builtin_ia32_ldmxcsr (mxcsr);
|
|
88 #endif
|
|
89 }
|