From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Yury Norov <yury.norov@gmail.com>,
linux-kernel@vger.kernel.org
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH v1 2/2] bitmap: Optimize memset() calls
Date: Thu, 17 Aug 2023 19:54:53 +0300 [thread overview]
Message-ID: <20230817165453.713353-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230817165453.713353-1-andriy.shevchenko@linux.intel.com>
Intead of byte memset() calls use 32- or 64-bit version depending
on the compile-time BITS_PER_LONG value.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/bitmap.h | 16 ++++++++++++----
lib/bitmap.c | 4 ++--
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 2d5042d1b501..6eec4d4fd623 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -234,22 +234,30 @@ extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp,
static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
{
- unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+ unsigned int len = BITS_TO_LONGS(nbits);
if (small_const_nbits(nbits))
*dst = 0;
else
- memset(dst, 0, len);
+#if BITS_PER_LONG == 64
+ memset64((uint64_t *)dst, 0, len);
+#else
+ memset32((uint32_t *)dst, 0, len);
+#endif
}
static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
{
- unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+ unsigned int len = BITS_TO_LONGS(nbits);
if (small_const_nbits(nbits))
*dst = ~0UL;
else
- memset(dst, 0xff, len);
+#if BITS_PER_LONG == 64
+ memset64((uint64_t *)dst, GENMASK(63, 0), len);
+#else
+ memset32((uint32_t *)dst, GENMASK(31, 0), len);
+#endif
}
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 935e0f96e785..df0fb37a5732 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -128,7 +128,7 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
dst[k] = lower | upper;
}
if (off)
- memset(&dst[lim - off], 0, off*sizeof(unsigned long));
+ bitmap_zero(&dst[lim - off], off);
}
EXPORT_SYMBOL(__bitmap_shift_right);
@@ -166,7 +166,7 @@ void __bitmap_shift_left(unsigned long *dst, const unsigned long *src,
dst[k + off] = lower | upper;
}
if (off)
- memset(dst, 0, off*sizeof(unsigned long));
+ bitmap_zero(dst, off);
}
EXPORT_SYMBOL(__bitmap_shift_left);
--
2.40.0.1.gaa8946217a0b
next prev parent reply other threads:[~2023-08-17 16:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 16:54 [rfc, rft, PATCH v1 0/2] bitmap: clean up and (micro?)optimization Andy Shevchenko
2023-08-17 16:54 ` [PATCH v1 1/2] bitmap: Use constants and macros from bits.h Andy Shevchenko
2023-08-18 6:28 ` Rasmus Villemoes
2023-08-18 8:50 ` Andy Shevchenko
2023-08-18 9:13 ` Rasmus Villemoes
2023-08-17 16:54 ` Andy Shevchenko [this message]
2023-08-18 6:53 ` [PATCH v1 2/2] bitmap: Optimize memset() calls Rasmus Villemoes
2023-08-18 8:55 ` Andy Shevchenko
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=20230817165453.713353-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=yury.norov@gmail.com \
/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