From patchwork Tue Feb 2 10:08:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 44270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A7ECAB7D23 for ; Tue, 2 Feb 2010 21:30:41 +1100 (EST) Received: from localhost ([127.0.0.1]:58789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcG01-0003GC-2V for incoming@patchwork.ozlabs.org; Tue, 02 Feb 2010 05:28:49 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NcFgb-0002jy-Ko for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:45 -0500 Received: from [199.232.76.173] (port=38601 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcFgZ-0002iB-NO for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:43 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NcFgP-0006tk-KK for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:43 -0500 Received: from va3ehsobe003.messaging.microsoft.com ([216.32.180.13]:34260 helo=VA3EHSOBE003.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1NcFgP-0006tT-6C for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:33 -0500 Received: from mail101-va3-R.bigfish.com (10.7.14.239) by VA3EHSOBE003.bigfish.com (10.7.40.23) with Microsoft SMTP Server id 8.1.240.5; Tue, 2 Feb 2010 10:08:30 +0000 Received: from mail101-va3 (localhost [127.0.0.1]) by mail101-va3-R.bigfish.com (Postfix) with ESMTP id 799C2B48631; Tue, 2 Feb 2010 10:08:30 +0000 (UTC) X-SpamScore: 3 X-BigFish: VPS3(zzab9bh936eMab78ozz1202hzzz32i6bh62h) Received: from mail101-va3 (localhost.localdomain [127.0.0.1]) by mail101-va3 (MessageSwitch) id 1265105310152803_30603; Tue, 2 Feb 2010 10:08:30 +0000 (UTC) Received: from VA3EHSMHS017.bigfish.com (unknown [10.7.14.242]) by mail101-va3.bigfish.com (Postfix) with ESMTP id 21702890013; Tue, 2 Feb 2010 10:08:30 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by VA3EHSMHS017.bigfish.com (10.7.99.27) with Microsoft SMTP Server (TLS) id 14.0.482.39; Tue, 2 Feb 2010 10:08:29 +0000 Received: from ausb3twp01.amd.com (ausb3twp01.amd.com [163.181.250.37]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id o12AA7JX002790; Tue, 2 Feb 2010 04:10:10 -0600 X-WSS-ID: 0KX7LHX-01-GSZ-02 X-M-MSG: Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2DAFE10284A3; Tue, 2 Feb 2010 04:08:21 -0600 (CST) Received: from sausexmb1.amd.com ([163.181.3.156]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Feb 2010 04:08:25 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Feb 2010 04:08:24 -0600 Received: from gwo.osrc.amd.com ([165.204.16.204]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Feb 2010 11:08:19 +0100 Received: from localhost.localdomain (tronje.osrc.amd.com [165.204.15.48]) by gwo.osrc.amd.com (Postfix) with ESMTP id 8E5F449C210; Tue, 2 Feb 2010 10:08:38 +0000 (GMT) From: Andre Przywara To: qemu-devel@nongnu.org Date: Tue, 2 Feb 2010 11:08:16 +0100 Message-ID: <1265105301-3455-9-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1265105301-3455-1-git-send-email-andre.przywara@amd.com> References: <1265105301-3455-1-git-send-email-andre.przywara@amd.com> X-OriginalArrivalTime: 02 Feb 2010 10:08:19.0837 (UTC) FILETIME=[A53F22D0:01CAA3EF] MIME-Version: 1.0 X-Reverse-DNS: ausb3extmailp02.amd.com X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ Cc: john.cooper@redhat.com, Andre Przywara Subject: [Qemu-devel] [PATCH 08/13] cpuid: simplify CPUID flag search function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org avoid code duplication and handle the CPUID flag name search in a loop. Signed-off-by: Andre Przywara --- 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);