Skip to content

minmax: Optimise to reduce .i line length

David Laight dri-devel linux-btrfs linux-mm lkml llvm netdev oe-kbuild-all 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest11 patches 9 repliesIn review
  2. v13 of 11 patches 16 repliesSuperseded

Changes in v2 from the cover letter

- Typographical and spelling corrections to the commit messages. Patches unchanged.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11minmax: Put all the clamp() definitions togetherinclude/linux/minmax.h+56 -640 replies
2/11minmax: Use _Static_assert() instead of static_assert()include/linux/minmax.h+4 -43 replies
3/11minmax: Simplify signedness checkinclude/linux/minmax.h+10 -121 reply
4/11minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__include/linux/minmax.h+24 -240 replies
5/11minmax: Move the signedness check out of __cmp_once() and __clamp_once()include/linux/minmax.h+7 -70 replies
6/11minmax: Remove 'constexpr' check from __careful_clamp()include/linux/minmax.h+7 -70 replies
7/11minmax: minmax: Add __types_ok3() and optimise defines with 3 argumentsinclude/linux/minmax.h+19 -40 replies
8/11minmax: Add min_const() and max_const()include/linux/minmax.h+15 -04 replies
9/11tree-wide: minmax: Replace all the uses of max() for array sizes with max_const()drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c drivers/gpu/drm/drm_color_mgmt.c drivers/input/touchscreen/cyttsp4_core.c +5 more+10 -100 replies
10/11block: Use a boolean expression instead of max() on booleansblock/blk-settings.c+1 -10 replies
11/11minmax: min() and max() don't need to return constant expressionsinclude/linux/minmax.h+12 -111 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH next v2 00/11] minmax: Optimise to reduce .i line length

The changes to minmax.h that changed the type check to a signedness check significantly increased the length of the expansion. In some cases it has also significantly increased compile type. This is particularly noticable for nested expansions.

The fact that _Static_assert() only requires a compile time constant not a constant expression allows a lot of simplification.

The other thing that compilicates the expansion is the necessity of returning a constant expression from constant arguments (for VLA). I can only find a handful of places this is done. Penalising most of the code for these few cases seems 'suboptimal'. Instead I've added min_const() and max_const() for VLA and static initialisers, these check the arguments are constant to avoid misuse.

Patch [9] is dependant on the earlier patches.
Patch [10] isn't dependant on them.
Patch [11] depends on both 9 and 10.

Changes for v2:
- Typographical and spelling corrections to the commit messages. Patches unchanged.

David Laight (11):
[1] minmax: Put all the clamp() definitions together
[2] minmax: Use _Static_assert() instead of static_assert()
[3] minmax: Simplify signedness check
[4] minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__
[5] minmax: Move the signedness check out of __cmp_once() and

    __clamp_once()
  [6] minmax: Remove 'constexpr' check from __careful_clamp()
  [7] minmax: minmax: Add __types_ok3() and optimise defines with 3
    arguments
  [8] minmax: Add min_const() and max_const()
  [9] tree-wide: minmax: Replace all the uses of max() for array sizes with
    max_const().

[10] block: Use a boolean expression instead of max() on booleans
[11] minmax: min() and max() don't need to return constant expressions

 block/blk-settings.c                          |   2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c        |   2 +-
 drivers/gpu/drm/drm_color_mgmt.c              |   4 +-
 drivers/input/touchscreen/cyttsp4_core.c      |   2 +-
 .../net/can/usb/etas_es58x/es58x_devlink.c    |   2 +-
 fs/btrfs/tree-checker.c                       |   2 +-
 include/linux/minmax.h                        | 211 ++++++++++--------
 lib/vsprintf.c                                |   4 +-
 net/ipv4/proc.c                               |   2 +-
 net/ipv6/proc.c                               |   2 +-
 10 files changed, 127 insertions(+), 106 deletions(-)
Signature · 5 lines
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)