Home | History | Annotate | Line # | Download | only in string
      1 /*
      2  * Written by J.T. Conklin <jtc (at) NetBSD.org>.
      3  * Public domain.
      4  */
      5 
      6 #include <machine/asm.h>
      7 
      8 #if defined(LIBC_SCCS)
      9         RCSID("$NetBSD: strncmp.S,v 1.4 2014/05/22 15:01:57 uebayasi Exp $")
     10 #endif
     11 
     12 /*
     13  * NOTE: I've unrolled the loop eight times: large enough to make a
     14  * significant difference, and small enough not to totally trash the
     15  * cache.
     16  */
     17 
     18 ENTRY(strncmp)
     19 	testq	%rdx,%rdx
     20 	jmp	L2			/* Jump into the loop! */
     21 
     22 L1:	incq	%rdi
     23 	incq	%rsi
     24 	decq	%rdx
     25 L2:	jz	L4			/* strings are equal */
     26 	movb	(%rdi),%al
     27 	testb	%al,%al
     28 	jz	L3
     29 	cmpb	%al,(%rsi)
     30 	jne	L3
     31 
     32 	incq	%rdi
     33 	incq	%rsi
     34 	decq	%rdx
     35 	jz	L4
     36 	movb	(%rdi),%al
     37 	testb	%al,%al
     38 	jz	L3
     39 	cmpb	%al,(%rsi)
     40 	jne	L3
     41 
     42 	incq	%rdi
     43 	incq	%rsi
     44 	decq	%rdx
     45 	jz	L4
     46 	movb	(%rdi),%al
     47 	testb	%al,%al
     48 	jz	L3
     49 	cmpb	%al,(%rsi)
     50 	jne	L3
     51 
     52 	incq	%rdi
     53 	incq	%rsi
     54 	decq	%rdx
     55 	jz	L4
     56 	movb	(%rdi),%al
     57 	testb	%al,%al
     58 	jz	L3
     59 	cmpb	%al,(%rsi)
     60 	jne	L3
     61 
     62 	incq	%rdi
     63 	incq	%rsi
     64 	decq	%rdx
     65 	jz	L4
     66 	movb	(%rdi),%al
     67 	testb	%al,%al
     68 	jz	L3
     69 	cmpb	%al,(%rsi)
     70 	jne	L3
     71 
     72 	incq	%rdi
     73 	incq	%rsi
     74 	decq	%rdx
     75 	jz	L4
     76 	movb	(%rdi),%al
     77 	testb	%al,%al
     78 	jz	L3
     79 	cmpb	%al,(%rsi)
     80 	jne	L3
     81 
     82 	incq	%rdi
     83 	incq	%rsi
     84 	decq	%rdx
     85 	jz	L4
     86 	movb	(%rdi),%al
     87 	testb	%al,%al
     88 	jz	L3
     89 	cmpb	%al,(%rsi)
     90 	jne	L3
     91 
     92 	incq	%rdi
     93 	incq	%rsi
     94 	decq	%rdx
     95 	jz	L4
     96 	movb	(%rdi),%al
     97 	testb	%al,%al
     98 	jz	L3
     99 	cmpb	%al,(%rsi)
    100 	je	L1
    101 
    102 L3:	movzbl	(%rdi),%eax		/* unsigned comparison */
    103 	movzbl	(%rsi),%ecx
    104 	subl	%ecx,%eax
    105 	ret
    106 L4:	xorl	%eax,%eax
    107 	ret
    108 END(strncmp)
    109