Skip to contentSkip to conversation

vsprintf: uninline simple_strntoull(), reorder arguments

PATCH Andy Shevchenko 2 participants 2 messages Oct 30, 2023 – Nov 1, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 82a2af6e-9b6c-4a09-89d7-ca90cc1cdad1@p183

Andy Shevchenko

author Reviewed-by
#1 lore raw
Quoted 6 lines · Alexey Dobriyan

* uninline simple_strntoull(),
gcc overinlines and this function is not performance critical

* reorder arguments, so that appending INT_MAX as 4th argument generates very efficient tail call

Quoted 8 lines

Space savings:

add/remove: 1/0 grow/shrink: 0/3 up/down: 27/-179 (-152)
Function old new delta
simple_strntoll - 27 +27
simple_strtoull 15 10 -5
simple_strtoll 41 7 -34
vsscanf 1930 1790 -140

Makes sense to me

...

Review

Quoted 12 lines
(quoted diff) +4 -6
 		if (is_sign)
-			val.s = simple_strntoll(str,
-						field_width >= 0 ? field_width : INT_MAX,
-						&next, base);
+			val.s = simple_strntoll(str, &next, base,
+						field_width >= 0 ? field_width : INT_MAX);
 		else
-			val.u = simple_strntoull(str,
-						 field_width >= 0 ? field_width : INT_MAX,
-						 &next, base);
+			val.u = simple_strntoull(str, &next, base,
+						 field_width >= 0 ? field_width : INT_MAX);

Looking at these, why do we even care about signedness? field_witdh IIRC is 16-bit or less and if size_t is to big it's still fine. No?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by
#2 lore raw
In reply to a message not in the archive
Quoted 8 lines · Alexey Dobriyan

* uninline simple_strntoull(),
gcc overinlines and this function is not performance critical

* reorder arguments, so that appending INT_MAX as 4th argument generates very efficient tail call

Space savings:

Quoted 8 lines

add/remove: 1/0 grow/shrink: 0/3 up/down: 27/-179 (-152)
Function old new delta
simple_strntoll - 27 +27
simple_strtoull 15 10 -5
simple_strtoll 41 7 -34
vsscanf 1930 1790 -140

I am usually quite skeptical about these micro-optimizations. They might help only on some architectures with some compiler versions. And they might make it worse for others.

Well, I could imagine that passing constant via the last parameter might help in most cases. And the new ordering of the parameters is fine. So let's get it in.

I have just pushed the patch into printk/linux.git, branch for-6.7.

Best Regards,
Petr