regmap: Cleanup and microoptimization
Subsystems (2)
cover regmap: Cleanup and microoptimization
Two patches move the code to use BITS_TO_BYTES(), while the last one otpimizes the code generation on x86 (32- and 64-bit on different compilers).
Andy Shevchenko (3):
regmap: cache: Use BITS_TO_BYTES()
regmap: Use BITS_TO_BYTES()
regmap: place foo / 8 and foo % 8 closer to each other
drivers/base/regmap/regcache.c | 2 +- drivers/base/regmap/regmap.c | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 1/3 regmap: cache: Use BITS_TO_BYTES()
BITS_TO_BYTES() is the existing macro which takes care about full bytes that may fully hold the given amount of bits. Use it.
--- drivers/base/regmap/regcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regcache.c +1 -1
@@ -154,7 +154,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config) map->num_reg_defaults = config->num_reg_defaults; map->num_reg_defaults_raw = config->num_reg_defaults_raw; map->reg_defaults_raw = config->reg_defaults_raw; - map->cache_word_size =DIV_ROUND_UP (config->val_bits,8 ); + map->cache_word_size =BITS_TO_BYTES (config->val_bits); map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; map->cache =NULL ;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 2/3 regmap: Use BITS_TO_BYTES()
In reply to Andy ShevchenkoBITS_TO_BYTES() is the existing macro which takes care about full bytes that may fully hold the given amount of bits. Use it.
--- drivers/base/regmap/regmap.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/base/regmap/regmap.c +3 -4
@@ -759,12 +759,11 @@ struct regmap *__regmap_init(struct device *dev, map->reg_base = config->reg_base; - map->format.reg_bytes =DIV_ROUND_UP (config->reg_bits,8 ); + map->format.reg_bytes =BITS_TO_BYTES (config->reg_bits); map->format.pad_bytes = config->pad_bits /8 ; map->format.reg_shift = config->reg_shift; - map->format.val_bytes =DIV_ROUND_UP (config->val_bits,8 ); - map->format.buf_size =DIV_ROUND_UP (config->reg_bits + - config->val_bits + config->pad_bits,8 ); + map->format.val_bytes =BITS_TO_BYTES (config->val_bits); + map->format.buf_size =BITS_TO_BYTES (config->reg_bits + config->val_bits + config->pad_bits); map->reg_shift = config->pad_bits %8 ;if (config->reg_stride) map->reg_stride = config->reg_stride;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 3/3 regmap: place foo / 8 and foo % 8 closer to each other
In reply to Andy ShevchenkoOn x86 the compiler (gcc (Debian 14.2.0-8) 14.2.0) may generate a better code if it sees division and modulo goes together.
Function old new delta
__regmap_init 3740 3732 -8
Total: Before=31159, After=31151, chg -0.03%
clang (Debian clang version 18.1.8) on x86_64 still shows better code
Function old new delta
__regmap_init 3582 3579 -3
Total: Before=39854, After=39851, chg -0.01%
--- drivers/base/regmap/regmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/regmap/regmap.c +2 -2
@@ -758,13 +758,13 @@ struct regmap *__regmap_init(struct device *dev, map->alloc_flags =GFP_KERNEL ; map->reg_base = config->reg_base; + map->reg_shift = config->pad_bits %8 ; - map->format.reg_bytes =BITS_TO_BYTES (config->reg_bits); map->format.pad_bytes = config->pad_bits /8 ; map->format.reg_shift = config->reg_shift; + map->format.reg_bytes =BITS_TO_BYTES (config->reg_bits); map->format.val_bytes =BITS_TO_BYTES (config->val_bits); map->format.buf_size =BITS_TO_BYTES (config->reg_bits + config->val_bits + config->pad_bits); - map->reg_shift = config->pad_bits %8 ;if (config->reg_stride) map->reg_stride = config->reg_stride;else
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Mark Brown
maintainerQuoted 10 lines · Andy Shevchenko
Two patches move the code to use
BITS_TO_BYTES(), while the last one otpimizes the code generation on x86 (32- and 64-bit on different compilers).Andy Shevchenko (3):
regmap: cache: UseBITS_TO_BYTES()
regmap: UseBITS_TO_BYTES()
regmap: place foo / 8 and foo % 8 closer to each other[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[1/3] regmap: cache: Use BITS_TO_BYTES()
commit: 4a3aafe01f6c628932a402c21e58101173c8dab3
[2/3] regmap: Use BITS_TO_BYTES()
commit: a4a7d86bc1a59839ad0dffbefa473135b342dd0b
[3/3] regmap: place foo / 8 and foo % 8 closer to each other
commit: 9b3cd5c7099fe7710356dd76ecf9910dc8c32548All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark