[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/13] cpuid: simplify CPUID flag search function
From: |
Andre Przywara |
Subject: |
[Qemu-devel] [PATCH 08/13] cpuid: simplify CPUID flag search function |
Date: |
Tue, 2 Feb 2010 11:08:16 +0100 |
avoid code duplication and handle the CPUID flag name search in a
loop.
Signed-off-by: Andre Przywara <address@hidden>
---
target-i386/cpuid.c | 38 +++++++++++++-------------------------
1 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 3f56c50..635c2f4 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -90,34 +90,22 @@ static void add_flagname_to_bitmaps(const char *flagname,
uint32_t *features,
uint32_t *ext3_features,
uint32_t *kvm_features)
{
- int i;
+ int i, j;
int found = 0;
-
- for ( i = 0 ; i < 32 ; i++ )
- if (feature_name[i] && !strcmp (flagname, feature_name[i])) {
- *features |= 1 << i;
- found = 1;
- }
- for ( i = 0 ; i < 32 ; i++ )
- if (ext_feature_name[i] && !strcmp (flagname, ext_feature_name[i])) {
- *ext_features |= 1 << i;
- found = 1;
- }
- for ( i = 0 ; i < 32 ; i++ )
- if (ext2_feature_name[i] && !strcmp (flagname, ext2_feature_name[i])) {
- *ext2_features |= 1 << i;
- found = 1;
- }
- for ( i = 0 ; i < 32 ; i++ )
- if (ext3_feature_name[i] && !strcmp (flagname, ext3_feature_name[i])) {
- *ext3_features |= 1 << i;
- found = 1;
- }
- for ( i = 0 ; i < 32 ; i++ )
- if (kvm_feature_name[i] && !strcmp (flagname, kvm_feature_name[i])) {
- *kvm_features |= 1 << i;
- found = 1;
+ const char ** feature_names[5] = {feature_name, ext_feature_name,
+ ext2_feature_name, ext3_feature_name,
+ kvm_feature_name};
+ uint32_t* feature_flags[5] = {features, ext_features, ext2_features,
+ ext3_features, kvm_features};
+
+ for (j = 0; j < 5; j++) {
+ for ( i = 0 ; i < 32 ; i++ ) {
+ if (feature_names[j][i] && !strcmp(flagname, feature_names[j][i]))
{
+ *feature_flags[j] |= 1 << i;
+ found = 1;
+ }
}
+ }
if (!found) {
fprintf(stderr, "CPU feature %s not found\n", flagname);
--
1.6.4
- [Qemu-devel] [PATCH 00/13] i386 cpuid: cleanup and fixes, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 02/13] cpuid: replace magic number with named constant, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 05/13] cpuid: add missing CPUID feature flag names, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 08/13] cpuid: simplify CPUID flag search function,
Andre Przywara <=
- [Qemu-devel] [PATCH 11/13] cpuid: Always expose 32 and 64-bit CPUs, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 10/13] cpuid: add TCG feature bit trimming, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 03/13] cpuid: moved host_cpuid function and remove prototype, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 09/13] cpuid: propagate further CPUID leafs when -cpu host, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 04/13] cpuid: Replace strtok with get_opt_name, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 01/13] cpuid: move CPUID functions into separate file, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 07/13] cpuid: remove unnecessary kvm_trim function, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 06/13] cpuid: list all known x86 CPUID feature flags, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 12/13] cpuid: Add kvm32 CPU model, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 13/13] cpuid: fix CPUID levels, Andre Przywara, 2010/02/02