linux/drivers/s390/cio
Alexander Lobakin a37fbe666c bitmap: introduce generic optimized bitmap_size()
The number of times yet another open coded
`BITS_TO_LONGS(nbits) * sizeof(long)` can be spotted is huge.
Some generic helper is long overdue.

Add one, bitmap_size(), but with one detail.
BITS_TO_LONGS() uses DIV_ROUND_UP(). The latter works well when both
divident and divisor are compile-time constants or when the divisor
is not a pow-of-2. When it is however, the compilers sometimes tend
to generate suboptimal code (GCC 13):

48 83 c0 3f          	add    $0x3f,%rax
48 c1 e8 06          	shr    $0x6,%rax
48 8d 14 c5 00 00 00 00	lea    0x0(,%rax,8),%rdx

%BITS_PER_LONG is always a pow-2 (either 32 or 64), but GCC still does
full division of `nbits + 63` by it and then multiplication by 8.
Instead of BITS_TO_LONGS(), use ALIGN() and then divide by 8. GCC:

8d 50 3f             	lea    0x3f(%rax),%edx
c1 ea 03             	shr    $0x3,%edx
81 e2 f8 ff ff 1f    	and    $0x1ffffff8,%edx

Now it shifts `nbits + 63` by 3 positions (IOW performs fast division
by 8) and then masks bits[2:0]. bloat-o-meter:

add/remove: 0/0 grow/shrink: 20/133 up/down: 156/-773 (-617)

Clang does it better and generates the same code before/after starting
from -O1, except that with the ALIGN() approach it uses %edx and thus
still saves some bytes:

add/remove: 0/0 grow/shrink: 9/133 up/down: 18/-538 (-520)

Note that we can't expand DIV_ROUND_UP() by adding a check and using
this approach there, as it's used in array declarations where
expressions are not allowed.
Add this helper to tools/ as well.

Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Acked-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-04-01 10:49:28 +01:00
..
airq.c s390/airq: remove lsi_mask from airq_struct 2023-08-30 11:03:28 +02:00
blacklist.c s390/cio: avoid excessive path-verification requests 2021-09-27 13:54:38 +02:00
blacklist.h
ccwgroup.c s390/cio: use while (i--) pattern to clean up 2024-03-17 19:08:49 +01:00
ccwreq.c
chp.c s390/cio: export CMG value as decimal 2023-10-25 15:08:29 +02:00
chp.h
chsc_sch.c s390/cio: remove unneeded DMA zone allocation 2024-02-09 13:58:15 +01:00
chsc_sch.h
chsc.c s390/cio: use while (i--) pattern to clean up 2024-03-17 19:08:49 +01:00
chsc.h s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
cio_debug.h
cio_debugfs.c
cio_inject.c
cio_inject.h
cio.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
cio.h s390/cio: make sch->lock spinlock pointer a member 2023-12-12 14:41:58 +01:00
cmf.c s390/cmf: fix virtual vs physical address confusion 2024-02-09 13:58:15 +01:00
crw.c s390: use control register bit defines 2023-09-19 13:26:57 +02:00
css.c s390/virtio_ccw: use DMA handle from DMA API 2024-03-13 09:23:46 +01:00
css.h s390/cio: evaluate devices with non-operational paths 2023-01-22 18:42:34 +01:00
device_fsm.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
device_id.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
device_ops.c s390/virtio_ccw: use DMA handle from DMA API 2024-03-13 09:23:46 +01:00
device_pgid.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
device_status.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
device.c s390/cio: make ccw_bus_type const 2024-02-09 13:58:16 +01:00
device.h
eadm_sch.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
eadm_sch.h
fcx.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
idset.c bitmap: introduce generic optimized bitmap_size() 2024-04-01 10:49:28 +01:00
idset.h
io_sch.h
ioasm.c s390/extable: move EX_TABLE define to asm-extable.h 2022-03-08 00:33:00 +01:00
ioasm.h
isc.c s390/ctlreg: add local and system prefix to some functions 2023-09-19 13:26:56 +02:00
itcw.c s390/cio: sort out physical vs virtual pointers usage 2022-12-01 10:58:04 +01:00
Makefile
orb.h s390/cio: use bitwise types to allow for type checking 2024-03-13 09:23:46 +01:00
qdio_debug.c s390: move from strlcpy with unused retval to strscpy 2022-08-30 22:00:33 +02:00
qdio_debug.h
qdio_main.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
qdio_setup.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
qdio_thinint.c s390/cio: use new address translation helpers 2024-03-13 09:23:47 +01:00
qdio.h s390/qdio: fix do_sqbs() inline assembly constraint 2023-05-17 15:20:17 +02:00
scm.c s390/cio: make scm_bus_type const 2024-02-09 13:58:16 +01:00
trace.c
trace.h s390: use struct tpi_info in lowcore.h 2021-06-07 17:07:01 +02:00
vfio_ccw_async.c vfio/ccw: Remove private->mdev 2022-07-07 14:06:12 -06:00
vfio_ccw_chp.c eventfd: simplify eventfd_signal() 2023-11-28 14:08:38 +01:00
vfio_ccw_cp.c s390/vfio_ccw_cp: use new address translation helpers 2024-03-13 09:23:49 +01:00
vfio_ccw_cp.h vfio/ccw: simplify the cp_get_orb interface 2023-01-09 14:34:07 +01:00
vfio_ccw_drv.c s390 updates for 6.8 merge window 2024-01-10 18:18:20 -08:00
vfio_ccw_fsm.c s390/vfio_ccw: fix virtual vs physical address confusion 2024-03-13 09:23:45 +01:00
vfio_ccw_ops.c eventfd: simplify eventfd_signal() 2023-11-28 14:08:38 +01:00
vfio_ccw_private.h vfio/ccw: replace one-element array with flexible-array member 2023-06-01 17:07:55 +02:00
vfio_ccw_trace.c
vfio_ccw_trace.h