Browse Source

amd64 string ops: replace some instructions by smaller ones,
e.g. testb $0xff, %cl -> testb %cl, %cl

Denis Vlasenko 16 years ago
parent
commit
534dfb536f

+ 4 - 4
libc/string/x86_64/memset.S

@@ -53,15 +53,15 @@ ENTRY (memset)
 	imul	%rax,%r8
 #endif
 	test	$0x7,%edi	/* Check for alignment.  */
-	je	2f
+	jz	2f
 
 	.p2align 4
 1:	/* Align ptr to 8 byte.  */
 	mov	%sil,(%rcx)
 	dec	%rdx
 	inc	%rcx
-	test	$0x7,%ecx
-	jne	1b
+	test	$0x7,%cl
+	jnz	1b
 
 2:	/* Check for really large regions.  */
 	mov	%rdx,%rax
@@ -107,7 +107,7 @@ ENTRY (memset)
 	jne	8b
 9:
 #if BZERO_P
-	nop	/* huh?? */
+	/* nothing */
 #else
 	/* Load result (only if used as memset).  */
 	mov	%rdi,%rax	/* start address of destination is result */

+ 1 - 1
libc/string/x86_64/strcat.S

@@ -103,7 +103,7 @@ ENTRY (BP_SYM (strcat))
 				   the addition will not result in 0.  */
 	jz 4b			/* no NUL found => continue loop */
 
-	.p2align 4		/* Align, it's a jump target.  */
+	.p2align 4		/* Align, it is a jump target.  */
 3:	subq $8,%rax		/* correct pointer increment.  */
 
 	testb %cl, %cl		/* is first byte NUL? */

+ 3 - 4
libc/string/x86_64/strcspn.S

@@ -26,7 +26,6 @@
 #include "_glibc_inc.h"
 
 /* Seems to be unrolled too much */
-/* (and why testb $0xff, %cl, not testb %cl, %cl?) */
 
 /* BEWARE: `#ifdef strcspn' means that strcspn is redefined as `strpbrk' */
 #define STRPBRK_P (defined strcspn)
@@ -63,19 +62,19 @@ L(2):	movb (%rax), %cl	/* get byte from skipset */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in skipset table */
 
 	movb 1(%rax), %cl	/* get byte from skipset */
-	testb $0xff, %cl	/* is NUL char? */
+	testb %cl, %cl		/* is NUL char? */
 	jz L(1)			/* yes => start compare loop */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in skipset table */
 
 	movb 2(%rax), %cl	/* get byte from skipset */
-	testb $0xff, %cl	/* is NUL char? */
+	testb %cl, %cl		/* is NUL char? */
 	jz L(1)			/* yes => start compare loop */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in skipset table */
 
 	movb 3(%rax), %cl	/* get byte from skipset */
 	addq $4, %rax		/* increment skipset pointer */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in skipset table */
-	testb $0xff, %cl	/* is NUL char? */
+	testb %cl, %cl		/* is NUL char? */
 	jnz L(2)		/* no => process next dword from skipset */
 
 L(1):	leaq -4(%rdx), %rax	/* prepare loop */

+ 1 - 1
libc/string/x86_64/strlen.S

@@ -98,7 +98,7 @@ ENTRY (strlen)
 				   the addition will not result in 0.  */
 	jz 4b			/* no NUL found => continue loop */
 
-	.p2align 4		/* Align, it's a jump target.  */
+	.p2align 4		/* Align, it is a jump target.  */
 3:	subq $8,%rax		/* correct pointer increment.  */
 
 	testb %cl, %cl		/* is first byte NUL? */

+ 3 - 3
libc/string/x86_64/strspn.S

@@ -57,19 +57,19 @@ L(2):	movb (%rax), %cl	/* get byte from stopset */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in stopset table */
 
 	movb 1(%rax), %cl	/* get byte from stopset */
-	testb $0xff, %cl	/* is NUL char? */
+	testb %cl, %cl		/* is NUL char? */
 	jz L(1)			/* yes => start compare loop */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in stopset table */
 
 	movb 2(%rax), %cl	/* get byte from stopset */
-	testb $0xff, %cl	/* is NUL char? */
+	testb %cl, %cl		/* is NUL char? */
 	jz L(1)			/* yes => start compare loop */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in stopset table */
 
 	movb 3(%rax), %cl	/* get byte from stopset */
 	addq $4, %rax		/* increment stopset pointer */
 	movb %cl, (%rsp,%rcx)	/* set corresponding byte in stopset table */
-	testb $0xff, %cl	/* is NUL char? */
+	testb %cl, %cl		/* is NUL char? */
 	jnz L(2)		/* no => process next dword from stopset */
 
 L(1):	leaq -4(%rdx), %rax	/* prepare loop */