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


Groups > linux.kernel > #1470954 > unrolled thread

[PATCH] make isdigit() table lookupless

Started byAlexey Dobriyan <adobriyan@gmail.com>
First post2016-08-26 21:10 +0200
Last post2016-08-26 21:10 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] make isdigit() table lookupless Alexey Dobriyan <adobriyan@gmail.com> - 2016-08-26 21:10 +0200

#1470954 — [PATCH] make isdigit() table lookupless

FromAlexey Dobriyan <adobriyan@gmail.com>
Date2016-08-26 21:10 +0200
Subject[PATCH] make isdigit() table lookupless
Message-ID<sauFQ-2Ek-19@gated-at.bofh.it>
Make isdigit into a simple range checking inline function:

	return '0' <= c && c <= '9';

This code is 1 branch, not 2 because any reasonable compiler can
optimize this code into SUB+CMP, so the code

	while (isdigit((c = *s++)))
		...

remains 1 branch per iteration HOWEVER it suddenly doesn't do table
lookup priming cacheline nobody cares about.

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

 include/linux/ctype.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/include/linux/ctype.h
+++ b/include/linux/ctype.h
@@ -22,7 +22,10 @@ extern const unsigned char _ctype[];
 #define isalnum(c)	((__ismask(c)&(_U|_L|_D)) != 0)
 #define isalpha(c)	((__ismask(c)&(_U|_L)) != 0)
 #define iscntrl(c)	((__ismask(c)&(_C)) != 0)
-#define isdigit(c)	((__ismask(c)&(_D)) != 0)
+static inline int isdigit(int c)
+{
+	return '0' <= c && c <= '9';
+}
 #define isgraph(c)	((__ismask(c)&(_P|_U|_L|_D)) != 0)
 #define islower(c)	((__ismask(c)&(_L)) != 0)
 #define isprint(c)	((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web