diff options
author | Martin Liska <mliska@suse.cz> | 2021-12-15 10:54:23 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2022-05-11 11:03:18 +0200 |
commit | ef14bba0a6f3836d41d75863e6516d21aef0e936 (patch) | |
tree | 83486d168a2b552a62e57d24a8d897b716d37094 /gcc/common | |
parent | b0fd3e3120e83bcd783d5c2443bade7cef20814a (diff) | |
download | gcc-ef14bba0a6f3836d41d75863e6516d21aef0e936.zip gcc-ef14bba0a6f3836d41d75863e6516d21aef0e936.tar.gz gcc-ef14bba0a6f3836d41d75863e6516d21aef0e936.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.
Diffstat (limited to 'gcc/common')
-rw-r--r-- | gcc/common/config/i386/cpuinfo.h | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/gcc/common/config/i386/cpuinfo.h b/gcc/common/config/i386/cpuinfo.h index 239759d..6d6171f 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 |