Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1423589457-8407-2-git-send-email-vda.linux@googlemail.com>
Date: Tue, 10 Feb 2015 18:30:57 +0100
From: Denys Vlasenko <vda.linux@...glemail.com>
To: musl@...ts.openwall.com
Cc: Denys Vlasenko <vda.linux@...glemail.com>
Subject: [PATCH 2/2] x86_64/memset: avoid prforming final store twice

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@...glemail.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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.