Yury Norov
277a20a498
lib: add fast path for find_next_*_bit()
Similarly to bitmap functions, find_next_*_bit() users will benefit if
we'll handle a case of bitmaps that fit into a single word inline. In the
very best case, the compiler may replace a function call with a few
instructions.
This is the quite typical find_next_bit() user:
unsigned int cpumask_next(int n, const struct cpumask *srcp)
{
/* -1 is a legal arg here. */
if (n != -1)
cpumask_check(n);
return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
}
EXPORT_SYMBOL(cpumask_next);
Currently, on ARM64 the generated code looks like this:
0000000000000000 <cpumask_next>:
0: a9bf7bfd stp x29, x30, [sp, #-16]!
4: 11000402 add w2, w0, #0x1
8: aa0103e0 mov x0, x1
c: d2800401 mov x1, #0x40 // #64
10: 910003fd mov x29, sp
14: 93407c42 sxtw x2, w2
18: 94000000 bl 0 <find_next_bit>
1c: a8c17bfd ldp x29, x30, [sp], #16
20: d65f03c0 ret
24: d503201f nop
After applying this patch:
0000000000000140 <cpumask_next>:
140: 11000400 add w0, w0, #0x1
144: 93407c00 sxtw x0, w0
148: f100fc1f cmp x0, #0x3f
14c: 54000168 b.hi 178 <cpumask_next+0x38> // b.pmore
150: f9400023 ldr x3, [x1]
154: 92800001 mov x1, #0xffffffffffffffff // #-1
158: 9ac02020 lsl x0, x1, x0
15c: 52800802 mov w2, #0x40 // #64
160: 8a030001 and x1, x0, x3
164: dac00020 rbit x0, x1
168: f100003f cmp x1, #0x0
16c: dac01000 clz x0, x0
170: 1a800040 csel w0, w2, w0, eq // eq = none
174: d65f03c0 ret
178: 52800800 mov w0, #0x40 // #64
17c: d65f03c0 ret
find_next_bit() call is replaced with 6 instructions. find_next_bit()
itself is 41 instructions plus function call overhead.
Despite inlining, the scripts/bloat-o-meter report smaller .text size
after applying the series:
add/remove: 11/9 grow/shrink: 233/176 up/down: 5780/-6768 (-988)
Link: https://lkml.kernel.org/r/20210401003153.97325-10-yury.norov@gmail.com
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Alexey Klimov <aklimov@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Sterba <dsterba@suse.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Jianpeng Ma <jianpeng.ma@intel.com>
Cc: Joe Perches <joe@perches.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Rich Felker <dalias@libc.org>
Cc: Stefano Brivio <sbrivio@redhat.com>
Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: Yoshinori Sato <ysato@users.osdn.me>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-05-06 19:24:12 -07:00
..
2021-05-06 19:24:12 -07:00
2020-02-17 20:12:17 +01:00
2017-11-02 11:10:55 +01:00
2019-06-03 12:32:56 +02:00
2020-11-07 13:20:41 +01:00
2020-01-07 07:47:23 -08:00
2020-07-29 16:14:18 +02:00
2017-11-02 11:10:55 +01:00
2018-01-30 19:07:54 -08:00
2017-11-02 11:10:55 +01:00
2017-11-15 13:28:48 -08:00
2020-11-14 11:26:03 -08:00
2020-03-06 11:06:19 +01:00
2021-05-06 19:24:11 -07:00
2021-04-08 16:04:20 -07:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2020-06-26 00:27:37 -07:00
2020-08-20 15:45:14 -04:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2020-09-17 13:00:46 -04:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2019-06-05 17:37:16 +02:00
2021-04-21 13:45:36 +02:00
2018-12-13 21:06:18 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2020-10-25 14:51:49 -07:00
2019-05-24 17:27:11 +02:00
2021-02-03 16:42:57 +00:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2018-12-14 15:05:45 -08:00
2019-06-24 09:16:47 +10:00
2019-06-19 17:09:55 +02:00
2020-03-27 23:58:55 -04:00
2020-12-15 22:46:15 -08:00
2020-02-10 12:58:36 +01:00
2020-11-23 10:31:06 +01:00
2020-06-20 22:14:53 +10:00
2021-03-24 11:35:24 +00:00
2017-11-02 11:10:55 +01:00
2018-06-07 17:34:38 -07:00
2021-04-09 08:48:27 +02:00
2017-11-02 11:10:55 +01:00
2021-04-08 20:18:38 +09:00
2019-05-30 11:26:32 -07:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2021-02-24 16:32:23 -08:00
2017-11-02 11:10:55 +01:00
2020-11-24 14:42:08 +01:00
2020-10-25 14:51:49 -07:00
2018-03-06 18:40:44 +01:00
2020-07-09 13:29:42 -04:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2020-01-23 10:41:16 -08:00
2019-04-08 11:59:39 +01:00
2020-07-17 10:02:03 +01:00
2020-10-26 16:45:03 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2020-09-25 00:36:41 +09:00
2021-04-21 09:49:19 +00:00
2020-12-15 15:03:31 -08:00
2020-10-26 16:45:03 +01:00
2021-01-14 15:08:55 -08:00
2021-01-20 09:30:45 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2018-03-09 23:19:56 +01:00
2018-05-07 07:15:41 +02:00
2020-10-26 23:54:48 +00:00
2020-08-14 19:56:55 -07:00
2020-04-07 10:43:39 -07:00
2019-12-01 06:29:19 -08:00
2020-06-09 09:39:14 -07:00
2020-06-09 09:39:14 -07:00
2019-07-31 19:03:34 +02:00
2018-02-06 10:28:58 +01:00
2021-02-11 07:59:54 -05:00
2020-07-29 16:14:19 +02:00
2020-10-26 20:19:48 +01:00
2017-11-02 11:10:55 +01:00
2020-07-21 10:50:36 +01:00
2020-07-10 16:01:52 -07:00
2020-08-11 12:06:15 +02:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2019-05-14 19:52:48 -07:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2021-02-10 23:34:16 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2019-05-24 17:27:11 +02:00
2020-11-16 21:53:16 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2021-01-29 20:02:29 +01:00
2017-11-02 11:10:55 +01:00
2020-05-28 11:35:41 -07:00
2017-11-02 11:10:55 +01:00
2020-10-27 16:13:09 +01:00
2017-11-02 11:10:55 +01:00
2020-04-23 10:50:26 +09:00
2017-11-02 11:10:55 +01:00
2021-04-08 16:04:20 -07:00
2017-11-02 11:10:55 +01:00
2019-05-24 17:27:13 +02:00