1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/* Subroutines for the gcc driver.
Copyright (C) 2015-2017 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
/* This will be called by the spec parser in gcc.c when it sees
a %:local_cpu_detect(args) construct. Currently it will be called
with either "arch" or "tune" as argument depending on if -march=native
or -mtune=native is to be substituted.
It returns a string containing new command line parameters to be
put at the place of the above two options, depending on what CPU
this is executed. E.g. "-march=zEC12" on a zEC12 for -march=native.
If the routine can't detect a known processor, the -march or -mtune
option is discarded.
ARGC and ARGV are set depending on the actual arguments given
in the spec. */
const char *
s390_host_detect_local_cpu (int argc, const char **argv)
{
const char *cpu = NULL;
char buf[256];
FILE *f;
bool arch;
const char *options = "";
unsigned int has_features;
unsigned int has_processor;
unsigned int is_cpu_z9_109 = 0;
unsigned int has_highgprs = 0;
unsigned int has_dfp = 0;
unsigned int has_te = 0;
unsigned int has_vx = 0;
unsigned int has_opt_esa_zarch = 0;
int i;
if (argc < 1)
return NULL;
arch = strcmp (argv[0], "arch") == 0;
if (!arch && strcmp (argv[0], "tune"))
return NULL;
for (i = 1; i < argc; i++)
if (strcmp (argv[i], "mesa_mzarch") == 0)
has_opt_esa_zarch = 1;
f = fopen ("/proc/cpuinfo", "r");
if (f == NULL)
return NULL;
for (has_features = 0, has_processor = 0;
(has_features == 0 || has_processor == 0)
&& fgets (buf, sizeof (buf), f) != NULL; )
{
if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
{
const char *p;
long machine_id;
p = strstr (buf, "machine = ");
if (p == NULL)
continue;
p += 10;
has_processor = 1;
machine_id = strtol (p, NULL, 16);
switch (machine_id)
{
/* g5 and g6 default to z900 */
case 0x9672:
case 0x2064:
case 0x2066:
cpu = "z900";
break;
case 0x2084:
case 0x2086:
cpu = "z990";
break;
case 0x2094:
case 0x2096:
cpu = "z9-109";
is_cpu_z9_109 = 1;
break;
case 0x2097:
case 0x2098:
cpu = "z10";
break;
case 0x2817:
case 0x2818:
cpu = "z196";
break;
case 0x2827:
case 0x2828:
cpu = "zEC12";
break;
case 0x2964:
cpu = "z13";
break;
default:
cpu = "arch12";
break;
}
}
if (has_features == 0 && strncmp (buf, "features", 8) == 0)
{
const char *p;
p = strchr (buf, ':');
if (p == NULL)
continue;
p++;
while (*p != 0)
{
int i;
while (ISSPACE (*p))
p++;
for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
;
if (i == 3 && strncmp (p, "dfp", 3) == 0)
has_dfp = 1;
else if (i == 2 && strncmp (p, "te", 2) == 0)
has_te = 1;
else if (i == 2 && strncmp (p, "vx", 2) == 0)
has_vx = 1;
else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
has_highgprs = 1;
p += i;
}
has_features = 1;
}
}
fclose (f);
if (cpu == NULL)
return NULL;
if (arch)
{
const char *opt_htm = "";
const char *opt_vx = "";
const char *opt_esa_zarch = "";
/* We may switch off these cpu features but never switch the on
explicitly. This overrides options specified on the command line. */
if (!has_te)
opt_htm = " -mno-htm";
if (!has_vx)
opt_vx = " -mno-vx";
/* However, we set -mzarch only if neither -mzarch nor -mesa are used on
the command line. This allows the user to switch to -mesa manually.
*/
if (!has_opt_esa_zarch && has_highgprs)
opt_esa_zarch = " -mzarch";
options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
}
if (has_dfp && is_cpu_z9_109)
cpu = "z9-ec";
return concat ("-m", argv[0], "=", cpu, options, NULL);
}
|