From nobody Thu May 16 00:33:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688393084431540.7164640202549; Mon, 3 Jul 2023 07:04:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGKAC-00063u-Q9; Mon, 03 Jul 2023 10:04:24 -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 1qGKA7-0005uN-1f; Mon, 03 Jul 2023 10:04:21 -0400 Received: from [202.114.0.240] (helo=hust.edu.cn) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGKA4-0003Fv-Gf; Mon, 03 Jul 2023 10:04:18 -0400 Received: from localhost.localdomain ([10.12.190.169]) (user=reaperlu@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 363E3lXW013519-363E3lXX013519 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 3 Jul 2023 22:04:00 +0800 From: Ruibo Lu To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, luruibo2000@163.com, alistair.francis@wdc.com, liweiwei@iscas.ac.cn Subject: [PATCH v2] target/riscv: Optimize ambiguous local variable in pmp_hart_has_privs Date: Mon, 3 Jul 2023 22:03:40 +0800 Message-ID: <20230703140340.212360-1-reaperlu@hust.edu.cn> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FEAS-AUTH-USER: reaperlu@hust.edu.cn X-Host-Lookup-Failed: Reverse DNS lookup failed for 202.114.0.240 (deferred) 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=202.114.0.240; envelope-from=reaperlu@hust.edu.cn; helo=hust.edu.cn X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-ZM-MESSAGEID: 1688393087342100001 Content-Type: text/plain; charset="utf-8" These two values represents whether start/end address is in pmp_range. However, the type and name of them is ambiguous. This commit change the name and type of them to improve code readability and accuracy. Signed-off-by: Ruibo Lu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/riscv/pmp.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 1a9279ba88..cdf32d9833 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -203,16 +203,16 @@ void pmp_update_rule_nums(CPURISCVState *env) } } =20 -static int pmp_is_in_range(CPURISCVState *env, int pmp_index, +static bool pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr) { - int result =3D 0; + bool result =3D false; =20 if ((addr >=3D env->pmp_state.addr[pmp_index].sa) && (addr <=3D env->pmp_state.addr[pmp_index].ea)) { - result =3D 1; + result =3D true; } else { - result =3D 0; + result =3D false; } =20 return result; @@ -287,8 +287,8 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulon= g addr, { int i =3D 0; int pmp_size =3D 0; - target_ulong s =3D 0; - target_ulong e =3D 0; + bool sa_in =3D false; + bool ea_in =3D false; =20 /* Short cut if no rules */ if (0 =3D=3D pmp_get_num_rules(env)) { @@ -314,11 +314,11 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ul= ong addr, * from low to high */ for (i =3D 0; i < MAX_RISCV_PMPS; i++) { - s =3D pmp_is_in_range(env, i, addr); - e =3D pmp_is_in_range(env, i, addr + pmp_size - 1); + sa_in =3D pmp_is_in_range(env, i, addr); + ea_in =3D pmp_is_in_range(env, i, addr + pmp_size - 1); =20 /* partially inside */ - if ((s + e) =3D=3D 1) { + if (sa_in ^ ea_in) { qemu_log_mask(LOG_GUEST_ERROR, "pmp violation - access is partially inside\n"); *allowed_privs =3D 0; @@ -339,7 +339,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulon= g addr, (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) | ((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2); =20 - if (((s + e) =3D=3D 2) && (PMP_AMATCH_OFF !=3D a_field)) { + if (sa_in && ea_in && (PMP_AMATCH_OFF !=3D a_field)) { /* * If the PMP entry is not off and the address is in range, * do the priv check --=20 2.41.0