mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Denys Vlasenko <vda.linux@googlemail.com>
To: musl@lists.openwall.com
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Subject: [PATCH 2/2] x86_64/memset: avoid prforming final store twice
Date: Tue, 10 Feb 2015 18:30:57 +0100	[thread overview]
Message-ID: <1423589457-8407-2-git-send-email-vda.linux@googlemail.com> (raw)
In-Reply-To: <1423589457-8407-1-git-send-email-vda.linux@googlemail.com>

The code does a potentially misaligned 8-byte store to fill the tail
of the buffer. Then it fills the initial part of the buffer
which is a multiple of 8 bytes.
Therefore, if size is divisible by 8, we were storing last word twice.

This patch decrements byte count before dividing it by 8,
making one less store in "size is divisible by 8" case,
and not changing anything in all other cases.
All at the cost of replacing one MOV insn with LEA insn.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 src/string/x86_64/memset.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/string/x86_64/memset.s b/src/string/x86_64/memset.s
index 263336b..3cc8fcf 100644
--- a/src/string/x86_64/memset.s
+++ b/src/string/x86_64/memset.s
@@ -9,7 +9,7 @@ memset:
 	cmp $16,%rdx
 	jb 1f
 
-	mov %rdx,%rcx
+	lea -1(%rdx),%rcx
 	mov %rdi,%r8
 	shr $3,%rcx
 	mov %rax,-8(%rdi,%rdx)
-- 
1.8.1.4



  reply	other threads:[~2015-02-10 17:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-10 17:30 [PATCH 1/2] x86_64/memset: simple optimizations Denys Vlasenko
2015-02-10 17:30 ` Denys Vlasenko [this message]
2015-02-10 20:50 ` Rich Felker
2015-02-10 21:08   ` Denys Vlasenko
2015-02-10 21:37     ` Rich Felker
2015-02-10 22:36       ` Rich Felker
2015-02-10 23:20         ` Rich Felker
2015-02-11  1:07       ` Denys Vlasenko
2015-02-11  1:21         ` Rich Felker

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=1423589457-8407-2-git-send-email-vda.linux@googlemail.com \
    --to=vda.linux@googlemail.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).