xref: /netbsd-src/lib/libc/arch/i386/string/strncmp.S (revision 0d34bfa26d596b4f9bcb49175a92020d91572850)
10b9f5089Scgd/*
299410184Ssalo * Written by J.T. Conklin <jtc@NetBSD.org>.
3954b7961Sjtc * Public domain.
40b9f5089Scgd */
50b9f5089Scgd
601284ad8Sjtc#include <machine/asm.h>
70b9f5089Scgd
8c95cd47bSjtc#if defined(LIBC_SCCS)
9*0d34bfa2Suebayasi	RCSID("$NetBSD: strncmp.S,v 1.15 2014/05/23 02:34:19 uebayasi Exp $")
10c95cd47bSjtc#endif
11c95cd47bSjtc
120b9f5089Scgd/*
13954b7961Sjtc * NOTE: I've unrolled the loop eight times: large enough to make a
140b9f5089Scgd * significant difference, and small enough not to totally trash the
1501284ad8Sjtc * cache.
160b9f5089Scgd */
170b9f5089Scgd
180b9f5089ScgdENTRY(strncmp)
190b9f5089Scgd	pushl	%ebx
200b9f5089Scgd	movl	8(%esp),%eax
210b9f5089Scgd	movl	12(%esp),%ecx
220b9f5089Scgd	movl	16(%esp),%edx
2301284ad8Sjtc	testl	%edx,%edx
240b9f5089Scgd	jmp	L2			/* Jump into the loop! */
250b9f5089Scgd
2674511f97Skleink	_ALIGN_TEXT,0x90
270b9f5089ScgdL1:	incl	%eax
280b9f5089Scgd	incl	%ecx
290b9f5089Scgd	decl	%edx
3090ff28feSmycroftL2:	jz	L4			/* strings are equal */
310b9f5089Scgd	movb	(%eax),%bl
32e09d2f42Sjtc	testb	%bl,%bl
3390ff28feSmycroft	jz	L3
340b9f5089Scgd	cmpb	%bl,(%ecx)
350b9f5089Scgd	jne	L3
3601284ad8Sjtc
370b9f5089Scgd	incl	%eax
380b9f5089Scgd	incl	%ecx
390b9f5089Scgd	decl	%edx
4090ff28feSmycroft	jz	L4
410b9f5089Scgd	movb	(%eax),%bl
42e09d2f42Sjtc	testb	%bl,%bl
4390ff28feSmycroft	jz	L3
440b9f5089Scgd	cmpb	%bl,(%ecx)
450b9f5089Scgd	jne	L3
4601284ad8Sjtc
470b9f5089Scgd	incl	%eax
480b9f5089Scgd	incl	%ecx
490b9f5089Scgd	decl	%edx
5090ff28feSmycroft	jz	L4
510b9f5089Scgd	movb	(%eax),%bl
52e09d2f42Sjtc	testb	%bl,%bl
5390ff28feSmycroft	jz	L3
540b9f5089Scgd	cmpb	%bl,(%ecx)
550b9f5089Scgd	jne	L3
5601284ad8Sjtc
570b9f5089Scgd	incl	%eax
580b9f5089Scgd	incl	%ecx
590b9f5089Scgd	decl	%edx
6090ff28feSmycroft	jz	L4
610b9f5089Scgd	movb	(%eax),%bl
62e09d2f42Sjtc	testb	%bl,%bl
6390ff28feSmycroft	jz	L3
640b9f5089Scgd	cmpb	%bl,(%ecx)
650b9f5089Scgd	jne	L3
6601284ad8Sjtc
670b9f5089Scgd	incl	%eax
680b9f5089Scgd	incl	%ecx
690b9f5089Scgd	decl	%edx
7090ff28feSmycroft	jz	L4
710b9f5089Scgd	movb	(%eax),%bl
72e09d2f42Sjtc	testb	%bl,%bl
7390ff28feSmycroft	jz	L3
740b9f5089Scgd	cmpb	%bl,(%ecx)
750b9f5089Scgd	jne	L3
7601284ad8Sjtc
770b9f5089Scgd	incl	%eax
780b9f5089Scgd	incl	%ecx
790b9f5089Scgd	decl	%edx
8090ff28feSmycroft	jz	L4
810b9f5089Scgd	movb	(%eax),%bl
82e09d2f42Sjtc	testb	%bl,%bl
8390ff28feSmycroft	jz	L3
840b9f5089Scgd	cmpb	%bl,(%ecx)
850b9f5089Scgd	jne	L3
8601284ad8Sjtc
870b9f5089Scgd	incl	%eax
880b9f5089Scgd	incl	%ecx
890b9f5089Scgd	decl	%edx
9090ff28feSmycroft	jz	L4
910b9f5089Scgd	movb	(%eax),%bl
92e09d2f42Sjtc	testb	%bl,%bl
9390ff28feSmycroft	jz	L3
940b9f5089Scgd	cmpb	%bl,(%ecx)
950b9f5089Scgd	jne	L3
9601284ad8Sjtc
970b9f5089Scgd	incl	%eax
980b9f5089Scgd	incl	%ecx
990b9f5089Scgd	decl	%edx
10090ff28feSmycroft	jz	L4
1010b9f5089Scgd	movb	(%eax),%bl
102e09d2f42Sjtc	testb	%bl,%bl
10390ff28feSmycroft	jz	L3
1040b9f5089Scgd	cmpb	%bl,(%ecx)
1050b9f5089Scgd	je	L1
10601284ad8Sjtc
10774511f97Skleink	_ALIGN_TEXT,0x90
108afc37a84SrpauloL3:	movzbl	(%eax),%eax		/* unsigned comparison */
1095cffad21Sjtc	movzbl	(%ecx),%ecx
1100b9f5089Scgd	subl	%ecx,%eax
1110b9f5089Scgd	popl	%ebx
1120b9f5089Scgd	ret
11374511f97Skleink	_ALIGN_TEXT,0x90
1140b9f5089ScgdL4:	xorl	%eax,%eax
1150b9f5089Scgd	popl	%ebx
1160b9f5089Scgd	ret
117*0d34bfa2SuebayasiEND(strncmp)
118