From: Paul White <paul.white.kernel@gmail.com>
To: anup@brainfault.org, atish.patra@linux.dev, pjw@kernel.org,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr
Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Paul White <paul.white.kernel@gmail.com>
Subject: [PATCH 0/2] KVM: riscv: Unify and optimize FP register loops
Date: Sun, 25 Oct 2026 23:41:25 -0400 [thread overview]
Message-ID: <cover.1792982932.git.paul.white.kernel@gmail.com> (raw)
The change to both patches in this series is a
structural/architectural one. Both functions set_reg and get_reg use
identical code to locate the register the application specified in the
token even though they do different things with that location
information: the set_reg function adds data the application requested
to send to that identified location (in the copy_from_user function)
while the get_reg function retrieves what data is at that identified
location and sends it to the application (using the copy_to_user
function). Everything else is the same. That is the only difference
between the code.
Therefore I was able to apply the same solution to both of the
function's finding-the-requested-register parts (which is everything
up until the final if statement) which were filled with redundancy.
The solution I came up with is to create local variables for the
entire function for all the variables of the original code that would
be different, depending on the floating point type. Then once I ask
whether it is a double floating point or single floating point mode, I
assign the aforementioned variables to the values they should have for
that mode so that when I go through the if statements that ask whether
the requested register number is a status control register or data
register, I only have to go through it once because the respective
floating point values/addresses would have been assigned to the
aforementioned local variables, so the whole code kind of changes or
is tailored to the floating point type.
This architectural change/solution will make the cpu execute the code
faster (as the cpu will have less decisions to make and the bare-metal
math used to figure out the address of the register is executed faster
by the cpu than looking up object properties and array indexes), is
more maintainable, and is more readable.
Paul White (2):
KVM: riscv: Eliminate redundancy in get_reg function via pointers
KVM: riscv: Eliminate redundancy in set_reg function via pointers
arch/riscv/kvm/vcpu_fp.c | 128 +++++++++++++++++++++++----------------
1 file changed, 76 insertions(+), 52 deletions(-)
--
2.53.0
next reply other threads:[~2026-10-26 3:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 3:41 Paul White [this message]
2026-10-26 3:41 ` [PATCH 1/2] KVM: riscv: Eliminate redundancy in get_reg function via pointers Paul White
2026-10-26 3:41 ` [PATCH 2/2] KVM: riscv: Eliminate redundancy in set_reg " Paul White
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=cover.1792982932.git.paul.white.kernel@gmail.com \
--to=paul.white.kernel@gmail.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.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
all inboxes | Powered by JetHome®