diff mbox

[qom-cpu,7/9] target-i386: Use FeatureWord loop on filter_features_for_kvm()

Message ID 1366657220-776-8-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost April 22, 2013, 7 p.m. UTC
Instead of open-coding the filtering code for each feature word, change
the existing code to use the feature_word_info array, that have exactly
the same CPUID eax/ecx/register values for each feature word.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

Comments

Eric Blake May 3, 2013, 3:01 p.m. UTC | #1
On 04/22/2013 01:00 PM, Eduardo Habkost wrote:
> Instead of open-coding the filtering code for each feature word, change
> the existing code to use the feature_word_info array, that have exactly
> the same CPUID eax/ecx/register values for each feature word.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c | 24 +++++++-----------------
>  1 file changed, 7 insertions(+), 17 deletions(-)
> 

> +    for (w = 0; w < FEATURE_WORDS; w++) {
> +        FeatureWordInfo *wi = &feature_word_info[w];
> +        env->features[w] &= kvm_arch_get_supported_cpuid(s, wi->cpuid_eax,
> +                                                            wi->cpuid_ecx,
> +                                                            wi->cpuid_reg);

Indentation is unusual, but the resulting alignment is nicer than having
'wi->' flush under 's'.  I would have written the call in four lines
instead of 3, but that's not essential.

Reviewed-by: Eric Blake <eblake@redhat.com>
Andreas Färber May 6, 2013, 4:28 p.m. UTC | #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 03.05.2013 17:01, schrieb Eric Blake:
> On 04/22/2013 01:00 PM, Eduardo Habkost wrote:
>> Instead of open-coding the filtering code for each feature word,
>> change the existing code to use the feature_word_info array, that
>> have exactly the same CPUID eax/ecx/register values for each
>> feature word.
>> 
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- 
>> target-i386/cpu.c | 24 +++++++----------------- 1 file changed, 7
>> insertions(+), 17 deletions(-)
>> 
> 
>> +    for (w = 0; w < FEATURE_WORDS; w++) { +
>> FeatureWordInfo *wi = &feature_word_info[w]; +
>> env->features[w] &= kvm_arch_get_supported_cpuid(s,
>> wi->cpuid_eax, +
>> wi->cpuid_ecx, +
>> wi->cpuid_reg);
> 
> Indentation is unusual, but the resulting alignment is nicer than
> having 'wi->' flush under 's'.  I would have written the call in
> four lines instead of 3, but that's not essential.
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

- -- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iQIcBAEBAgAGBQJRh9oXAAoJEPou0S0+fgE/oksP/1SKyK1oTJs9l7GG5atYxav7
7bDM/Pf4wTx63vs19XmvoaKCBBHYVhxM8RhXYRBFn1SHQhiXiJmgTpNDTpE9L+yq
CpoXTyL/oReB32cUEeZYBjYWdG62IV8Ci09+FUhhmf4cduBQTXFV7i5jq/9IDooi
fMUoksVGHeLOHvsUPFp3OSlO24KRCO0z/w8O74/fPzdrmrz3cMRxy7V59/ZHsNPg
lAkXiFu56whYcA62A76HvRW200P75I8BuLq7NCPffFwMf9/N6eba7Wep0J1xnzpG
GkXB7swuOENKRVPbZ6XKrCIAH96kk6WbJaXPrPplP6jATXhhuChlyyskrEz++hne
XjjFAGOLFGrLuD+3eIB4VZ509GE+hUfyAG6JQWf+7BG20scepvsOgaPT/rvNyDjN
LQnL/BJoV1+s4YKuZCIv3km/WQ76oNRNSlmA+R+KKCEfjOsl8Byg3L6/YSE4TaPs
RiNXZTh0HkcyMzTYNdEOcxZcpW0G77jRAV7L3fMPd0TMixY8oKsqW4wg9pvZodLg
yeCRn1N+op9HDj9W9qAq8IXwJiuLEKpCu2hqzVpYJRxws7ZAo7tfI5+ym1AMj4FZ
pEb87EXqEqESzeWJS4XJZxaPw14WaWInWkNXhdq0J3J78UkB2pHnvAr2dDL9FvPx
9o6UzZiavkgcd860Im4J
=4ouF
-----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 757749c..bdb94a7 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1638,24 +1638,14 @@  static void filter_features_for_kvm(X86CPU *cpu)
 {
     CPUX86State *env = &cpu->env;
     KVMState *s = kvm_state;
+    FeatureWord w;
 
-    env->features[FEAT_1_EDX] &=
-        kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX);
-    env->features[FEAT_1_ECX] &=
-        kvm_arch_get_supported_cpuid(s, 1, 0, R_ECX);
-    env->features[FEAT_8000_0001_EDX] &=
-        kvm_arch_get_supported_cpuid(s, 0x80000001, 0, R_EDX);
-    env->features[FEAT_8000_0001_ECX] &=
-        kvm_arch_get_supported_cpuid(s, 0x80000001, 0, R_ECX);
-    env->features[FEAT_SVM]  &=
-        kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX);
-    env->features[FEAT_7_0_EBX] &=
-        kvm_arch_get_supported_cpuid(s, 7, 0, R_EBX);
-    env->features[FEAT_KVM] &=
-        kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX);
-    env->features[FEAT_C000_0001_EDX] &=
-        kvm_arch_get_supported_cpuid(s, 0xC0000001, 0, R_EDX);
-
+    for (w = 0; w < FEATURE_WORDS; w++) {
+        FeatureWordInfo *wi = &feature_word_info[w];
+        env->features[w] &= kvm_arch_get_supported_cpuid(s, wi->cpuid_eax,
+                                                            wi->cpuid_ecx,
+                                                            wi->cpuid_reg);
+    }
 }
 #endif