From 6c35d16a3925958b3a22426de0cb8e04f654b6dd Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 24 Jun 2020 04:39:16 -0700 Subject: x86: Share _isa_names_table and use cpuinfo.h Both driver-i386.c and libgcc use CPUID to detect the processor name as well as available ISAs. To detect the same processor or ISAs, the same detection logic is duplicated in 2 places. Sometimes only one place was up to date or got it right. Sometimes both places got it wrong. 1. Add common/config/i386/i386-isas.h to define _isa_names_table. 2. Use isa_names_table to auto-generate ISA command-line options. 3. Use isa_names_table to auto-generate __builtin_cpu_supports tests. 4. Use common/config/i386/cpuinfo.h to check available ISAs and detect newer Intel processors in driver-i386.c and builtin_target.c. 5. Detection of AMD processors and older processors in driver-i386.c is unchanged. gcc/ PR target/95843 * common/config/i386/i386-isas.h: New file. Extracted from gcc/config/i386/i386-builtins.c. (_isa_names_table): Add option. (ISA_NAMES_TABLE_START): New. (ISA_NAMES_TABLE_END): Likewise. (ISA_NAMES_TABLE_ENTRY): Likewise. (isa_names_table): Defined with ISA_NAMES_TABLE_START, ISA_NAMES_TABLE_END and ISA_NAMES_TABLE_ENTRY. Add more ISAs from enum processor_features. * config/i386/driver-i386.c: Include "common/config/i386/cpuinfo.h" and "common/config/i386/i386-isas.h". (has_feature): New macro. (host_detect_local_cpu): Call cpu_indicator_init to get CPU features. Use has_feature to detect processor features. Call Call get_intel_cpu to get the newer Intel CPU name. Use isa_names_table to generate command-line options. * config/i386/i386-builtins.c: Include "common/config/i386/i386-isas.h". (_arch_names_table): Removed. (isa_names_table): Likewise. gcc/testsuite/ PR target/95843 * gcc.target/i386/builtin_target.c: Include , ../../../common/config/i386/i386-cpuinfo.h and ../../../common/config/i386/cpuinfo.h. (check_amd_cpu_model): Removed. (check_intel_cpu_model): Likewise, (CHECK___builtin_cpu_is): New. (gcc_assert): New. Defined as assert. (gcc_unreachable): New. Defined as abort. (inline): New. Defined as empty. (ISA_NAMES_TABLE_START): Likewise. (ISA_NAMES_TABLE_END): Likewise. (ISA_NAMES_TABLE_ENTRY): New. (check_features): Include "../../../common/config/i386/i386-isas.h". (check_detailed): Call cpu_indicator_init. Always call check_features. Call get_amd_cpu instead of check_amd_cpu_model. Call get_intel_cpu instead of check_intel_cpu_model. --- gcc/common/config/i386/i386-isas.h | 163 +++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 gcc/common/config/i386/i386-isas.h (limited to 'gcc/common') diff --git a/gcc/common/config/i386/i386-isas.h b/gcc/common/config/i386/i386-isas.h new file mode 100644 index 0000000..08c9dbe --- /dev/null +++ b/gcc/common/config/i386/i386-isas.h @@ -0,0 +1,163 @@ +/* i386 ISA table. + Copyright (C) 2020 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 +. */ + +/* These are the target attribute strings for which a dispatcher is + available, from fold_builtin_cpu. */ +struct _isa_names_table +{ + const char *const name; + const enum processor_features feature; + const enum feature_priority priority; + const char *const option; +}; + +/* NB: isa_names_table is shared by i386-builtins.c, driver-i386.c and + gcc.target/i386/builtin_target.c. isa_names_table is a static const + array in i386-builtins.c and driver-i386.c. But it is a list of + assert statements in gcc.target/i386/builtin_target.c. */ + +#ifndef ISA_NAMES_TABLE_START +# define ISA_NAMES_TABLE_START \ + static const struct _isa_names_table isa_names_table[] = { +#endif + +#ifndef ISA_NAMES_TABLE_END +# define ISA_NAMES_TABLE_END }; +#endif + +#ifndef ISA_NAMES_TABLE_ENTRY +# define ISA_NAMES_TABLE_ENTRY(name, feature, priority, option) \ + {name, feature, priority, option}, +#endif + +ISA_NAMES_TABLE_START + ISA_NAMES_TABLE_ENTRY("cmov", FEATURE_CMOV, P_NONE, NULL) + ISA_NAMES_TABLE_ENTRY("mmx", FEATURE_MMX, P_MMX, "-mmmx") + ISA_NAMES_TABLE_ENTRY("popcnt", FEATURE_POPCNT, P_POPCNT, "-mpopcnt") + ISA_NAMES_TABLE_ENTRY("sse", FEATURE_SSE, P_SSE, "-msse") + ISA_NAMES_TABLE_ENTRY("sse2", FEATURE_SSE2, P_SSE2, "-msse2") + ISA_NAMES_TABLE_ENTRY("sse3", FEATURE_SSE3, P_SSE3, "-msse3") + ISA_NAMES_TABLE_ENTRY("ssse3", FEATURE_SSSE3, P_SSSE3, "-mssse3") + ISA_NAMES_TABLE_ENTRY("sse4.1", FEATURE_SSE4_1, P_SSE4_1, "-msse4.1") + ISA_NAMES_TABLE_ENTRY("sse4.2", FEATURE_SSE4_2, P_SSE4_2, "-msse4.2") + ISA_NAMES_TABLE_ENTRY("avx", FEATURE_AVX, P_AVX, "-mavx") + ISA_NAMES_TABLE_ENTRY("avx2", FEATURE_AVX2, P_AVX2, "-mavx2") + ISA_NAMES_TABLE_ENTRY("sse4a", FEATURE_SSE4_A, P_SSE4_A, "-msse4a") + ISA_NAMES_TABLE_ENTRY("fma4", FEATURE_FMA4, P_FMA4, "-mfma4") + ISA_NAMES_TABLE_ENTRY("xop", FEATURE_XOP, P_XOP, "-mxop") + ISA_NAMES_TABLE_ENTRY("fma", FEATURE_FMA, P_FMA, "-mfma") + ISA_NAMES_TABLE_ENTRY("avx512f", FEATURE_AVX512F, P_AVX512F, + "-mavx512f") + ISA_NAMES_TABLE_ENTRY("bmi", FEATURE_BMI, P_BMI, "-mbmi") + ISA_NAMES_TABLE_ENTRY("bmi2", FEATURE_BMI2, P_BMI2, "-mbmi2") + ISA_NAMES_TABLE_ENTRY("aes", FEATURE_AES, P_AES, "-maes") + ISA_NAMES_TABLE_ENTRY("pclmul", FEATURE_PCLMUL, P_PCLMUL, "-mpclmul") + ISA_NAMES_TABLE_ENTRY("avx512vl", FEATURE_AVX512VL, P_NONE, + "-mavx512vl") + ISA_NAMES_TABLE_ENTRY("avx512bw", FEATURE_AVX512BW, P_NONE, + "-mavx512bw") + ISA_NAMES_TABLE_ENTRY("avx512dq", FEATURE_AVX512DQ, P_NONE, + "-mavx512dq") + ISA_NAMES_TABLE_ENTRY("avx512cd", FEATURE_AVX512CD, P_NONE, + "-mavx512cd") + ISA_NAMES_TABLE_ENTRY("avx512er", FEATURE_AVX512ER, P_NONE, + "-mavx512er") + ISA_NAMES_TABLE_ENTRY("avx512pf", FEATURE_AVX512PF, P_NONE, + "-mavx512pf") + ISA_NAMES_TABLE_ENTRY("avx512vbmi", FEATURE_AVX512VBMI, P_NONE, + "-mavx512vbmi") + ISA_NAMES_TABLE_ENTRY("avx512ifma", FEATURE_AVX512IFMA, P_NONE, + "-mavx512ifma") + ISA_NAMES_TABLE_ENTRY("avx5124vnniw", FEATURE_AVX5124VNNIW, P_NONE, + "-mavx5124vnniw") + ISA_NAMES_TABLE_ENTRY("avx5124fmaps", FEATURE_AVX5124FMAPS, P_NONE, + "-mavx5124fmaps") + ISA_NAMES_TABLE_ENTRY("avx512vpopcntdq", FEATURE_AVX512VPOPCNTDQ, + P_NONE, "-mavx512vpopcntdq") + ISA_NAMES_TABLE_ENTRY("avx512vbmi2", FEATURE_AVX512VBMI2, P_NONE, + "-mavx512vbmi2") + ISA_NAMES_TABLE_ENTRY("gfni", FEATURE_GFNI, P_NONE, "-mgfni") + ISA_NAMES_TABLE_ENTRY("vpclmulqdq", FEATURE_VPCLMULQDQ, P_NONE, + "-mvpclmulqdq") + ISA_NAMES_TABLE_ENTRY("avx512vnni", FEATURE_AVX512VNNI, P_NONE, + "-mavx512vnni") + ISA_NAMES_TABLE_ENTRY("avx512bitalg", FEATURE_AVX512BITALG, P_NONE, + "-mavx512bitalg") + ISA_NAMES_TABLE_ENTRY("avx512bf16", FEATURE_AVX512BF16, P_NONE, + "-mavx512bf16") + ISA_NAMES_TABLE_ENTRY("avx512vp2intersect", FEATURE_AVX512VP2INTERSECT, + P_NONE, "-mavx512vp2intersect") + ISA_NAMES_TABLE_ENTRY("3dnow", FEATURE_3DNOW, P_NONE, "-m3dnow") + ISA_NAMES_TABLE_ENTRY("3dnowp", FEATURE_3DNOWP, P_NONE, NULL) + ISA_NAMES_TABLE_ENTRY("adx", FEATURE_ADX, P_NONE, "-madx") + ISA_NAMES_TABLE_ENTRY("abm", FEATURE_ABM, P_NONE, "-mabm") + ISA_NAMES_TABLE_ENTRY("cldemote", FEATURE_CLDEMOTE, P_NONE, + "-mcldemote") + ISA_NAMES_TABLE_ENTRY("clflushopt", FEATURE_CLFLUSHOPT, P_NONE, + "-mclflushopt") + ISA_NAMES_TABLE_ENTRY("clwb", FEATURE_CLWB, P_NONE, "-mclwb") + ISA_NAMES_TABLE_ENTRY("clzero", FEATURE_CLZERO, P_NONE, "-mclzero") + ISA_NAMES_TABLE_ENTRY("cmpxchg16b", FEATURE_CMPXCHG16B, P_NONE, + "-mcx16") + ISA_NAMES_TABLE_ENTRY("cmpxchg8b", FEATURE_CMPXCHG8B, P_NONE, NULL) + ISA_NAMES_TABLE_ENTRY("enqcmd", FEATURE_ENQCMD, P_NONE, "-menqcmd") + ISA_NAMES_TABLE_ENTRY("f16c", FEATURE_F16C, P_NONE, "-mf16c") + ISA_NAMES_TABLE_ENTRY("fsgsbase", FEATURE_FSGSBASE, P_NONE, + "-mfsgsbase") + ISA_NAMES_TABLE_ENTRY("fxsave", FEATURE_FXSAVE, P_NONE, "-mfxsr") + ISA_NAMES_TABLE_ENTRY("hle", FEATURE_HLE, P_NONE, "-mhle") + ISA_NAMES_TABLE_ENTRY("ibt", FEATURE_IBT, P_NONE, NULL) + ISA_NAMES_TABLE_ENTRY("lahf_lm", FEATURE_LAHF_LM, P_NONE, "-msahf") + ISA_NAMES_TABLE_ENTRY("lm", FEATURE_LM, P_NONE, NULL) + ISA_NAMES_TABLE_ENTRY("lwp", FEATURE_LWP, P_NONE, "-mlwp") + ISA_NAMES_TABLE_ENTRY("lzcnt", FEATURE_LZCNT, P_NONE, "-mlzcnt") + ISA_NAMES_TABLE_ENTRY("movbe", FEATURE_MOVBE, P_NONE, "-mmovbe") + ISA_NAMES_TABLE_ENTRY("movdir64b", FEATURE_MOVDIR64B, P_NONE, + "-mmovdir64b") + ISA_NAMES_TABLE_ENTRY("movdiri", FEATURE_MOVDIRI, P_NONE, "-mmovdiri") + ISA_NAMES_TABLE_ENTRY("mwaitx", FEATURE_MWAITX, P_NONE, "-mmwaitx") + ISA_NAMES_TABLE_ENTRY("osxsave", FEATURE_OSXSAVE, P_NONE, NULL) + ISA_NAMES_TABLE_ENTRY("pconfig", FEATURE_PCONFIG, P_NONE, "-mpconfig") + ISA_NAMES_TABLE_ENTRY("pku", FEATURE_PKU, P_NONE, "-mpku") + ISA_NAMES_TABLE_ENTRY("prefetchwt1", FEATURE_PREFETCHWT1, P_NONE, + "-mprefetchwt1") + ISA_NAMES_TABLE_ENTRY("prfchw", FEATURE_PRFCHW, P_NONE, "-mprfchw") + ISA_NAMES_TABLE_ENTRY("ptwrite", FEATURE_PTWRITE, P_NONE, "-mptwrite") + ISA_NAMES_TABLE_ENTRY("rdpid", FEATURE_RDPID, P_NONE, "-mrdpid") + ISA_NAMES_TABLE_ENTRY("rdrnd", FEATURE_RDRND, P_NONE, "-mrdrnd") + ISA_NAMES_TABLE_ENTRY("rdseed", FEATURE_RDSEED, P_NONE, "-mrdseed") + ISA_NAMES_TABLE_ENTRY("rtm", FEATURE_RTM, P_NONE, "-mrtm") + ISA_NAMES_TABLE_ENTRY("serialize", FEATURE_SERIALIZE, P_NONE, + "-mserialize") + ISA_NAMES_TABLE_ENTRY("sgx", FEATURE_SGX, P_NONE, "-msgx") + ISA_NAMES_TABLE_ENTRY("sha", FEATURE_SHA, P_NONE, "-msha") + ISA_NAMES_TABLE_ENTRY("shstk", FEATURE_SHSTK, P_NONE, "-mshstk") + ISA_NAMES_TABLE_ENTRY("tbm", FEATURE_TBM, P_NONE, "-mtbm") + ISA_NAMES_TABLE_ENTRY("tsxldtrk", FEATURE_TSXLDTRK, P_NONE, + "-mtsxldtrk") + ISA_NAMES_TABLE_ENTRY("vaes", FEATURE_VAES, P_NONE, "-mvaes") + ISA_NAMES_TABLE_ENTRY("waitpkg", FEATURE_WAITPKG, P_NONE, "-mwaitpkg") + ISA_NAMES_TABLE_ENTRY("wbnoinvd", FEATURE_WBNOINVD, P_NONE, + "-mwbnoinvd") + ISA_NAMES_TABLE_ENTRY("xsave", FEATURE_XSAVE, P_NONE, "-mxsave") + ISA_NAMES_TABLE_ENTRY("xsavec", FEATURE_XSAVEC, P_NONE, "-mxsavec") + ISA_NAMES_TABLE_ENTRY("xsaveopt", FEATURE_XSAVEOPT, P_NONE, + "-mxsaveopt") + ISA_NAMES_TABLE_ENTRY("xsaves", FEATURE_XSAVES, P_NONE, "-mxsaves") +ISA_NAMES_TABLE_END -- cgit v1.1