From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: David Gibson <david@gibson.dropbear.id.au>,
Alexander Graf <agraf@suse.de>,
qemu-ppc@nongnu.org
Subject: [Qemu-devel] [PATCH v2 5/8] ppc: replace inter-function cyclic dependency/recurssion with 2 simple lookups
Date: Wed, 30 Aug 2017 15:24:32 +0200 [thread overview]
Message-ID: <1504099475-241036-6-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1504099475-241036-1-git-send-email-imammedo@redhat.com>
previous patches cleaned up cpu model/alias naming which
allows to simplify cpu model/alias to cpu type lookup a bit
byt removing recurssion and dependency of ppc_cpu_class_by_name() /
ppc_cpu_class_by_alias() on each other.
Besides of simplifying code it reduces it by ~15LOC.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
v2:
s/g_ascii_strup/g_ascii_strdown/ due to switch to lower-cased model names
---
target/ppc/translate_init.c | 43 +++++++++++++------------------------------
1 file changed, 13 insertions(+), 30 deletions(-)
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index 0325226..cf0d795 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -10176,22 +10176,6 @@ PowerPCCPUClass *ppc_cpu_class_by_pvr_mask(uint32_t pvr)
return pcc;
}
-static gint ppc_cpu_compare_class_name(gconstpointer a, gconstpointer b)
-{
- ObjectClass *oc = (ObjectClass *)a;
- const char *name = b;
- PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
-
- if (strncasecmp(name, object_class_get_name(oc), strlen(name)) == 0 &&
- ppc_cpu_is_valid(pcc) &&
- strcmp(object_class_get_name(oc) + strlen(name),
- POWERPC_CPU_TYPE_SUFFIX) == 0) {
- return 0;
- }
- return -1;
-}
-
-
static ObjectClass *ppc_cpu_class_by_name(const char *name);
static ObjectClass *ppc_cpu_class_by_alias(PowerPCCPUAlias *alias)
@@ -10216,8 +10200,8 @@ static ObjectClass *ppc_cpu_class_by_alias(PowerPCCPUAlias *alias)
static ObjectClass *ppc_cpu_class_by_name(const char *name)
{
- GSList *list, *item;
- ObjectClass *ret = NULL;
+ char *cpu_model, *typename;
+ ObjectClass *oc;
const char *p;
int i, len;
@@ -10238,21 +10222,20 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name)
}
}
- list = object_class_get_list(TYPE_POWERPC_CPU, false);
- item = g_slist_find_custom(list, name, ppc_cpu_compare_class_name);
- if (item != NULL) {
- ret = OBJECT_CLASS(item->data);
+ cpu_model = g_ascii_strdown(name, -1);
+ p = ppc_cpu_lookup_alias(cpu_model);
+ if (p) {
+ g_free(cpu_model);
+ cpu_model = g_strdup(p);
}
- g_slist_free(list);
- if (ret) {
- return ret;
- }
+ typename = g_strdup_printf("%s" POWERPC_CPU_TYPE_SUFFIX, cpu_model);
+ oc = object_class_by_name(typename);
+ g_free(typename);
+ g_free(cpu_model);
- for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
- if (strcasecmp(ppc_cpu_aliases[i].alias, name) == 0) {
- return ppc_cpu_class_by_alias(&ppc_cpu_aliases[i]);
- }
+ if (oc && ppc_cpu_is_valid(POWERPC_CPU_CLASS(oc))) {
+ return oc;
}
return NULL;
--
2.7.4
next prev parent reply other threads:[~2017-08-30 13:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-30 13:24 [Qemu-devel] [PATCH v2 0/8] ppc: cpu_model handling cleanups Igor Mammedov
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 1/8] ppc: replace cpu_ppc_init() with cpu_generic_init() Igor Mammedov
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 2/8] ppc: use macros to make cpu type name from string literal Igor Mammedov
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 3/8] ppc: make cpu_model translation to type consistent Igor Mammedov
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 4/8] ppc: make cpu alias point only to real cpu models Igor Mammedov
2017-08-30 13:24 ` Igor Mammedov [this message]
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 6/8] ppc: simplify cpu model lookup by PVR Igor Mammedov
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 7/8] ppc: drop caching ObjectClass from PowerPCCPUAlias Igor Mammedov
2017-08-30 13:24 ` [Qemu-devel] [PATCH v2 8/8] ppc: remove non implemented cpu models Igor Mammedov
2017-08-30 13:46 ` [Qemu-devel] [Qemu-ppc] " Thomas Huth
2017-08-30 14:14 ` Igor Mammedov
2017-08-30 14:26 ` [Qemu-devel] [PATCH v2 9/8] fixup! " Igor Mammedov
2017-08-30 14:44 ` [Qemu-devel] [Qemu-ppc] " Thomas Huth
2017-09-04 11:10 ` [Qemu-devel] " David Gibson
2017-09-04 13:05 ` Igor Mammedov
2017-08-31 7:58 ` [Qemu-devel] [Qemu-ppc] [PATCH v2 8/8] " Thomas Huth
2017-08-31 8:35 ` Igor Mammedov
2017-08-31 8:36 ` Thomas Huth
2017-09-04 4:29 ` [Qemu-devel] [PATCH v2 0/8] ppc: cpu_model handling cleanups David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1504099475-241036-6-git-send-email-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=agraf@suse.de \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).