annotate libgcc/config/i386/crtfastmath.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /*
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 * Copyright (C) 2005-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 *
kono
parents:
diff changeset
4 * This file is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
5 * under the terms of the GNU General Public License as published by the
kono
parents:
diff changeset
6 * Free Software Foundation; either version 3, or (at your option) any
kono
parents:
diff changeset
7 * later version.
kono
parents:
diff changeset
8 *
kono
parents:
diff changeset
9 * This file is distributed in the hope that it will be useful, but
kono
parents:
diff changeset
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
12 * General Public License for more details.
kono
parents:
diff changeset
13 *
kono
parents:
diff changeset
14 * Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
15 * permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
16 * 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
17 *
kono
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
19 * a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
20 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
21 * <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
22 */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #ifndef _SOFT_FLOAT
kono
parents:
diff changeset
25 #define MXCSR_DAZ (1 << 6) /* Enable denormals are zero mode */
kono
parents:
diff changeset
26 #define MXCSR_FTZ (1 << 15) /* Enable flush to zero mode */
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #ifndef __x86_64__
kono
parents:
diff changeset
29 /* All 64-bit targets have SSE and DAZ;
kono
parents:
diff changeset
30 only check them explicitly for 32-bit ones. */
kono
parents:
diff changeset
31 #include "cpuid.h"
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 __attribute__ ((target("fxsr,sse")))
kono
parents:
diff changeset
34 static void
kono
parents:
diff changeset
35 /* The i386 ABI only requires 4-byte stack alignment, so this is necessary
kono
parents:
diff changeset
36 to make sure the fxsave struct gets correct alignment.
kono
parents:
diff changeset
37 See PR27537 and PR28621. */
kono
parents:
diff changeset
38 __attribute__ ((force_align_arg_pointer))
kono
parents:
diff changeset
39 set_fast_math_sse (unsigned int edx)
kono
parents:
diff changeset
40 {
kono
parents:
diff changeset
41 unsigned int mxcsr;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 if (edx & bit_FXSAVE)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 /* Check if DAZ is available. */
kono
parents:
diff changeset
46 struct
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 unsigned short cwd;
kono
parents:
diff changeset
49 unsigned short swd;
kono
parents:
diff changeset
50 unsigned short twd;
kono
parents:
diff changeset
51 unsigned short fop;
kono
parents:
diff changeset
52 unsigned int fip;
kono
parents:
diff changeset
53 unsigned int fcs;
kono
parents:
diff changeset
54 unsigned int foo;
kono
parents:
diff changeset
55 unsigned int fos;
kono
parents:
diff changeset
56 unsigned int mxcsr;
kono
parents:
diff changeset
57 unsigned int mxcsr_mask;
kono
parents:
diff changeset
58 unsigned int st_space[32];
kono
parents:
diff changeset
59 unsigned int xmm_space[32];
kono
parents:
diff changeset
60 unsigned int padding[56];
kono
parents:
diff changeset
61 } __attribute__ ((aligned (16))) fxsave;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 /* This is necessary since some implementations of FXSAVE
kono
parents:
diff changeset
64 do not modify reserved areas within the image. */
kono
parents:
diff changeset
65 fxsave.mxcsr_mask = 0;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 __builtin_ia32_fxsave (&fxsave);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 mxcsr = fxsave.mxcsr;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 if (fxsave.mxcsr_mask & MXCSR_DAZ)
kono
parents:
diff changeset
72 mxcsr |= MXCSR_DAZ;
kono
parents:
diff changeset
73 }
kono
parents:
diff changeset
74 else
kono
parents:
diff changeset
75 mxcsr = __builtin_ia32_stmxcsr ();
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 mxcsr |= MXCSR_FTZ;
kono
parents:
diff changeset
78 __builtin_ia32_ldmxcsr (mxcsr);
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80 #endif
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 static void __attribute__((constructor))
kono
parents:
diff changeset
83 set_fast_math (void)
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 #ifndef __x86_64__
kono
parents:
diff changeset
86 unsigned int eax, ebx, ecx, edx;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
kono
parents:
diff changeset
89 return;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 if (edx & bit_SSE)
kono
parents:
diff changeset
92 set_fast_math_sse (edx);
kono
parents:
diff changeset
93 #else
kono
parents:
diff changeset
94 unsigned int mxcsr = __builtin_ia32_stmxcsr ();
kono
parents:
diff changeset
95 mxcsr |= MXCSR_DAZ | MXCSR_FTZ;
kono
parents:
diff changeset
96 __builtin_ia32_ldmxcsr (mxcsr);
kono
parents:
diff changeset
97 #endif
kono
parents:
diff changeset
98 }
kono
parents:
diff changeset
99 #endif