From nobody Sun Sep 28 17:07:44 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1758032967; cv=none; d=zohomail.com; s=zohoarc; b=ODM+9H6oko+QHhL3WPs7hMDY+Xp3KJT/mmIu2oR+8uvxi49xyBlCKeZ/zaO10Xvq3o0RTFT+txCjNMaNiBYWPfGuplG8KyBCJ8zeVrtHxoyTKiOmbb/p7fNkIyRO2LQdiLjqfczt0DQCIF3bIDaCdSUeduyWYIkchX2fNwubSN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758032967; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jRgfGoWkJBViaWdfAuuV3gVCQiMB3rBg0skWkT97tNk=; b=Pg+WG0q2dJjQz80x9f32z3KLVkUnkpyDQEJtspeigPHNG8VPTQ+AmYcEghRZL7FSWHTy8O+GgC8sTwjt0BESQmT+/ATFOVd4J845ZNoGZtRDttvntSpQ2f/gtH4tx0hcRDdgTrfk+xJ+v4sSKeVLY1gykbiaVT0fEobVMcoo+Mo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758032967216753.9316959148781; Tue, 16 Sep 2025 07:29:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uyWap-0006Gi-HX; Tue, 16 Sep 2025 10:23:39 -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 1uyWaP-0005qA-PX for qemu-devel@nongnu.org; Tue, 16 Sep 2025 10:23:15 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uyWaE-0008Mg-FQ for qemu-devel@nongnu.org; Tue, 16 Sep 2025 10:23:11 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2445826fd9dso65604575ad.3 for ; Tue, 16 Sep 2025 07:23:00 -0700 (PDT) Received: from stoup.. ([71.212.157.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2651d2df15esm73459905ad.45.2025.09.16.07.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Sep 2025 07:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758032580; x=1758637380; 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=jRgfGoWkJBViaWdfAuuV3gVCQiMB3rBg0skWkT97tNk=; b=tQByyXcTa7IKRSB8ZWM4+ZTk2/esMRKDZ8zBS9Q3LL1D0SeuuSkC/yhdtEFR4190dp DFsE1LzHCmC+2bdx9umrsvjmbbh9g5o/yDinq0ytzGQioEcdCxnpJQU7Nk6ORkINxc6A kZgtMi0eEgjaeIK2slbvyCjwpmcTl+uW0bBM2IGu8W7711YZUKvDS9dWBiI+QYpxBDo2 MEgkhDRFyTtWyq+mRSpg/NGMBuJXxbpruzjeth8TcQIlhxwqIhhWazU01W6Ljje7dsja KRxCUZxWwIvt2ac/Zah6GyPAZ8pX7m1Pev64X3xyUPiHwa2MPkipLjU1JezsKjAQB1nF e2ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758032580; x=1758637380; 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=jRgfGoWkJBViaWdfAuuV3gVCQiMB3rBg0skWkT97tNk=; b=eqU9usU58ruPQdTeqegPAcKxkJEyPiNwzxw6yaEAQgwAM0cr3Fkn0gjYAbGL46lkCp okzKcj+sKuJGb6/vEVSKjh7RnPSgkOcopA2K+b2MpsF1uUxLwMYqMkGsefw0zow8bMha jOj3KcJXcg6DFKBE40rxUysNzqeRCd4bRoKcY1c7xdgWcfMPmEsdPVjeLuJy5G+jxCnV u7kruBoin/G7/HlRlYWCxqhKHN05mDU5p3UwqXNJCUNT0YeuSwANOdhZfQx/yh1EhFTx ksZE+jvA+Pxhxu+UrHnKTPzI15CZdfYFnPwBEkG8IcXg6akcRLSwTI7lp3YVltf/ME1o u/HA== X-Gm-Message-State: AOJu0YyqZEbxXgmVuRdqMfZwXMWClwPJWcojoU4+0OSGiLuAFFg+h7Q5 PslE2UKbeMSIGAyFwSpAJuCcCuV1c18Cjw7xRSxPO6H8s8awIPVAzHTGAnbw0qmjo+GYU1Bi7pU Pwdk6 X-Gm-Gg: ASbGnctuipVFWGJJbyLNlOYfvSUFODR0K0lB+FzJmpq8tc6MvhmsUo1jxrlPONi/LWz 8pn8toWPmcwhHbn706yao9alHv7RMG6GKi1xANe3mw+JJu/ruc2pf0k2EuFaYeYRloQJk7zRbVO mwlT80ZmI0lVJ2qZJxTg9kredkV1VRjvWQyp7yLeQ0y7p9zcqKMoNkAf1SoQD51KiZPARIm5/Q1 kaIB9vFWt9Aqn2CUcWTFDlk7WucY0spYXX5VzdGRwoQipwWpMAU7RFP/r1J1iZboDmC7ElbBVHk vLTpePBnAOokAWI3DqeepNu7IqiZFAn931xMNnMjyN7LCwqUCtTFasTbKaDRyIcq5fWhHrGOCNl rVKEwXAoBfnqLRm/HnhMOOEpoaurH X-Google-Smtp-Source: AGHT+IEKg8RBNQVZfjsGxxqrsTnQ/ZBF4bXbkMjZ2HndW1XegnOq6B70B5k+pKzbPOExU5yiP7nkGQ== X-Received: by 2002:a17:902:d2cf:b0:266:e0e6:873e with SMTP id d9443c01a7336-266e0e68a56mr103540915ad.57.1758032579582; Tue, 16 Sep 2025 07:22:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v2 26/36] target/arm: Hoist the allocation of ARMCPRegInfo Date: Tue, 16 Sep 2025 07:22:27 -0700 Message-ID: <20250916142238.664316-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250916142238.664316-1-richard.henderson@linaro.org> References: <20250916142238.664316-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1758032968261116600 Content-Type: text/plain; charset="utf-8" Pass in a newly allocated structure, rather than having to dance around allocation of the name and the structure. Since we no longer have two copies of the structure handy within add_cpreg_to_hashtable, delay the writeback of concrete values over wildcards until we're done querying the wildcards. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/helper.c | 97 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 7f55ea726d..71dd094fac 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7443,13 +7443,12 @@ static ARMCPRegInfo *alloc_cpreg(const ARMCPRegInfo= *in, * Private utility function for define_one_arm_cp_reg(): * add a single reginfo struct to the hash table. */ -static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, +static void add_cpreg_to_hashtable(ARMCPU *cpu, ARMCPRegInfo *r, CPState state, CPSecureState secstate, int cp, int crm, int opc1, int opc2, - const char *name, uint32_t key) + uint32_t key) { CPUARMState *env =3D &cpu->env; - ARMCPRegInfo *r2; bool ns =3D secstate & ARM_CP_SECSTATE_NS; =20 /* Overriding of an existing definition must be explicitly requested. = */ @@ -7460,19 +7459,6 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, cons= t ARMCPRegInfo *r, } } =20 - r2 =3D alloc_cpreg(r, name, NULL); - - /* - * Update fields to match the instantiation, overwiting wildcards - * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH. - */ - r2->cp =3D cp; - r2->crm =3D crm; - r2->opc1 =3D opc1; - r2->opc2 =3D opc2; - r2->state =3D state; - r2->secure =3D secstate; - { bool isbanked =3D r->bank_fieldoffsets[0] && r->bank_fieldoffsets[= 1]; =20 @@ -7482,7 +7468,7 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const= ARMCPRegInfo *r, * Overwriting fieldoffset as the array is only used to define * banked registers but later only fieldoffset is used. */ - r2->fieldoffset =3D r->bank_fieldoffsets[ns]; + r->fieldoffset =3D r->bank_fieldoffsets[ns]; } if (state =3D=3D ARM_CP_STATE_AA32) { if (isbanked) { @@ -7499,19 +7485,19 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, con= st ARMCPRegInfo *r, */ if ((r->state =3D=3D ARM_CP_STATE_BOTH && ns) || (arm_feature(env, ARM_FEATURE_V8) && !ns)) { - r2->type |=3D ARM_CP_ALIAS; + r->type |=3D ARM_CP_ALIAS; } } else if ((secstate !=3D r->secure) && !ns) { /* * The register is not banked so we only want to allow * migration of the non-secure instance. */ - r2->type |=3D ARM_CP_ALIAS; + r->type |=3D ARM_CP_ALIAS; } =20 if (HOST_BIG_ENDIAN && - r->state =3D=3D ARM_CP_STATE_BOTH && r2->fieldoffset) { - r2->fieldoffset +=3D sizeof(uint32_t); + r->state =3D=3D ARM_CP_STATE_BOTH && r->fieldoffset) { + r->fieldoffset +=3D sizeof(uint32_t); } } } @@ -7523,35 +7509,46 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, con= st ARMCPRegInfo *r, * multiple times. Special registers (ie NOP/WFI) are * never migratable and not even raw-accessible. */ - if (r2->type & ARM_CP_SPECIAL_MASK) { - r2->type |=3D ARM_CP_NO_RAW; + if (r->type & ARM_CP_SPECIAL_MASK) { + r->type |=3D ARM_CP_NO_RAW; } if (((r->crm =3D=3D CP_ANY) && crm !=3D 0) || ((r->opc1 =3D=3D CP_ANY) && opc1 !=3D 0) || ((r->opc2 =3D=3D CP_ANY) && opc2 !=3D 0)) { - r2->type |=3D ARM_CP_ALIAS | ARM_CP_NO_GDB; + r->type |=3D ARM_CP_ALIAS | ARM_CP_NO_GDB; } =20 + /* + * Update fields to match the instantiation, overwiting wildcards + * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH. + */ + r->cp =3D cp; + r->crm =3D crm; + r->opc1 =3D opc1; + r->opc2 =3D opc2; + r->state =3D state; + r->secure =3D secstate; + /* * Check that raw accesses are either forbidden or handled. Note that * we can't assert this earlier because the setup of fieldoffset for * banked registers has to be done first. */ - if (!(r2->type & ARM_CP_NO_RAW)) { - assert(!raw_accessors_invalid(r2)); + if (!(r->type & ARM_CP_NO_RAW)) { + assert(!raw_accessors_invalid(r)); } =20 - g_hash_table_insert(cpu->cp_regs, (gpointer)(uintptr_t)key, r2); + g_hash_table_insert(cpu->cp_regs, (gpointer)(uintptr_t)key, r); } =20 -static void add_cpreg_to_hashtable_aa32(ARMCPU *cpu, const ARMCPRegInfo *r, +static void add_cpreg_to_hashtable_aa32(ARMCPU *cpu, ARMCPRegInfo *r, int cp, int crm, int opc1, int opc= 2) { /* * Under AArch32 CP registers can be common * (same for secure and non-secure world) or banked. */ - char *name; + ARMCPRegInfo *r_s; bool is64 =3D r->type & ARM_CP_64BIT; uint32_t key =3D ENCODE_CP_REG(cp, is64, 0, r->crn, crm, opc1, opc2); =20 @@ -7563,24 +7560,23 @@ static void add_cpreg_to_hashtable_aa32(ARMCPU *cpu= , const ARMCPRegInfo *r, /* fall through */ case ARM_CP_SECSTATE_S: add_cpreg_to_hashtable(cpu, r, ARM_CP_STATE_AA32, r->secure, - cp, crm, opc1, opc2, r->name, key); + cp, crm, opc1, opc2, key); break; case ARM_CP_SECSTATE_BOTH: - name =3D g_strdup_printf("%s_S", r->name); - add_cpreg_to_hashtable(cpu, r, ARM_CP_STATE_AA32, ARM_CP_SECSTATE_= S, - cp, crm, opc1, opc2, name, key); - g_free(name); + r_s =3D alloc_cpreg(r, r->name, "_S"); + add_cpreg_to_hashtable(cpu, r_s, ARM_CP_STATE_AA32, ARM_CP_SECSTAT= E_S, + cp, crm, opc1, opc2, key); =20 key |=3D CP_REG_AA32_NS_MASK; add_cpreg_to_hashtable(cpu, r, ARM_CP_STATE_AA32, ARM_CP_SECSTATE_= NS, - cp, crm, opc1, opc2, r->name, key); + cp, crm, opc1, opc2, key); break; default: g_assert_not_reached(); } } =20 -static void add_cpreg_to_hashtable_aa64(ARMCPU *cpu, const ARMCPRegInfo *r, +static void add_cpreg_to_hashtable_aa64(ARMCPU *cpu, ARMCPRegInfo *r, int crm, int opc1, int opc2) { uint32_t key =3D ENCODE_AA64_CP_REG(r->opc0, opc1, r->crn, crm, opc2); @@ -7597,24 +7593,23 @@ static void add_cpreg_to_hashtable_aa64(ARMCPU *cpu= , const ARMCPRegInfo *r, * and name that it is passed, so it's OK to use * a local struct here. */ - ARMCPRegInfo nxs_ri =3D *r; - g_autofree char *name =3D g_strdup_printf("%sNXS", r->name); + ARMCPRegInfo *nxs_ri =3D alloc_cpreg(r, r->name, "NXS"); uint32_t nxs_key; =20 - assert(nxs_ri.crn < 0xf); - nxs_ri.crn++; + assert(nxs_ri->crn < 0xf); + nxs_ri->crn++; nxs_key =3D key + (1 << CP_REG_ARM64_SYSREG_CRN_SHIFT); - if (nxs_ri.fgt) { - nxs_ri.fgt |=3D R_FGT_NXS_MASK; + if (nxs_ri->fgt) { + nxs_ri->fgt |=3D R_FGT_NXS_MASK; } =20 - add_cpreg_to_hashtable(cpu, &nxs_ri, ARM_CP_STATE_AA64, + add_cpreg_to_hashtable(cpu, nxs_ri, ARM_CP_STATE_AA64, ARM_CP_SECSTATE_NS, 0, crm, opc1, opc2, - name, nxs_key); + nxs_key); } =20 add_cpreg_to_hashtable(cpu, r, ARM_CP_STATE_AA64, ARM_CP_SECSTATE_NS, - 0, crm, opc1, opc2, r->name, key); + 0, crm, opc1, opc2, key); } =20 void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *r) @@ -7821,16 +7816,20 @@ void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCP= RegInfo *r) for (int crm =3D crmmin; crm <=3D crmmax; crm++) { for (int opc1 =3D opc1min; opc1 <=3D opc1max; opc1++) { for (int opc2 =3D opc2min; opc2 <=3D opc2max; opc2++) { + ARMCPRegInfo *r2 =3D alloc_cpreg(r, r->name, NULL); + ARMCPRegInfo *r3; + switch (r->state) { case ARM_CP_STATE_AA32: - add_cpreg_to_hashtable_aa32(cpu, r, cp, crm, opc1, opc= 2); + add_cpreg_to_hashtable_aa32(cpu, r2, cp, crm, opc1, op= c2); break; case ARM_CP_STATE_AA64: - add_cpreg_to_hashtable_aa64(cpu, r, crm, opc1, opc2); + add_cpreg_to_hashtable_aa64(cpu, r2, crm, opc1, opc2); break; case ARM_CP_STATE_BOTH: - add_cpreg_to_hashtable_aa32(cpu, r, cp, crm, opc1, opc= 2); - add_cpreg_to_hashtable_aa64(cpu, r, crm, opc1, opc2); + r3 =3D alloc_cpreg(r2, r2->name, NULL); + add_cpreg_to_hashtable_aa32(cpu, r2, cp, crm, opc1, op= c2); + add_cpreg_to_hashtable_aa64(cpu, r3, crm, opc1, opc2); break; default: g_assert_not_reached(); --=20 2.43.0