From patchwork Fri Sep 8 11:22:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 720800 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp705690wrp; Fri, 8 Sep 2023 04:24:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE88glF8llDB9jYREg1COKGQyoXJ4UscOGCziYR1vffXkfBg37njhEWw7BtL3iecY2hC5Mr X-Received: by 2002:a0c:edb3:0:b0:63c:fbdd:4592 with SMTP id h19-20020a0cedb3000000b0063cfbdd4592mr1835333qvr.31.1694172291075; Fri, 08 Sep 2023 04:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694172291; cv=none; d=google.com; s=arc-20160816; b=lw0ox/rPD1BIv7i3umQI+lMGq3BJyD84GNhuqWKMySffaFbdE/9qvnY7SXHIR5HNkn QYoa6gaWTTFIMEtLpYCTZApFpMOOLSA8edmJ3XZKXZeIsHDi8/Olq3GcOe5BqqOk63LI rvG0XcjCq5yjvYThEnV5siEUgZKBSCkVYMSV5HNT+EMRuMqekupBUXRCP59BXa8lWW4D hDyqa90soBqE5wDNAiK3X1gwSvePQlWlsKoyJoGCkByT3IRSW+ycwlFANod9gq5UUQQg BPEWU7IlfE4BDvtsIMi9bH99FpFE2sl3hCS6yhyRmHS4Q/+1mT3K6SdSWWCE7tr5KjL+ WQIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K/YkGJmASUJnEMaMG4VGJ0aAEtMk9/BNtlzjAdGgNrE=; fh=xrkPdSTzLfgAPR/xILKWCY/2YOP2wIq4k78J4mWio7M=; b=oKDTk200b3WWISYthkoV1jXSBZkd3/TZ5CH7euNn5F75bwWEOURTwql8Wl8ITQZROH D08FlXY/OttGjOB+If6h+aeZEiuc7Kq6DfjLHIlkdtUu/dz48X6+R360WzRyco+Q/xt0 tKatGgC6c8+MVk/wy6tHdoI0S1rZas5Agumvq3LmbOHlmXzg1VYabaZavP8fskeLKej9 XZH8NiPwyVxhxzkvRAvyJVCwrNl2SoQ9e8YBfWIghwe1qhM6SxhYwX8kpgBEVGRCsQ5z Cy7I/A1ecP6hciZX2mITZSLdVwROs7c7Ra5OV8trCfWzxAGZxO2Rdp6SCK2yu/+U5hNm ThXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vG+EtTkh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n12-20020a0ce48c000000b0065166c4cf34si1009247qvl.312.2023.09.08.04.24.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Sep 2023 04:24:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vG+EtTkh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeZa9-00041J-4f; Fri, 08 Sep 2023 07:23:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeZa6-0003zc-Bg for qemu-devel@nongnu.org; Fri, 08 Sep 2023 07:23:22 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeZa1-0003ip-8P for qemu-devel@nongnu.org; Fri, 08 Sep 2023 07:23:21 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-401d24f1f27so21802995e9.1 for ; Fri, 08 Sep 2023 04:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694172194; x=1694776994; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K/YkGJmASUJnEMaMG4VGJ0aAEtMk9/BNtlzjAdGgNrE=; b=vG+EtTkhxGOiBMFDUfD4sFJpkgiXInUbX/4kf3IoiE0R1KwcgOrqaiRN9J5sbFVCAS FyIHGUgbz4l8VxmsKPA03os3Kybdw3pmabmgdQtLhkRyArOss1HyQBoeVkwTbuM69UF1 LpI+JuM4fTl+jaCVQsZ1lcRhEFyhYPBOQW3VuedSQ4mna2SEvjGLXKhkN+5VFbugEreS dFyKCk5jQu47kciXi5NLupO+W0BUabOmxez7tgS6nurpVjy6k6HpncyxtwNDLUoUpSXm 1CIr4kEvC2ZGp0FJEkgayJSuLtHPPI37nNgpxcb6CdTnXaFJZEFWoJTQNnkoLQZY7bU5 OGgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694172194; x=1694776994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K/YkGJmASUJnEMaMG4VGJ0aAEtMk9/BNtlzjAdGgNrE=; b=aWFwuQvkDXFWFsrsXDbPkDYhR+6+hZzcgy+W+Cpr/UjB6qpRxdURJPXTPRtWlhh503 rxR3iBnE6+VwuI+JMDJsrgxaZyfq05/mX2aW+jcXCQh+VPdvHCwMuwsSe7AKpvDxyo66 ma9YUclqZIw5TXFeGD/I2y4oMHDN8hxzEX26LwxZfEZlIeEeYHysbbHpkcvUNTFjJibq FGFz+wMtcz+gpb/ScssRd+4yaq9cHrCRmKOAPhBAeFtJWF5uxlppW3iNn7fXqxfbFRfW iB1g02CcSZBWK9g+2tMynvKPzPJGsGQSqeZRvxE4cgCDaBn5mBqjW/VZymqdcScxnXOA wIzA== X-Gm-Message-State: AOJu0YwK5f/9UGfi8M+Pm4btg6MNoOWV34Xto2EMR55o6GyWrkhmHqRZ eDyWkfEy0fnyrGO1IgmEctCq7iYno1yeM8e0/mw= X-Received: by 2002:a1c:4b0b:0:b0:402:ee59:ff49 with SMTP id y11-20020a1c4b0b000000b00402ee59ff49mr2030454wma.9.1694172194657; Fri, 08 Sep 2023 04:23:14 -0700 (PDT) Received: from m1x-phil.lan (lfb24-h01-176-173-167-175.dsl.sta.abo.bbox.fr. [176.173.167.175]) by smtp.gmail.com with ESMTPSA id y23-20020a7bcd97000000b003fee6f027c7sm4966259wmj.19.2023.09.08.04.23.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 Sep 2023 04:23:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, David Hildenbrand , Gavin Shan Cc: Chris Wulff , David Gibson , qemu-s390x@nongnu.org, Weiwei Li , qemu-arm@nongnu.org, Mark Cave-Ayland , Jiaxun Yang , Yoshinori Sato , Richard Henderson , Marcel Apfelbaum , Max Filippov , Nicholas Piggin , Eduardo Habkost , Ilya Leoshkevich , Bastian Koppelmann , Greg Kurz , "Edgar E. Iglesias" , qemu-ppc@nongnu.org, Daniel Henrique Barboza , Marek Vasut , Palmer Dabbelt , Michael Rolnik , Laurent Vivier , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , qemu-riscv@nongnu.org, Aurelien Jarno , Bin Meng , Xiaojuan Yang , Daniel Henrique Barboza , Aleksandar Rikalo , Artyom Tarasenko , Song Gao , Stafford Horne , Yanan Wang , Alistair Francis , Brian Cain , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Thomas Huth , Liu Zhiwei Subject: [PATCH 4/4] hw/cpu: Call object_class_dynamic_cast() once in cpu_class_by_name() Date: Fri, 8 Sep 2023 13:22:34 +0200 Message-ID: <20230908112235.75914-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908112235.75914-1-philmd@linaro.org> References: <20230908112235.75914-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Leverage the public CPUClass::cpu_resolving_type field and call object_class_dynamic_cast() once in cpu_class_by_name(). Signed-off-by: Philippe Mathieu-Daudé --- hw/core/cpu-common.c | 3 ++- target/alpha/cpu.c | 3 +-- target/arm/cpu.c | 4 +--- target/avr/cpu.c | 4 +--- target/cris/cpu.c | 4 +--- target/hexagon/cpu.c | 4 +--- target/loongarch/cpu.c | 5 +---- target/m68k/cpu.c | 4 +--- target/openrisc/cpu.c | 4 +--- target/riscv/cpu.c | 4 +--- target/rx/cpu.c | 2 +- target/tricore/cpu.c | 4 +--- target/xtensa/cpu.c | 4 +--- 13 files changed, 14 insertions(+), 35 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 2d24261a6a..f4a2ccebea 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -157,7 +157,8 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) cc = CPU_CLASS(oc); assert(cc->cpu_resolving_type && cc->class_by_name); oc = cc->class_by_name(cpu_model); - if (oc == NULL || object_class_is_abstract(oc)) { + if (oc == NULL || object_class_is_abstract(oc) + || !object_class_dynamic_cast(oc, cc->cpu_resolving_type)) { return NULL; } return oc; diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c index 0ddea8004c..b184fcc123 100644 --- a/target/alpha/cpu.c +++ b/target/alpha/cpu.c @@ -126,8 +126,7 @@ static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model) int i; oc = object_class_by_name(cpu_model); - if (oc != NULL && object_class_dynamic_cast(oc, TYPE_ALPHA_CPU) != NULL && - !object_class_is_abstract(oc)) { + if (oc != NULL && !object_class_is_abstract(oc)) { return oc; } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 9e51bde170..d29040cd8c 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2300,9 +2300,7 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU)) { - return NULL; - } + return oc; } diff --git a/target/avr/cpu.c b/target/avr/cpu.c index f6004169ac..53735ff1dd 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -159,9 +159,7 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) ObjectClass *oc; oc = object_class_by_name(cpu_model); - if (object_class_dynamic_cast(oc, TYPE_AVR_CPU) == NULL) { - oc = NULL; - } + return oc; } diff --git a/target/cris/cpu.c b/target/cris/cpu.c index adde4f599d..b307d0b9db 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -95,9 +95,7 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(CRIS_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_CRIS_CPU)) { - oc = NULL; - } + return oc; } diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 2d4fed838d..4b8d63c4a7 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -63,9 +63,7 @@ static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_HEXAGON_CPU)) { - return NULL; - } + return oc; } diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 189dfd32d1..1eb2c579eb 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -646,10 +646,7 @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model) } } - if (object_class_dynamic_cast(oc, TYPE_LOONGARCH_CPU)) { - return oc; - } - return NULL; + return oc; } void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index bd7bb103d7..e8b86c80f1 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -111,9 +111,7 @@ static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL) { - return NULL; - } + return oc; } diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index 5e1e0576e0..7aac9105bd 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -168,9 +168,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(OPENRISC_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU)) { - return NULL; - } + return oc; } diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index e8f04ef82b..0170e288e7 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -619,9 +619,7 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_RISCV_CPU)) { - return NULL; - } + return oc; } diff --git a/target/rx/cpu.c b/target/rx/cpu.c index 2a6df418a8..879d4fcdef 100644 --- a/target/rx/cpu.c +++ b/target/rx/cpu.c @@ -111,7 +111,7 @@ static ObjectClass *rx_cpu_class_by_name(const char *cpu_model) char *typename; oc = object_class_by_name(cpu_model); - if (oc != NULL && object_class_dynamic_cast(oc, TYPE_RX_CPU) != NULL) { + if (oc != NULL) { return oc; } typename = g_strdup_printf(RX_CPU_TYPE_NAME("%s"), cpu_model); diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index ffe5158786..f65b8761b0 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -140,9 +140,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(TRICORE_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU)) { - return NULL; - } + return oc; } diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index 13bed05d0c..6d96e5ab27 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -141,9 +141,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc == NULL || !object_class_dynamic_cast(oc, TYPE_XTENSA_CPU)) { - return NULL; - } + return oc; }