10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56812Sraf * Common Development and Distribution License (the "License"). 66812Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 216812Sraf 220Sstevel@tonic-gate/* 236812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 27*7298SMark.J.Nelson@Sun.COM .file "wsncmp.s" 280Sstevel@tonic-gate 290Sstevel@tonic-gate/ 300Sstevel@tonic-gate/ Wide character wcsncpy() implementation 310Sstevel@tonic-gate/ 320Sstevel@tonic-gate/ Algorithm based on Solaris 2.6 gen/strncpy.s implementation 330Sstevel@tonic-gate/ 340Sstevel@tonic-gate 350Sstevel@tonic-gate#include <sys/asm_linkage.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate ANSI_PRAGMA_WEAK(wcsncmp,function) 380Sstevel@tonic-gate ANSI_PRAGMA_WEAK(wsncmp,function) 390Sstevel@tonic-gate 406812Sraf ENTRY(wcsncmp) /* (wchar *ws1, wchar_t *ws2, size_t n) */ 410Sstevel@tonic-gate cmpq %rdi,%rsi / same string? 420Sstevel@tonic-gate je .equal 430Sstevel@tonic-gate incq %rdx / will later predecrement this uint 440Sstevel@tonic-gate.loop: 450Sstevel@tonic-gate decq %rdx 460Sstevel@tonic-gate je .equal / Used all n chars? 470Sstevel@tonic-gate movl (%rdi),%eax / slodb ; scab 480Sstevel@tonic-gate cmpl (%rsi),%eax 490Sstevel@tonic-gate jne .notequal_0 / Are the bytes equal? 500Sstevel@tonic-gate testl %eax,%eax 510Sstevel@tonic-gate je .equal / End of string? 520Sstevel@tonic-gate 530Sstevel@tonic-gate decq %rdx 540Sstevel@tonic-gate je .equal / Used all n chars? 550Sstevel@tonic-gate movl 4(%rdi),%eax / slodb ; scab 560Sstevel@tonic-gate cmpl 4(%rsi),%eax 570Sstevel@tonic-gate jne .notequal_1 / Are the bytes equal? 580Sstevel@tonic-gate testl %eax,%eax 590Sstevel@tonic-gate je .equal / End of string? 600Sstevel@tonic-gate 610Sstevel@tonic-gate decq %rdx 620Sstevel@tonic-gate je .equal / Used all n chars? 630Sstevel@tonic-gate movl 8(%rdi),%eax / slodb ; scab 640Sstevel@tonic-gate cmpl 8(%rsi),%eax 650Sstevel@tonic-gate jne .notequal_2 / Are the bytes equal? 660Sstevel@tonic-gate testl %eax,%eax 670Sstevel@tonic-gate je .equal / End of string? 680Sstevel@tonic-gate 690Sstevel@tonic-gate decq %rdx 700Sstevel@tonic-gate je .equal / Used all n chars? 710Sstevel@tonic-gate movl 12(%rdi),%eax / slodb ; scab 720Sstevel@tonic-gate cmpl 12(%rsi),%eax 730Sstevel@tonic-gate jne .notequal_3 / Are the bytes equal? 740Sstevel@tonic-gate addq $16,%rdi 750Sstevel@tonic-gate addq $16,%rsi 760Sstevel@tonic-gate testl %eax,%eax 770Sstevel@tonic-gate jne .loop / End of string? 780Sstevel@tonic-gate 790Sstevel@tonic-gate.equal: 800Sstevel@tonic-gate xorl %eax,%eax / return 0 810Sstevel@tonic-gate ret 820Sstevel@tonic-gate 830Sstevel@tonic-gate .align 4 840Sstevel@tonic-gate.notequal_3: 850Sstevel@tonic-gate addq $4,%rsi 860Sstevel@tonic-gate.notequal_2: 870Sstevel@tonic-gate addq $4,%rsi 880Sstevel@tonic-gate.notequal_1: 890Sstevel@tonic-gate addq $4,%rsi 900Sstevel@tonic-gate.notequal_0: 910Sstevel@tonic-gate subl (%rsi),%eax / return value is (*s1 - *--s2) 920Sstevel@tonic-gate ret 936812Sraf SET_SIZE(wcsncmp) 940Sstevel@tonic-gate 956812Sraf ENTRY(wsncmp) 966812Sraf jmp wcsncmp / tail call into wcsncmp 976812Sraf SET_SIZE(wsncmp) 98