Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mls3z-0004dR-5m for qemu-devel@nongnu.org; Thu, 10 Sep 2009 18:24:23 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mls3s-0004WW-CZ for qemu-devel@nongnu.org; Thu, 10 Sep 2009 18:24:21 -0400 Received: from [199.232.76.173] (port=40030 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mls3r-0004W9-CQ for qemu-devel@nongnu.org; Thu, 10 Sep 2009 18:24:15 -0400 Received: from tx2ehsobe003.messaging.microsoft.com ([65.55.88.13]:1778 helo=TX2EHSOBE006.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1Mls3q-0001Jq-Tp for qemu-devel@nongnu.org; Thu, 10 Sep 2009 18:24:15 -0400 Received: from mail71-tx2 (localhost.localdomain [127.0.0.1]) by mail71-tx2-R.bigfish.com (Postfix) with ESMTP id 0CAA36D00E7 for ; Thu, 10 Sep 2009 22:24:14 +0000 (UTC) Received: from ausb3extmailp02.amd.com (ausb3extmailp02.amd.com [163.181.251.22]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail71-tx2.bigfish.com (Postfix) with ESMTP id 5DE53840046 for ; Thu, 10 Sep 2009 22:24:12 +0000 (UTC) Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n8AMO7cF021750 for ; Thu, 10 Sep 2009 17:24:11 -0500 Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.0) with ESMTP id 2BFCFC8511 for ; Thu, 10 Sep 2009 17:24:08 -0500 (CDT) From: Andre Przywara Date: Fri, 11 Sep 2009 00:20:54 +0200 Message-ID: <1252621257-26364-10-git-send-email-andre.przywara@amd.com> In-Reply-To: <1252621257-26364-1-git-send-email-andre.przywara@amd.com> References: <1252621257-26364-1-git-send-email-andre.przywara@amd.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 09/12] cpuid: simplify CPUID flag search function List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Andre Przywara avoid code duplication and handle the CPUID flag name search in a loop. Signed-off-by: Andre Przywara --- target-i386/cpuid.c | 33 +++++++++++++-------------------- 1 files changed, 13 insertions(+), 20 deletions(-) diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index e62dc04..4be1449 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -71,29 +71,22 @@ static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features, uint32_t *ext2_features, uint32_t *ext3_features) { - int i; + int i, j; int found = 0; + const char ** feature_names[4] = {feature_name, ext_feature_name, + ext2_feature_name, ext3_feature_name}; + uint32_t* feature_flags[4] = {features, ext_features, + ext2_features, ext3_features}; - 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 (j = 0; j < 4; 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.1.3