From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6964 Path: news.gmane.org!not-for-mail From: Denys Vlasenko Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 2/2] x86_64/memset: avoid prforming final store twice Date: Tue, 10 Feb 2015 18:30:57 +0100 Message-ID: <1423589457-8407-2-git-send-email-vda.linux@googlemail.com> References: <1423589457-8407-1-git-send-email-vda.linux@googlemail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1423589481 25135 80.91.229.3 (10 Feb 2015 17:31:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Feb 2015 17:31:21 +0000 (UTC) Cc: Denys Vlasenko To: musl@lists.openwall.com Original-X-From: musl-return-6977-gllmg-musl=m.gmane.org@lists.openwall.com Tue Feb 10 18:31:21 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YLEee-0005fq-G3 for gllmg-musl@m.gmane.org; Tue, 10 Feb 2015 18:31:20 +0100 Original-Received: (qmail 9284 invoked by uid 550); 10 Feb 2015 17:31:18 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9252 invoked from network); 10 Feb 2015 17:31:17 -0000 In-Reply-To: <1423589457-8407-1-git-send-email-vda.linux@googlemail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Xref: news.gmane.org gmane.linux.lib.musl.general:6964 Archived-At: 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 --- 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