This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v2] Do not multiply by zero in bzero.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Richard Henderson <rth at twiddle dot net>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 22 Mar 2013 09:14:22 +0100
- Subject: [PATCH v2] Do not multiply by zero in bzero.
- References: <20130321162026 dot GA16603 at domone dot kolej dot mff dot cuni dot cz> <514B6A49 dot 3050401 at twiddle dot net>
Here is updated version.
On Thu, Mar 21, 2013 at 01:15:05PM -0700, Richard Henderson wrote:
> On 03/21/2013 09:20 AM, OndÅej BÃlka wrote:
> > - mov %rsi,%rdx /* Adjust parameter. */
> > - xorl %esi,%esi /* Fill with 0s. */
> > - jmp L(memset_entry)
> > + mov %rsi,%r8 /* Adjust parameter. */
>
ok
> Please update the comment. It's no longer to adjust the parameter,
> it's to put the address where the body of memset wants it.
>
> > + xor %rdx,%rdx /* Fill with 0s. */
>
ok
> edx avoids the rex prefix
>
> > +
> > + cmp $0x1,%r8
> > + mov %rdi,%rax /* memset returns the dest address. */
>
> But this is bzero, not memset. The return type is void.
> You could in fact eliminate this insn.
Nice catch.
>
>
> r~
* sysdeps/x86_64/memset.S (memset): Move entry from bzero.
(bzero): Skip multiplication by zero in memset.
---
sysdeps/x86_64/memset.S | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/sysdeps/x86_64/memset.S b/sysdeps/x86_64/memset.S
index b393efe..bb7ddad 100644
--- a/sysdeps/x86_64/memset.S
+++ b/sysdeps/x86_64/memset.S
@@ -25,9 +25,14 @@
.text
#if !defined NOT_IN_libc
ENTRY(__bzero)
- mov %rsi,%rdx /* Adjust parameter. */
- xorl %esi,%esi /* Fill with 0s. */
- jmp L(memset_entry)
+ mov %rsi,%r8 /* Move length where memset expects it. */
+ xor %edx,%edx /* Fill with 0s. */
+
+ cmp $0x1,%r8
+ jne L(entry_from_bzero)
+ mov %dl,(%rdi)
+ retq
+
END(__bzero)
weak_alias (__bzero, bzero)
#endif
@@ -39,7 +44,6 @@ ENTRY_CHK (__memset_chk)
END_CHK (__memset_chk)
#endif
ENTRY (memset)
-L(memset_entry):
cmp $0x1,%rdx
mov %rdi,%rax /* memset returns the dest address. */
jne L(ck2)
@@ -50,6 +54,7 @@ L(ck2):
mov %rdx,%r8
movzbq %sil,%rdx
imul %r9,%rdx
+L(entry_from_bzero):
L(now_dw_aligned):
cmp $0x90,%r8
ja L(ck_mem_ops_method)
--
1.7.4.4