aboutsummaryrefslogtreecommitdiff
path: root/gcc/common
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2021-12-15 10:54:23 +0100
committerMartin Liska <mliska@suse.cz>2022-12-09 14:24:47 +0100
commitb4e5003eb7d7f26266ea8aadaa53b4ca376b95b6 (patch)
tree72db8f80972a6ada32c238f5d92f2d602b5b3753 /gcc/common
parent58791f4db575ad9f952025c5eac4cc46e5c27019 (diff)
downloadgcc-b4e5003eb7d7f26266ea8aadaa53b4ca376b95b6.zip
gcc-b4e5003eb7d7f26266ea8aadaa53b4ca376b95b6.tar.gz
gcc-b4e5003eb7d7f26266ea8aadaa53b4ca376b95b6.tar.bz2
i386: simplify cpu_feature handling
The patch removes unneeded loops for cpu_features2 and CONVERT_EXPR that can be simplified with NOP_EXPR. gcc/ChangeLog: * common/config/i386/cpuinfo.h (has_cpu_feature): Directly compute index in cpu_features2. (set_cpu_feature): Likewise. * config/i386/i386-builtins.cc (fold_builtin_cpu): Also remove loop for cpu_features2 and use NOP_EXPRs. (cherry picked from commit ef14bba0a6f3836d41d75863e6516d21aef0e936)
Diffstat (limited to 'gcc/common')
-rw-r--r--gcc/common/config/i386/cpuinfo.h50
1 files changed, 28 insertions, 22 deletions
diff --git a/gcc/common/config/i386/cpuinfo.h b/gcc/common/config/i386/cpuinfo.h
index 4abd548..8843f43 100644
--- a/gcc/common/config/i386/cpuinfo.h
+++ b/gcc/common/config/i386/cpuinfo.h
@@ -55,43 +55,49 @@ struct __processor_model2
static inline int
has_cpu_feature (struct __processor_model *cpu_model,
unsigned int *cpu_features2,
- enum processor_features f)
+ enum processor_features feature)
{
- unsigned int i;
+ unsigned index, offset;
+ unsigned f = feature;
+
if (f < 32)
{
/* The first 32 features. */
- return cpu_model->__cpu_features[0] & (1U << (f & 31));
+ return cpu_model->__cpu_features[0] & (1U << f);
+ }
+ else
+ {
+ /* The rest of features. cpu_features2[i] contains features from
+ (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
+ f -= 32;
+ index = f / 32;
+ offset = f % 32;
+ return cpu_features2[index] & (1U << offset);
}
- /* The rest of features. cpu_features2[i] contains features from
- (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
- for (i = 0; i < SIZE_OF_CPU_FEATURES; i++)
- if (f < (32 + 32 + i * 32))
- return cpu_features2[i] & (1U << ((f - (32 + i * 32)) & 31));
- gcc_unreachable ();
}
static inline void
set_cpu_feature (struct __processor_model *cpu_model,
unsigned int *cpu_features2,
- enum processor_features f)
+ enum processor_features feature)
{
- unsigned int i;
+ unsigned index, offset;
+ unsigned f = feature;
+
if (f < 32)
{
/* The first 32 features. */
- cpu_model->__cpu_features[0] |= (1U << (f & 31));
- return;
+ cpu_model->__cpu_features[0] |= (1U << f);
+ }
+ else
+ {
+ /* The rest of features. cpu_features2[i] contains features from
+ (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
+ f -= 32;
+ index = f / 32;
+ offset = f % 32;
+ cpu_features2[index] |= (1U << offset);
}
- /* The rest of features. cpu_features2[i] contains features from
- (32 + i * 32) to (31 + 32 + i * 32), inclusively. */
- for (i = 0; i < SIZE_OF_CPU_FEATURES; i++)
- if (f < (32 + 32 + i * 32))
- {
- cpu_features2[i] |= (1U << ((f - (32 + i * 32)) & 31));
- return;
- }
- gcc_unreachable ();
}
/* Get the specific type of AMD CPU and return AMD CPU name. Return