* config/sparc/sparc.c (sparc_option_override): Set MASK_FSMULD flag
[official-gcc.git] / gcc / config / sparc / driver-sparc.c
blob0c25d6cfa1509bd47780fc5befef98597636aa94
1 /* Subroutines for the gcc driver.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
25 static const struct cpu_names {
26 const char *const name;
27 const char *const cpu;
28 } cpu_names[] = {
29 #if defined __sun__ && defined __svr4__
30 { "TMS390S10", "supersparc" }, /* Texas Instruments microSPARC I */
31 { "TMS390Z50", "supersparc" }, /* Texas Instruments SuperSPARC I */
32 { "TMS390Z55", "supersparc" }, /* Texas Instruments
33 SuperSPARC I with SuperCache */
34 { "MB86904", "supersparc" }, /* Fujitsu microSPARC II */
35 { "MB86907", "supersparc" }, /* Fujitsu TurboSPARC */
36 { "RT623", "hypersparc" }, /* Ross hyperSPARC */
37 { "RT625", "hypersparc" },
38 { "RT626", "hypersparc" },
39 { "UltraSPARC-I", "ultrasparc" },
40 { "UltraSPARC-II", "ultrasparc" },
41 { "UltraSPARC-IIe", "ultrasparc" },
42 { "UltraSPARC-IIi", "ultrasparc" },
43 { "SPARC64-III", "ultrasparc" },
44 { "SPARC64-IV", "ultrasparc" },
45 { "UltraSPARC-III", "ultrasparc3" },
46 { "UltraSPARC-III+", "ultrasparc3" },
47 { "UltraSPARC-IIIi", "ultrasparc3" },
48 { "UltraSPARC-IIIi+", "ultrasparc3" },
49 { "UltraSPARC-IV", "ultrasparc3" },
50 { "UltraSPARC-IV+", "ultrasparc3" },
51 { "SPARC64-V", "ultrasparc3" },
52 { "SPARC64-VI", "ultrasparc3" },
53 { "SPARC64-VII", "ultrasparc3" },
54 { "UltraSPARC-T1", "niagara" },
55 { "UltraSPARC-T2", "niagara2" },
56 { "UltraSPARC-T2", "niagara2" },
57 { "UltraSPARC-T2+", "niagara2" },
58 { "SPARC-T3", "niagara3" },
59 { "SPARC-T4", "niagara4" },
60 { "SPARC-T5", "niagara4" },
61 #else
62 { "SuperSparc", "supersparc" },
63 { "HyperSparc", "hypersparc" },
64 { "SpitFire", "ultrasparc" },
65 { "BlackBird", "ultrasparc" },
66 { "Sabre", "ultrasparc" },
67 { "Hummingbird", "ultrasparc" },
68 { "Cheetah", "ultrasparc3" },
69 { "Jalapeno", "ultrasparc3" },
70 { "Jaguar", "ultrasparc3" },
71 { "Panther", "ultrasparc3" },
72 { "Serrano", "ultrasparc3" },
73 { "UltraSparc T1", "niagara" },
74 { "UltraSparc T2", "niagara2" },
75 { "UltraSparc T3", "niagara3" },
76 { "UltraSparc T4", "niagara4" },
77 { "UltraSparc T5", "niagara4" },
78 { "LEON", "leon3" },
79 #endif
80 { "SPARC-M7", "niagara7" },
81 { "SPARC-S7", "niagara7" },
82 { "SPARC-M8", "m8" },
83 { NULL, NULL }
86 #if defined __sun__ && defined __svr4__
87 #include <kstat.h>
88 #endif
90 /* This will be called by the spec parser in gcc.c when it sees
91 a %:local_cpu_detect(args) construct. Currently it will be called
92 with either "cpu" or "tune" as argument depending on if -mcpu=native
93 or -mtune=native is to be substituted.
95 It returns a string containing new command line parameters to be
96 put at the place of the above two options, depending on what CPU
97 this is executed. E.g. "-mcpu=ultrasparc3" on an UltraSPARC III for
98 -mcpu=native. If the routine can't detect a known processor,
99 the -mcpu or -mtune option is discarded.
101 ARGC and ARGV are set depending on the actual arguments given
102 in the spec. */
103 const char *
104 host_detect_local_cpu (int argc, const char **argv)
106 const char *cpu = NULL;
107 #if defined __sun__ && defined __svr4__
108 char *buf = NULL;
109 kstat_ctl_t *kc;
110 kstat_t *ksp;
111 kstat_named_t *brand = NULL;
112 #else
113 char buf[128];
114 FILE *f;
115 #endif
116 int i;
118 if (argc < 1)
119 return NULL;
121 if (strcmp (argv[0], "cpu") && strcmp (argv[0], "tune"))
122 return NULL;
124 #if defined __sun__ && defined __svr4__
125 kc = kstat_open ();
126 if (kc != NULL)
128 ksp = kstat_lookup (kc, CONST_CAST2 (char *, const char *, "cpu_info"),
129 -1, NULL);
130 if (ksp != NULL
131 && kstat_read (kc, ksp, NULL) != -1
132 && ksp->ks_type == KSTAT_TYPE_NAMED)
133 brand = (kstat_named_t *)
134 kstat_data_lookup (ksp, CONST_CAST2 (char *, const char *, "brand"));
135 /* "brand" was only introduced in Solaris 10. */
136 if (brand == NULL)
137 brand = (kstat_named_t *)
138 kstat_data_lookup (ksp, CONST_CAST2 (char *, const char *,
139 "implementation"));
140 /* KSTAT_DATA_STRING was introduced in Solaris 9. */
141 #ifdef KSTAT_DATA_STRING
142 if (brand != NULL && brand->data_type == KSTAT_DATA_STRING)
143 buf = KSTAT_NAMED_STR_PTR (brand);
144 #else
145 if (brand != NULL && brand->data_type == KSTAT_DATA_CHAR)
146 buf = brand->value.c;
147 #endif
149 kstat_close (kc);
151 for (i = 0; cpu_names[i].name != NULL; i++)
152 if (strcmp (buf, cpu_names[i].name) == 0)
153 cpu = cpu_names[i].cpu;
154 #else
155 f = fopen ("/proc/cpuinfo", "r");
156 if (f == NULL)
157 return NULL;
159 while (fgets (buf, sizeof (buf), f) != NULL)
160 if (strncmp (buf, "cpu\t\t:", sizeof ("cpu\t\t:") - 1) == 0)
162 for (i = 0; cpu_names [i].name; i++)
163 if (strstr (buf, cpu_names [i].name) != NULL)
165 cpu = cpu_names [i].cpu;
166 break;
168 break;
171 fclose (f);
172 #endif
174 if (cpu == NULL)
175 return NULL;
177 return concat ("-m", argv[0], "=", cpu, NULL);