From patchwork Fri Jan 4 19:56:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 209536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C031A2C0079 for ; Sat, 5 Jan 2013 07:17:39 +1100 (EST) Received: from localhost ([::1]:53436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrDMg-0002A7-SR for incoming@patchwork.ozlabs.org; Fri, 04 Jan 2013 14:55:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrDLu-0000HC-G8 for qemu-devel@nongnu.org; Fri, 04 Jan 2013 14:54:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TrDLr-00088j-Th for qemu-devel@nongnu.org; Fri, 04 Jan 2013 14:54:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrDLr-00088B-LD for qemu-devel@nongnu.org; Fri, 04 Jan 2013 14:54:47 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r04JskBC030332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Jan 2013 14:54:46 -0500 Received: from blackpad.lan.raisama.net (vpn1-7-13.gru2.redhat.com [10.97.7.13]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r04JsjEQ002839; Fri, 4 Jan 2013 14:54:45 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 830B6203D27; Fri, 4 Jan 2013 17:56:24 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 4 Jan 2013 17:56:19 -0200 Message-Id: <1357329382-20944-4-git-send-email-ehabkost@redhat.com> In-Reply-To: <1357329382-20944-1-git-send-email-ehabkost@redhat.com> References: <1357329382-20944-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC 3/6] target-i386: Simplify cpu_x86_find_by_name() logic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move the check for "host" to beginning of function, so instead of a confusing if/else-if/else mess we now have just two obvious if/else blocks: 1) Special case for "host"; 2) General case for CPU model lookup on x86_defs list. This way, we will be able to easily move those two parts to separate class instance_init functions. Signed-off-by: Eduardo Habkost --- target-i386/cpu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 6c75327..a2ac3c3 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1250,20 +1250,24 @@ static void cpudef_2_x86_cpu(X86CPU *cpu, x86_def_t *def, Error **errp) static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name) { - x86_def_t *def; - for (def = x86_defs; def; def = def->next) { - if (name && !strcmp(name, def->name)) { - break; - } - } if (kvm_enabled() && name && strcmp(name, "host") == 0) { #ifdef CONFIG_KVM kvm_cpu_fill_host(x86_cpu_def); #endif - } else if (!def) { - return -1; } else { + x86_def_t *def; + + for (def = x86_defs; def; def = def->next) { + if (name && !strcmp(name, def->name)) { + break; + } + } + + if (!def) { + return -1; + } + memcpy(x86_cpu_def, def, sizeof(*def)); /* sysenter isn't supported on compatibility mode on AMD, syscall * isn't supported in compatibility mode on Intel.