comparison gcc/config/aarch64/driver-aarch64.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Native CPU detection for aarch64. 1 /* Native CPU detection for aarch64.
2 Copyright (C) 2015-2018 Free Software Foundation, Inc. 2 Copyright (C) 2015-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify 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 7 it under the terms of the GNU General Public License as published by
30 unsigned long); 30 unsigned long);
31 31
32 struct aarch64_arch_extension 32 struct aarch64_arch_extension
33 { 33 {
34 const char *ext; 34 const char *ext;
35 unsigned int flag; 35 uint64_t flag;
36 const char *feat_string; 36 const char *feat_string;
37 }; 37 };
38 38
39 #define AARCH64_OPT_EXTENSION(EXT_NAME, FLAG_CANONICAL, FLAGS_ON, FLAGS_OFF, FEATURE_STRING) \ 39 #define AARCH64_OPT_EXTENSION(EXT_NAME, FLAG_CANONICAL, FLAGS_ON, FLAGS_OFF, \
40 SYNTHETIC, FEATURE_STRING) \
40 { EXT_NAME, FLAG_CANONICAL, FEATURE_STRING }, 41 { EXT_NAME, FLAG_CANONICAL, FEATURE_STRING },
41 static struct aarch64_arch_extension aarch64_extensions[] = 42 static struct aarch64_arch_extension aarch64_extensions[] =
42 { 43 {
43 #include "aarch64-option-extensions.def" 44 #include "aarch64-option-extensions.def"
44 }; 45 };
49 const char* name; 50 const char* name;
50 const char* arch; 51 const char* arch;
51 unsigned char implementer_id; /* Exactly 8 bits */ 52 unsigned char implementer_id; /* Exactly 8 bits */
52 unsigned int part_no; /* 12 bits + 12 bits */ 53 unsigned int part_no; /* 12 bits + 12 bits */
53 unsigned variant; 54 unsigned variant;
54 const unsigned long flags; 55 const uint64_t flags;
55 }; 56 };
56 57
57 #define AARCH64_BIG_LITTLE(BIG, LITTLE) \ 58 #define AARCH64_BIG_LITTLE(BIG, LITTLE) \
58 (((BIG)&0xFFFu) << 12 | ((LITTLE) & 0xFFFu)) 59 (((BIG)&0xFFFu) << 12 | ((LITTLE) & 0xFFFu))
59 #define INVALID_IMP ((unsigned char) -1) 60 #define INVALID_IMP ((unsigned char) -1)
72 73
73 struct aarch64_arch_driver_info 74 struct aarch64_arch_driver_info
74 { 75 {
75 const char* id; 76 const char* id;
76 const char* name; 77 const char* name;
77 const unsigned long flags; 78 const uint64_t flags;
78 }; 79 };
79 80
80 #define AARCH64_ARCH(NAME, CORE, ARCH_IDENT, ARCH_REV, FLAGS) \ 81 #define AARCH64_ARCH(NAME, CORE, ARCH_IDENT, ARCH_REV, FLAGS) \
81 { #ARCH_IDENT, NAME, FLAGS }, 82 { #ARCH_IDENT, NAME, FLAGS },
82 83
176 unsigned int cores[2] = { INVALID_CORE, INVALID_CORE }; 177 unsigned int cores[2] = { INVALID_CORE, INVALID_CORE };
177 unsigned int n_cores = 0; 178 unsigned int n_cores = 0;
178 unsigned int variants[2] = { ALL_VARIANTS, ALL_VARIANTS }; 179 unsigned int variants[2] = { ALL_VARIANTS, ALL_VARIANTS };
179 unsigned int n_variants = 0; 180 unsigned int n_variants = 0;
180 bool processed_exts = false; 181 bool processed_exts = false;
181 const char *ext_string = ""; 182 uint64_t extension_flags = 0;
182 unsigned long extension_flags = 0; 183 uint64_t default_flags = 0;
183 unsigned long default_flags = 0;
184 184
185 gcc_assert (argc); 185 gcc_assert (argc);
186 186
187 if (!argv[0]) 187 if (!argv[0])
188 goto not_found; 188 goto not_found;
247 } 247 }
248 if (!tune && !processed_exts && strstr (buf, "Features") != NULL) 248 if (!tune && !processed_exts && strstr (buf, "Features") != NULL)
249 { 249 {
250 for (i = 0; i < num_exts; i++) 250 for (i = 0; i < num_exts; i++)
251 { 251 {
252 char *p = NULL; 252 const char *p = aarch64_extensions[i].feat_string;
253 char *feat_string 253
254 = concat (aarch64_extensions[i].feat_string, NULL); 254 /* If the feature contains no HWCAPS string then ignore it for the
255 auto detection. */
256 if (*p == '\0')
257 continue;
258
255 bool enabled = true; 259 bool enabled = true;
256 260
257 /* This may be a multi-token feature string. We need 261 /* This may be a multi-token feature string. We need
258 to match all parts, which could be in any order. 262 to match all parts, which could be in any order. */
259 If this isn't a multi-token feature string, strtok is 263 size_t len = strlen (buf);
260 just going to return a pointer to feat_string. */ 264 do
261 p = strtok (feat_string, " ");
262 while (p != NULL)
263 { 265 {
264 if (strstr (buf, p) == NULL) 266 const char *end = strchr (p, ' ');
267 if (end == NULL)
268 end = strchr (p, '\0');
269 if (memmem (buf, len, p, end - p) == NULL)
265 { 270 {
266 /* Failed to match this token. Turn off the 271 /* Failed to match this token. Turn off the
267 features we'd otherwise enable. */ 272 features we'd otherwise enable. */
268 enabled = false; 273 enabled = false;
269 break; 274 break;
270 } 275 }
271 p = strtok (NULL, " "); 276 if (*end == '\0')
277 break;
278 p = end + 1;
272 } 279 }
280 while (1);
273 281
274 if (enabled) 282 if (enabled)
275 extension_flags |= aarch64_extensions[i].flag; 283 extension_flags |= aarch64_extensions[i].flag;
276 else 284 else
277 extension_flags &= ~(aarch64_extensions[i].flag); 285 extension_flags &= ~(aarch64_extensions[i].flag);
346 } 354 }
347 355
348 if (tune) 356 if (tune)
349 return res; 357 return res;
350 358
351 ext_string 359 {
352 = aarch64_get_extension_string_for_isa_flags (extension_flags, 360 std::string extension
353 default_flags).c_str (); 361 = aarch64_get_extension_string_for_isa_flags (extension_flags,
354 362 default_flags);
355 res = concat (res, ext_string, NULL); 363 res = concat (res, extension.c_str (), NULL);
364 }
356 365
357 return res; 366 return res;
358 367
359 not_found: 368 not_found:
360 { 369 {
361 /* If detection fails we ignore the option. 370 /* If detection fails we ignore the option.
362 Clean up and return empty string. */ 371 Clean up and return NULL. */
363 372
364 if (f) 373 if (f)
365 fclose (f); 374 fclose (f);
366 375
367 return ""; 376 return NULL;
368 } 377 }
369 } 378 }
370 379