Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1659850 > unrolled thread
| Started by | Matthew Wilcox <willy@infradead.org> |
|---|---|
| First post | 2017-06-07 16:30 +0200 |
| Last post | 2017-06-07 23:20 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible Matthew Wilcox <willy@infradead.org> - 2017-06-07 16:30 +0200
Re: [PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2017-06-07 23:20 +0200
| From | Matthew Wilcox <willy@infradead.org> |
|---|---|
| Date | 2017-06-07 16:30 +0200 |
| Subject | [PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible |
| Message-ID | <tPK8a-7Mn-19@gated-at.bofh.it> |
From: Matthew Wilcox <mawilcox@microsoft.com>
Several callers have constant 'start' and an 'nbits' that is a multiple of
8, so we can turn them into calls to memset. We don't need the entirety
of 'start' and 'nbits' to be constant, we just need to know whether
they're divisible by 8.
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
include/linux/bitmap.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 4e0f0c8167af..0b3e4452b054 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -319,6 +319,9 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start,
{
if (__builtin_constant_p(nbits) && nbits == 1)
__set_bit(start, map);
+ else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
+ __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
+ memset(map + start / 8, 0xff, nbits / 8);
else
__bitmap_set(map, start, nbits);
}
@@ -328,6 +331,9 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
{
if (__builtin_constant_p(nbits) && nbits == 1)
__clear_bit(start, map);
+ else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
+ __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
+ memset(map + start / 8, 0, nbits / 8);
else
__bitmap_clear(map, start, nbits);
}
--
2.11.0
[toc] | [next] | [standalone]
| From | Rasmus Villemoes <linux@rasmusvillemoes.dk> |
|---|---|
| Date | 2017-06-07 23:20 +0200 |
| Message-ID | <tPQwW-3ya-31@gated-at.bofh.it> |
| In reply to | #1659850 |
On Wed, Jun 07 2017, Matthew Wilcox <willy@infradead.org> wrote:
> From: Matthew Wilcox <mawilcox@microsoft.com>
>
> Several callers have constant 'start' and an 'nbits' that is a multiple of
> 8, so we can turn them into calls to memset. We don't need the entirety
> of 'start' and 'nbits' to be constant, we just need to know whether
> they're divisible by 8.
>
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> ---
> include/linux/bitmap.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 4e0f0c8167af..0b3e4452b054 100644
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -319,6 +319,9 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start,
> {
> if (__builtin_constant_p(nbits) && nbits == 1)
> __set_bit(start, map);
> + else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
> + __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
> + memset(map + start / 8, 0xff, nbits / 8);
> else
Isn't the pointer arithmetic wrong here? I think you need to cast map to
(char*).
>
> __bitmap_set(map, start, nbits);
> }
> @@ -328,6 +331,9 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
> {
> if (__builtin_constant_p(nbits) && nbits == 1)
> __clear_bit(start, map);
> + else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
> + __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
> + memset(map + start / 8, 0, nbits / 8);
> else
Ditto.
Do you have an example of how the generated code changes, both in the
case of actual constants and a case where gcc can see that start and
nbits are byte-aligned without knowing their actual values?
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web