From: tip-bot for Alexey Dobriyan <adobriyan@gmail.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
torvalds@linux-foundation.org, JBeulich@suse.com,
tglx@linutronix.de, adobriyan@gmail.com, mingo@elte.hu
Subject: [tip:x86/asm] x86/i386: Use less assembly in strlen(), speed things up a bit
Date: Mon, 12 Dec 2011 10:37:23 -0800 [thread overview]
Message-ID: <tip-890890cb8e415e1e7a61bfe3c8e246f710196824@git.kernel.org> (raw)
In-Reply-To: <20111211181319.GA17097@p183.telecom.by>
Commit-ID: 890890cb8e415e1e7a61bfe3c8e246f710196824
Gitweb: http://git.kernel.org/tip/890890cb8e415e1e7a61bfe3c8e246f710196824
Author: Alexey Dobriyan <adobriyan@gmail.com>
AuthorDate: Sun, 11 Dec 2011 21:13:19 +0300
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 12 Dec 2011 18:33:42 +0100
x86/i386: Use less assembly in strlen(), speed things up a bit
Current i386 strlen() hardcodes NOT/DEC sequence. DEC is
mentioned to be suboptimal on Core2. So, put only REPNE SCASB
sequence in assembly, compiler can do the rest.
The difference in generated code is like below (MCORE2=y):
<strlen>:
push %edi
mov $0xffffffff,%ecx
mov %eax,%edi
xor %eax,%eax
repnz scas %es:(%edi),%al
not %ecx
- dec %ecx
- mov %ecx,%eax
+ lea -0x1(%ecx),%eax
pop %edi
ret
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jan Beulich <JBeulich@suse.com>
Link: http://lkml.kernel.org/r/20111211181319.GA17097@p183.telecom.by
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/lib/string_32.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/arch/x86/lib/string_32.c b/arch/x86/lib/string_32.c
index 82004d2..bd59090 100644
--- a/arch/x86/lib/string_32.c
+++ b/arch/x86/lib/string_32.c
@@ -164,15 +164,13 @@ EXPORT_SYMBOL(strchr);
size_t strlen(const char *s)
{
int d0;
- int res;
+ size_t res;
asm volatile("repne\n\t"
- "scasb\n\t"
- "notl %0\n\t"
- "decl %0"
+ "scasb"
: "=c" (res), "=&D" (d0)
: "1" (s), "a" (0), "0" (0xffffffffu)
: "memory");
- return res;
+ return ~res - 1;
}
EXPORT_SYMBOL(strlen);
#endif
next prev parent reply other threads:[~2011-12-12 18:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-11 18:13 [PATCH] i386: less assembly in strlen() Alexey Dobriyan
2011-12-12 18:37 ` tip-bot for Alexey Dobriyan [this message]
2011-12-12 18:54 ` [tip:x86/asm] x86/i386: Use less assembly in strlen(), speed things up a bit Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-890890cb8e415e1e7a61bfe3c8e246f710196824@git.kernel.org \
--to=adobriyan@gmail.com \
--cc=JBeulich@suse.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox