2018-04-11 15:05:20

by Yury Norov

[permalink] [raw]
Subject: [PATCH] lib: micro-optimization for __bitmap_complement()

Use BITS_TO_LONGS() macro to avoid calculation of reminder
(bits % BITS_PER_LONG) On ARM64 it saves 5 instruction for function -
16 before and 11 after.

Signed-off-by: Yury Norov <[email protected]>
---
lib/bitmap.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index c82c61b66e16..7adc10074cff 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -62,12 +62,9 @@ EXPORT_SYMBOL(__bitmap_equal);

void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits)
{
- unsigned int k, lim = bits/BITS_PER_LONG;
+ unsigned int k, lim = BITS_TO_LONGS(bits);
for (k = 0; k < lim; ++k)
dst[k] = ~src[k];
-
- if (bits % BITS_PER_LONG)
- dst[k] = ~src[k];
}
EXPORT_SYMBOL(__bitmap_complement);

--
2.14.1



2018-04-20 13:44:44

by Yury Norov

[permalink] [raw]
Subject: Re: [PATCH] lib: micro-optimization for __bitmap_complement()

Ping?

On Wed, Apr 11, 2018 at 05:59:14PM +0300, Yury Norov wrote:
> Use BITS_TO_LONGS() macro to avoid calculation of reminder
> (bits % BITS_PER_LONG) On ARM64 it saves 5 instruction for function -
> 16 before and 11 after.
>
> Signed-off-by: Yury Norov <[email protected]>
> ---
> lib/bitmap.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index c82c61b66e16..7adc10074cff 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -62,12 +62,9 @@ EXPORT_SYMBOL(__bitmap_equal);
>
> void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits)
> {
> - unsigned int k, lim = bits/BITS_PER_LONG;
> + unsigned int k, lim = BITS_TO_LONGS(bits);
> for (k = 0; k < lim; ++k)
> dst[k] = ~src[k];
> -
> - if (bits % BITS_PER_LONG)
> - dst[k] = ~src[k];
> }
> EXPORT_SYMBOL(__bitmap_complement);
>
> --
> 2.14.1