xref: /titanic_51/usr/src/lib/libc/amd64/gen/wsncmp.s (revision 9a70fc3be3b1e966bf78825cdb8d509963a6f0a1)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217257d1b4Sraf
227c478bd9Sstevel@tonic-gate/*
237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*9a70fc3bSMark J. Nelson	.file	"wsncmp.s"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate/
307c478bd9Sstevel@tonic-gate/ Wide character wcsncpy() implementation
317c478bd9Sstevel@tonic-gate/
327c478bd9Sstevel@tonic-gate/ Algorithm based on Solaris 2.6 gen/strncpy.s implementation
337c478bd9Sstevel@tonic-gate/
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(wcsncmp,function)
387c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(wsncmp,function)
397c478bd9Sstevel@tonic-gate
407257d1b4Sraf	ENTRY(wcsncmp)		/* (wchar *ws1, wchar_t *ws2, size_t n) */
417c478bd9Sstevel@tonic-gate	cmpq	%rdi,%rsi	/ same string?
427c478bd9Sstevel@tonic-gate	je	.equal
437c478bd9Sstevel@tonic-gate	incq	%rdx		/ will later predecrement this uint
447c478bd9Sstevel@tonic-gate.loop:
457c478bd9Sstevel@tonic-gate	decq	%rdx
467c478bd9Sstevel@tonic-gate	je	.equal		/ Used all n chars?
477c478bd9Sstevel@tonic-gate	movl	(%rdi),%eax	/ slodb ; scab
487c478bd9Sstevel@tonic-gate	cmpl	(%rsi),%eax
497c478bd9Sstevel@tonic-gate	jne	.notequal_0	/ Are the bytes equal?
507c478bd9Sstevel@tonic-gate	testl	%eax,%eax
517c478bd9Sstevel@tonic-gate	je	.equal		/ End of string?
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate	decq	%rdx
547c478bd9Sstevel@tonic-gate	je	.equal		/ Used all n chars?
557c478bd9Sstevel@tonic-gate	movl	4(%rdi),%eax	/ slodb ; scab
567c478bd9Sstevel@tonic-gate	cmpl	4(%rsi),%eax
577c478bd9Sstevel@tonic-gate	jne	.notequal_1	/ Are the bytes equal?
587c478bd9Sstevel@tonic-gate	testl	%eax,%eax
597c478bd9Sstevel@tonic-gate	je	.equal		/ End of string?
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate	decq	%rdx
627c478bd9Sstevel@tonic-gate	je	.equal		/ Used all n chars?
637c478bd9Sstevel@tonic-gate	movl	8(%rdi),%eax	/ slodb ; scab
647c478bd9Sstevel@tonic-gate	cmpl	8(%rsi),%eax
657c478bd9Sstevel@tonic-gate	jne	.notequal_2	/ Are the bytes equal?
667c478bd9Sstevel@tonic-gate	testl	%eax,%eax
677c478bd9Sstevel@tonic-gate	je	.equal		/ End of string?
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate	decq	%rdx
707c478bd9Sstevel@tonic-gate	je	.equal		/ Used all n chars?
717c478bd9Sstevel@tonic-gate	movl	12(%rdi),%eax	/ slodb ; scab
727c478bd9Sstevel@tonic-gate	cmpl	12(%rsi),%eax
737c478bd9Sstevel@tonic-gate	jne	.notequal_3	/ Are the bytes equal?
747c478bd9Sstevel@tonic-gate	addq	$16,%rdi
757c478bd9Sstevel@tonic-gate	addq	$16,%rsi
767c478bd9Sstevel@tonic-gate	testl	%eax,%eax
777c478bd9Sstevel@tonic-gate	jne	.loop		/ End of string?
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate.equal:
807c478bd9Sstevel@tonic-gate	xorl	%eax,%eax	/ return 0
817c478bd9Sstevel@tonic-gate	ret
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate	.align	4
847c478bd9Sstevel@tonic-gate.notequal_3:
857c478bd9Sstevel@tonic-gate	addq	$4,%rsi
867c478bd9Sstevel@tonic-gate.notequal_2:
877c478bd9Sstevel@tonic-gate	addq	$4,%rsi
887c478bd9Sstevel@tonic-gate.notequal_1:
897c478bd9Sstevel@tonic-gate	addq	$4,%rsi
907c478bd9Sstevel@tonic-gate.notequal_0:
917c478bd9Sstevel@tonic-gate	subl	(%rsi),%eax	/ return value is (*s1 - *--s2)
927c478bd9Sstevel@tonic-gate	ret
937257d1b4Sraf	SET_SIZE(wcsncmp)
947c478bd9Sstevel@tonic-gate
957257d1b4Sraf	ENTRY(wsncmp)
967257d1b4Sraf	jmp	wcsncmp		/ tail call into wcsncmp
977257d1b4Sraf	SET_SIZE(wsncmp)
98