From: Ruibo Lu <reaperlu@hust.edu.cn>
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 [thread overview]
Message-ID: <20230703140340.212360-1-reaperlu@hust.edu.cn> (raw)
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 <reaperlu@hust.edu.cn>
---
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)
}
}
-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 = 0;
+ bool result = false;
if ((addr >= env->pmp_state.addr[pmp_index].sa) &&
(addr <= env->pmp_state.addr[pmp_index].ea)) {
- result = 1;
+ result = true;
} else {
- result = 0;
+ result = false;
}
return result;
@@ -287,8 +287,8 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
{
int i = 0;
int pmp_size = 0;
- target_ulong s = 0;
- target_ulong e = 0;
+ bool sa_in = false;
+ bool ea_in = false;
/* Short cut if no rules */
if (0 == pmp_get_num_rules(env)) {
@@ -314,11 +314,11 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
* from low to high
*/
for (i = 0; i < MAX_RISCV_PMPS; i++) {
- s = pmp_is_in_range(env, i, addr);
- e = pmp_is_in_range(env, i, addr + pmp_size - 1);
+ sa_in = pmp_is_in_range(env, i, addr);
+ ea_in = pmp_is_in_range(env, i, addr + pmp_size - 1);
/* partially inside */
- if ((s + e) == 1) {
+ if (sa_in ^ ea_in) {
qemu_log_mask(LOG_GUEST_ERROR,
"pmp violation - access is partially inside\n");
*allowed_privs = 0;
@@ -339,7 +339,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
(env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |
((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2);
- if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) {
+ if (sa_in && ea_in && (PMP_AMATCH_OFF != a_field)) {
/*
* If the PMP entry is not off and the address is in range,
* do the priv check
--
2.41.0
next reply other threads:[~2023-07-03 14:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-03 14:03 Ruibo Lu [this message]
2023-07-03 15:54 ` [PATCH v2] target/riscv: Optimize ambiguous local variable in pmp_hart_has_privs Philippe Mathieu-Daudé
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=20230703140340.212360-1-reaperlu@hust.edu.cn \
--to=reaperlu@hust.edu.cn \
--cc=alistair.francis@wdc.com \
--cc=liweiwei@iscas.ac.cn \
--cc=luruibo2000@163.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@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).