Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1471015 > unrolled thread

[PATCH] kstrtox: smaller _parse_integer()

Started byAlexey Dobriyan <adobriyan@gmail.com>
First post2016-08-27 00:20 +0200
Last post2016-08-27 00:20 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] kstrtox: smaller _parse_integer() Alexey Dobriyan <adobriyan@gmail.com> - 2016-08-27 00:20 +0200

#1471015 — [PATCH] kstrtox: smaller _parse_integer()

FromAlexey Dobriyan <adobriyan@gmail.com>
Date2016-08-27 00:20 +0200
Subject[PATCH] kstrtox: smaller _parse_integer()
Message-ID<saxDI-4xv-13@gated-at.bofh.it>
Set "overflow" bit upon encountering it instead of postponing to the end
of the conversion. Somehow gcc unwedges itself and generates better code:

	$ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux
	_parse_integer                      177     139     -38

Inspired by patch from Zhaoxiu Zeng.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 lib/kstrtox.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -48,11 +48,9 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
 {
 	unsigned long long res;
 	unsigned int rv;
-	int overflow;
 
 	res = 0;
 	rv = 0;
-	overflow = 0;
 	while (*s) {
 		unsigned int val;
 
@@ -71,15 +69,13 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
 		 */
 		if (unlikely(res & (~0ull << 60))) {
 			if (res > div_u64(ULLONG_MAX - val, base))
-				overflow = 1;
+				rv |= KSTRTOX_OVERFLOW;
 		}
 		res = res * base + val;
 		rv++;
 		s++;
 	}
 	*p = res;
-	if (overflow)
-		rv |= KSTRTOX_OVERFLOW;
 	return rv;
 }
 

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web