From: BALATON Zoltan <balaton@eik.bme.hu>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: [PATCH] bitops.h: Compile out asserts without --enable-debug
Date: Sat, 20 May 2023 22:54:44 +0200 (CEST) [thread overview]
Message-ID: <20230520205444.887287457E7@zero.eik.bme.hu> (raw)
The low level extract and deposit funtions provided by bitops.h are
used in performance critical places. It crept into target/ppc via
FIELD_EX64 and also used by softfloat so PPC code using a lot of FPU
where hardfloat is also disabled is doubly affected.
Normally asserts should be compiled out from release builds with
-DNDEBUG but that cannot be used in QEMU because some places still
rely on asserts instead of proper error checking. To resolve this,
compile out asserts from deposit/extract functions in optimised builds
which improves performance for target/ppc and possibly others too.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
include/qemu/bitops.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index cb3526d1f4..5a1d81297e 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -335,7 +335,9 @@ static inline uint64_t wswap64(uint64_t h)
*/
static inline uint32_t extract32(uint32_t value, int start, int length)
{
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 32 - start);
+#endif
return (value >> start) & (~0U >> (32 - length));
}
@@ -354,7 +356,9 @@ static inline uint32_t extract32(uint32_t value, int start, int length)
*/
static inline uint8_t extract8(uint8_t value, int start, int length)
{
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 8 - start);
+#endif
return extract32(value, start, length);
}
@@ -373,7 +377,9 @@ static inline uint8_t extract8(uint8_t value, int start, int length)
*/
static inline uint16_t extract16(uint16_t value, int start, int length)
{
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 16 - start);
+#endif
return extract32(value, start, length);
}
@@ -392,7 +398,9 @@ static inline uint16_t extract16(uint16_t value, int start, int length)
*/
static inline uint64_t extract64(uint64_t value, int start, int length)
{
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 64 - start);
+#endif
return (value >> start) & (~0ULL >> (64 - length));
}
@@ -414,7 +422,9 @@ static inline uint64_t extract64(uint64_t value, int start, int length)
*/
static inline int32_t sextract32(uint32_t value, int start, int length)
{
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 32 - start);
+#endif
/* Note that this implementation relies on right shift of signed
* integers being an arithmetic shift.
*/
@@ -439,7 +449,9 @@ static inline int32_t sextract32(uint32_t value, int start, int length)
*/
static inline int64_t sextract64(uint64_t value, int start, int length)
{
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 64 - start);
+#endif
/* Note that this implementation relies on right shift of signed
* integers being an arithmetic shift.
*/
@@ -467,7 +479,9 @@ static inline uint32_t deposit32(uint32_t value, int start, int length,
uint32_t fieldval)
{
uint32_t mask;
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 32 - start);
+#endif
mask = (~0U >> (32 - length)) << start;
return (value & ~mask) | ((fieldval << start) & mask);
}
@@ -493,7 +507,9 @@ static inline uint64_t deposit64(uint64_t value, int start, int length,
uint64_t fieldval)
{
uint64_t mask;
+#ifndef __OPTIMIZE__
assert(start >= 0 && length > 0 && length <= 64 - start);
+#endif
mask = (~0ULL >> (64 - length)) << start;
return (value & ~mask) | ((fieldval << start) & mask);
}
--
2.30.9
next reply other threads:[~2023-05-20 20:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-20 20:54 BALATON Zoltan [this message]
2023-05-22 9:16 ` [PATCH] bitops.h: Compile out asserts without --enable-debug Peter Maydell
2023-05-22 12:00 ` BALATON Zoltan
2023-05-22 12:05 ` Peter Maydell
2023-05-22 11:26 ` Alex Bennée
2023-05-22 13:25 ` BALATON Zoltan
2023-05-22 16:48 ` Alex Bennée
2023-05-22 22:26 ` BALATON Zoltan
2023-05-22 23:34 ` Richard Henderson
2023-05-23 6:43 ` Alex Bennée
2023-06-05 22:06 ` BALATON Zoltan
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=20230520205444.887287457E7@zero.eik.bme.hu \
--to=balaton@eik.bme.hu \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@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).