Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mobzm-0007s3-6p for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mobze-0007ps-5H for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:18 -0400 Received: from [199.232.76.173] (port=38460 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mobzd-0007pl-Jo for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:13 -0400 Received: from tx2ehsobe004.messaging.microsoft.com ([65.55.88.14]:55136 helo=TX2EHSOBE008.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1Mobzd-0003Kf-73 for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:13 -0400 Received: from mail77-tx2 (localhost.localdomain [127.0.0.1]) by mail77-tx2-R.bigfish.com (Postfix) with ESMTP id 41B931750314 for ; Fri, 18 Sep 2009 11:51:09 +0000 (UTC) Received: from TX2EHSMHS006.bigfish.com (unknown [10.9.14.245]) by mail77-tx2.bigfish.com (Postfix) with ESMTP id 82FC61858050 for ; Fri, 18 Sep 2009 11:51:07 +0000 (UTC) Received: from svlb1twp01.amd.com ([139.95.250.34]) by svlb1extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n8IBoxCx032266 for ; Fri, 18 Sep 2009 04:51:03 -0700 Received: from SSVLEXBH2.amd.com (ssvlexbh2.amd.com [139.95.53.183]) by svlb1twp01.amd.com (Tumbleweed MailGate 3.7.0) with ESMTP id 28AFD19A0149 for ; Fri, 18 Sep 2009 04:51:02 -0700 (PDT) From: Andre Przywara Date: Fri, 18 Sep 2009 13:48:03 +0200 Message-ID: <1253274494-13244-11-git-send-email-andre.przywara@amd.com> In-Reply-To: <1253274494-13244-1-git-send-email-andre.przywara@amd.com> References: <1253274494-13244-1-git-send-email-andre.przywara@amd.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v2 10/21] 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 8243f44..9fdaa6c 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -84,29 +84,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