xref: /titanic_51/usr/src/lib/libc/sparc/gen/strncpy.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	"strncpy.s"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate/*
307c478bd9Sstevel@tonic-gate * strncpy(s1, s2)
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * Copy string s2 to s1, truncating or null-padding to always copy n bytes
337c478bd9Sstevel@tonic-gate * return s1.
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * Fast assembler language version of the following C-program for strncpy
367c478bd9Sstevel@tonic-gate * which represents the `standard' for the C-library.
377c478bd9Sstevel@tonic-gate *
387c478bd9Sstevel@tonic-gate *	char *
397c478bd9Sstevel@tonic-gate *	strncpy(char *s1, const char *s2, size_t n)
407c478bd9Sstevel@tonic-gate *	{
417c478bd9Sstevel@tonic-gate *		char *os1 = s1;
427c478bd9Sstevel@tonic-gate *
437c478bd9Sstevel@tonic-gate *		n++;
447c478bd9Sstevel@tonic-gate *		while ((--n != 0) &&  ((*s1++ = *s2++) != '\0'))
457c478bd9Sstevel@tonic-gate *			;
467c478bd9Sstevel@tonic-gate *		if (n != 0)
477c478bd9Sstevel@tonic-gate *			while (--n != 0)
487c478bd9Sstevel@tonic-gate *				*s1++ = '\0';
497c478bd9Sstevel@tonic-gate *		return (os1);
507c478bd9Sstevel@tonic-gate *	}
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate	! strncpy works similarly to strcpy, except that n bytes of s2
567c478bd9Sstevel@tonic-gate	! are copied to s1. If a null character is reached in s2 yet more
577c478bd9Sstevel@tonic-gate	! bytes remain to be copied, strncpy will copy null bytes into
587c478bd9Sstevel@tonic-gate	! the destination string.
597c478bd9Sstevel@tonic-gate	!
607c478bd9Sstevel@tonic-gate	! This implementation works by first aligning the src ptr and
617c478bd9Sstevel@tonic-gate	! performing small copies until it is aligned.  Then, the string
627c478bd9Sstevel@tonic-gate	! is copied based upon destination alignment.  (byte, half-word,
637c478bd9Sstevel@tonic-gate	! word, etc.)
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate	ENTRY(strncpy)
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate	.align 32
687c478bd9Sstevel@tonic-gate	subcc	%g0, %o2, %o4		! n = -n
697c478bd9Sstevel@tonic-gate	bz	.doneshort		! if n == 0, done
707c478bd9Sstevel@tonic-gate	cmp	%o2, 7			! n < 7 ?
717c478bd9Sstevel@tonic-gate	add	%o1, %o2, %o3		! src = src + n
727c478bd9Sstevel@tonic-gate	blu	.shortcpy		! n < 7, use byte-wise copy
737c478bd9Sstevel@tonic-gate	add	%o0, %o2, %o2		! dst = dst + n
747c478bd9Sstevel@tonic-gate	andcc	%o1, 3, %o5		! src word aligned ?
757c478bd9Sstevel@tonic-gate	bz	.wordaligned		! yup
767c478bd9Sstevel@tonic-gate	save	%sp, -0x40, %sp		! create new register window
777c478bd9Sstevel@tonic-gate	sub	%i5, 4, %i5		! bytes until src aligned
787c478bd9Sstevel@tonic-gate	nop				! align loop on 16-byte boundary
797c478bd9Sstevel@tonic-gate	nop				! align loop on 16-byte boundary
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate.alignsrc:
827c478bd9Sstevel@tonic-gate	ldub	[%i3 + %i4], %i1	! src[]
837c478bd9Sstevel@tonic-gate	stb	%i1, [%i2 + %i4]	! dst[] = src[]
847c478bd9Sstevel@tonic-gate	inccc	%i4			! src++, dst++, n--
857c478bd9Sstevel@tonic-gate	bz	.done			! n == 0, done
867c478bd9Sstevel@tonic-gate	tst     %i1			! end of src reached (null byte) ?
877c478bd9Sstevel@tonic-gate	bz,a	.bytepad		! yes, at least one byte to pad here
887c478bd9Sstevel@tonic-gate	add 	%i2, %i4, %l0		! need single dest pointer for fill
897c478bd9Sstevel@tonic-gate	inccc	%i5			! src aligned now?
907c478bd9Sstevel@tonic-gate	bnz	.alignsrc		! no, copy another byte
917c478bd9Sstevel@tonic-gate	.empty
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate.wordaligned:
947c478bd9Sstevel@tonic-gate	add	%i2, %i4, %l0		! dst
957c478bd9Sstevel@tonic-gate	sethi	%hi(0x01010101), %l1	! Alan Mycroft's magic1
967c478bd9Sstevel@tonic-gate	sub	%i2, 4, %i2		! adjust for dest pre-incr in cpy loops
977c478bd9Sstevel@tonic-gate	or	%l1, %lo(0x01010101),%l1!  finish loading magic1
987c478bd9Sstevel@tonic-gate	andcc	%l0, 3, %g1		! destination word aligned ?
997c478bd9Sstevel@tonic-gate	bnz	.dstnotaligned		! nope
1007c478bd9Sstevel@tonic-gate	sll	%l1, 7, %i5		! create Alan Mycroft's magic2
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate.storeword:
1037c478bd9Sstevel@tonic-gate	lduw	[%i3 + %i4], %i1	! src dword
1047c478bd9Sstevel@tonic-gate	addcc	%i4, 4, %i4		! n += 4, src += 4, dst += 4
1057c478bd9Sstevel@tonic-gate	bcs	.lastword		! if counter wraps, last word
1067c478bd9Sstevel@tonic-gate	andn	%i5, %i1, %g1		! ~dword & 0x80808080
1077c478bd9Sstevel@tonic-gate	sub	%i1, %l1, %l0		! dword - 0x01010101
1087c478bd9Sstevel@tonic-gate	andcc	%l0, %g1, %g0		! ((dword - 0x01010101) & ~dword & 0x80808080)
1097c478bd9Sstevel@tonic-gate	bz,a	.storeword		! no zero byte if magic expression == 0
1107c478bd9Sstevel@tonic-gate	stw	%i1, [%i2 + %i4]	! store word to dst (address pre-incremented)
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate	! n has not expired, but src is at the end. we need to push out the
1137c478bd9Sstevel@tonic-gate	! remaining src bytes and then start padding with null bytes
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate.zerobyte:
1167c478bd9Sstevel@tonic-gate	add	%i2, %i4, %l0		! pointer to dest string
1177c478bd9Sstevel@tonic-gate	srl	%i1, 24, %g1		! first byte
1187c478bd9Sstevel@tonic-gate	stb	%g1, [%l0]		! store it
1197c478bd9Sstevel@tonic-gate	sub	%g1, 1, %g1		! byte == 0 ? -1 : byte - 1
1207c478bd9Sstevel@tonic-gate	sra	%g1, 31, %g1		! byte == 0 ? -1 : 0
1217c478bd9Sstevel@tonic-gate	andn	%i1, %g1, %i1		! if byte == 0, start padding with null bytes
1227c478bd9Sstevel@tonic-gate	srl	%i1, 16, %g1		! second byte
1237c478bd9Sstevel@tonic-gate	stb	%g1, [%l0 + 1]		! store it
1247c478bd9Sstevel@tonic-gate	and	%g1, 0xff, %g1		! isolate byte
1257c478bd9Sstevel@tonic-gate	sub	%g1, 1, %g1		! byte == 0 ? -1 : byte - 1
1267c478bd9Sstevel@tonic-gate	sra	%g1, 31, %g1		! byte == 0 ? -1 : 0
1277c478bd9Sstevel@tonic-gate	andn	%i1, %g1, %i1		! if byte == 0, start padding with null bytes
1287c478bd9Sstevel@tonic-gate	srl	%i1, 8, %g1		! third byte
1297c478bd9Sstevel@tonic-gate	stb	%g1, [%l0 + 2]		! store it
1307c478bd9Sstevel@tonic-gate	and	%g1, 0xff, %g1		! isolate byte
1317c478bd9Sstevel@tonic-gate	sub	%g1, 1, %g1		! byte == 0 ? -1 : byte - 1
1327c478bd9Sstevel@tonic-gate	sra	%g1, 31, %g1		! byte == 0 ? -1 : 0
1337c478bd9Sstevel@tonic-gate	andn	%i1, %g1, %i1		! if byte == 0, start padding with null bytes
1347c478bd9Sstevel@tonic-gate	stb	%i1, [%l0 + 3]		! store fourth byte
1357c478bd9Sstevel@tonic-gate	addcc	%i4, 8, %g0		! number of pad bytes < 8 ?
1367c478bd9Sstevel@tonic-gate	bcs	.bytepad		! yes, do simple byte wise fill
1377c478bd9Sstevel@tonic-gate	add	%l0, 4, %l0		! dst += 4
1387c478bd9Sstevel@tonic-gate	andcc	%l0, 3, %l1		! dst offset relative to word boundary
1397c478bd9Sstevel@tonic-gate	bz	.fillaligned		! dst already word aligned
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate	! here there is a least one more byte to zero out: otherwise we would
1427c478bd9Sstevel@tonic-gate	! have exited through label .lastword
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate	sub	%l1, 4, %l1		! bytes to align dst to word boundary
1457c478bd9Sstevel@tonic-gate.makealigned:
1467c478bd9Sstevel@tonic-gate	stb	%g0, [%l0]		! dst[] = 0
1477c478bd9Sstevel@tonic-gate	addcc	%i4, 1, %i4		! n--
1487c478bd9Sstevel@tonic-gate	bz	.done			! n == 0, we are done
1497c478bd9Sstevel@tonic-gate	addcc	%l1, 1, %l1		! any more byte needed to align
1507c478bd9Sstevel@tonic-gate	bnz	.makealigned		! yup, pad another byte
1517c478bd9Sstevel@tonic-gate	add	%l0, 1, %l0		! dst++
1527c478bd9Sstevel@tonic-gate	nop				! pad to align copy loop below
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate	! here we know that there at least another 4 bytes to pad, since
1557c478bd9Sstevel@tonic-gate	! we don't get here unless there were >= 8 bytes to pad to begin
1567c478bd9Sstevel@tonic-gate	! with, and we have padded at most 3 bytes suring dst aligning
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate.fillaligned:
1597c478bd9Sstevel@tonic-gate	add	%i4, 3, %i2		! round up to next word boundary
1607c478bd9Sstevel@tonic-gate	and	%i2, -4, %l1		! pointer to next word boundary
1617c478bd9Sstevel@tonic-gate	and	%i2, 4, %i2		! word count odd ? 4 : 0
1627c478bd9Sstevel@tonic-gate	stw	%g0, [%l0]		! store first word
1637c478bd9Sstevel@tonic-gate	addcc	%l1, %i2, %l1		! dword count == 1 ?
1647c478bd9Sstevel@tonic-gate	add	%i4, %i2, %i4		! if word count odd, n -= 4
1657c478bd9Sstevel@tonic-gate	bz	.bytepad		! if word count == 1, pad bytes left
1667c478bd9Sstevel@tonic-gate	add	%l0, %i2, %l0		! bump dst if word count odd
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate.fillword:
1697c478bd9Sstevel@tonic-gate	addcc	%l1, 8, %l1		! count -= 8
1707c478bd9Sstevel@tonic-gate	stw	%g0, [%l0]		! dst[n] = 0
1717c478bd9Sstevel@tonic-gate	stw	%g0, [%l0 + 4]		! dst[n+4] = 0
1727c478bd9Sstevel@tonic-gate	add	%l0, 8, %l0		! dst += 8
1737c478bd9Sstevel@tonic-gate	bcc	.fillword		! fill words until count == 0
1747c478bd9Sstevel@tonic-gate	addcc	%i4, 8, %i4		! n -= 8
1757c478bd9Sstevel@tonic-gate	bz	.done			! if n == 0, we are done
1767c478bd9Sstevel@tonic-gate	.empty
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate.bytepad:
1797c478bd9Sstevel@tonic-gate	and	%i4, 1, %i2		! byte count odd ? 1 : 0
1807c478bd9Sstevel@tonic-gate	stb	%g0, [%l0]		! store first byte
1817c478bd9Sstevel@tonic-gate	addcc	%i4, %i2, %i4		! byte count == 1 ?
1827c478bd9Sstevel@tonic-gate	bz	.done			! yup, we are done
1837c478bd9Sstevel@tonic-gate	add	%l0, %i2, %l0		! bump pointer if odd
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate.fillbyte:
1867c478bd9Sstevel@tonic-gate	addcc	%i4, 2, %i4		! n -= 2
1877c478bd9Sstevel@tonic-gate	stb	%g0, [%l0]		! dst[n] = 0
1887c478bd9Sstevel@tonic-gate	stb	%g0, [%l0 + 1]		! dst[n+1] = 0
1897c478bd9Sstevel@tonic-gate	bnz	.fillbyte		! fill until n == 0
1907c478bd9Sstevel@tonic-gate	add	%l0, 2, %l0		! dst += 2
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate.done:
1937c478bd9Sstevel@tonic-gate	ret				! done
1947c478bd9Sstevel@tonic-gate	restore	%i0, %g0, %o0		! restore reg window, return dst
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate	! this is the last word. It may contain null bytes. store bytes
1977c478bd9Sstevel@tonic-gate	! until n == 0. if null byte encountered, continue
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate.lastword:
2007c478bd9Sstevel@tonic-gate	sub	%i4, 4, %i4		! undo counter pre-increment
2017c478bd9Sstevel@tonic-gate	add	%i2, 4, %i2		! adjust dst for counter un-bumping
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate	srl	%i1, 24, %g1		! first byte
2047c478bd9Sstevel@tonic-gate	stb	%g1, [%i2 + %i4]	! store it
2057c478bd9Sstevel@tonic-gate	inccc	%i4			! n--
2067c478bd9Sstevel@tonic-gate	bz	.done			! if n == 0, we're done
2077c478bd9Sstevel@tonic-gate	sub	%g1, 1, %g1		! byte == 0 ? -1 : byte - 1
2087c478bd9Sstevel@tonic-gate	sra	%g1, 31, %g1		! byte == 0 ? -1 : 0
2097c478bd9Sstevel@tonic-gate	andn	%i1, %g1, %i1		! if byte == 0, start padding with null
2107c478bd9Sstevel@tonic-gate	srl	%i1, 16, %g1		! second byte
2117c478bd9Sstevel@tonic-gate	stb	%g1, [%i2 + %i4]	! store it
2127c478bd9Sstevel@tonic-gate	inccc	%i4			! n--
2137c478bd9Sstevel@tonic-gate	bz	.done			! if n == 0, we're done
2147c478bd9Sstevel@tonic-gate	and	%g1, 0xff, %g1		! isolate byte
2157c478bd9Sstevel@tonic-gate	sub	%g1, 1, %g1		! byte == 0 ? -1 : byte - 1
2167c478bd9Sstevel@tonic-gate	sra	%g1, 31, %g1		! byte == 0 ? -1 : 0
2177c478bd9Sstevel@tonic-gate	andn	%i1, %g1, %i1		! if byte == 0, start padding with null
2187c478bd9Sstevel@tonic-gate	srl	%i1, 8, %g1		! third byte
2197c478bd9Sstevel@tonic-gate	stb	%g1, [%i2 + %i4]	! store it
2207c478bd9Sstevel@tonic-gate	inccc	%i4			! n--
2217c478bd9Sstevel@tonic-gate	bz	.done			! if n == 0, we're done
2227c478bd9Sstevel@tonic-gate	and	%g1, 0xff, %g1		! isolate byte
2237c478bd9Sstevel@tonic-gate	sub	%g1, 1, %g1		! byte == 0 ? -1 : byte - 1
2247c478bd9Sstevel@tonic-gate	sra	%g1, 31, %g1		! byte == 0 ? -1 : 0
2257c478bd9Sstevel@tonic-gate	andn	%i1, %g1, %i1		! if byte == 0, start padding with null
2267c478bd9Sstevel@tonic-gate	ba	.done			! here n must be zero, we are done
2277c478bd9Sstevel@tonic-gate	stb	%i1, [%i2 + %i4]	! store fourth byte
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate.dstnotaligned:
2307c478bd9Sstevel@tonic-gate	cmp	%g1, 2			! dst half word aligned?
2317c478bd9Sstevel@tonic-gate	be	.storehalfword2		! yup, store half word at a time
2327c478bd9Sstevel@tonic-gate	.empty
2337c478bd9Sstevel@tonic-gate.storebyte:
2347c478bd9Sstevel@tonic-gate	lduw	[%i3 + %i4], %i1	! x = src[]
2357c478bd9Sstevel@tonic-gate	addcc	%i4, 4, %i4		! src += 4, dst += 4, n -= 4
2367c478bd9Sstevel@tonic-gate	bcs	.lastword		! if counter wraps, last word
2377c478bd9Sstevel@tonic-gate	andn	%i5, %i1, %g1		! ~x & 0x80808080
2387c478bd9Sstevel@tonic-gate	sub	%i1, %l1, %l0		! x - 0x01010101
2397c478bd9Sstevel@tonic-gate	andcc	%l0, %g1, %g0		! ((x - 0x01010101) & ~x & 0x80808080)
2407c478bd9Sstevel@tonic-gate	bnz	.zerobyte		! end of src found, may need to pad
2417c478bd9Sstevel@tonic-gate	add	%i2, %i4, %l0		! dst (in pointer form)
2427c478bd9Sstevel@tonic-gate	srl	%i1, 24, %g1		! %g1<7:0> = 1st byte; half-word aligned now
2437c478bd9Sstevel@tonic-gate	stb	%g1, [%l0]		! store first byte
2447c478bd9Sstevel@tonic-gate	srl	%i1, 8, %g1		! %g1<15:0> = bytes 2, 3
2457c478bd9Sstevel@tonic-gate	sth	%g1, [%l0 + 1]		! store bytes 2, 3
2467c478bd9Sstevel@tonic-gate	ba	.storebyte		! next word
2477c478bd9Sstevel@tonic-gate	stb	%i1, [%l0 + 3]		! store fourth byte
2487c478bd9Sstevel@tonic-gate	nop
2497c478bd9Sstevel@tonic-gate	nop
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate.storehalfword:
2527c478bd9Sstevel@tonic-gate	lduw	[%i3 + %i4], %i1	! x = src[]
2537c478bd9Sstevel@tonic-gate.storehalfword2:
2547c478bd9Sstevel@tonic-gate	addcc	%i4, 4, %i4		! src += 4, dst += 4, n -= 4
2557c478bd9Sstevel@tonic-gate	bcs	.lastword		! if counter wraps, last word
2567c478bd9Sstevel@tonic-gate	andn	%i5, %i1, %g1		! ~x & 0x80808080
2577c478bd9Sstevel@tonic-gate	sub	%i1, %l1, %l0		! x - 0x01010101
2587c478bd9Sstevel@tonic-gate	andcc	%l0, %g1, %g0		! ((x -0x01010101) & ~x & 0x8080808080)
2597c478bd9Sstevel@tonic-gate	bnz	.zerobyte		! x has zero byte, handle end cases
2607c478bd9Sstevel@tonic-gate	add	%i2, %i4, %l0		! dst (in pointer form)
2617c478bd9Sstevel@tonic-gate	srl	%i1, 16, %g1		! %g1<15:0> = bytes 1, 2
2627c478bd9Sstevel@tonic-gate	sth	%g1, [%l0]		! store bytes 1, 2
2637c478bd9Sstevel@tonic-gate	ba	.storehalfword		! next dword
2647c478bd9Sstevel@tonic-gate	sth	%i1, [%l0 + 2]		! store bytes 3, 4
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate.shortcpy:
2677c478bd9Sstevel@tonic-gate	ldub	[%o3 + %o4], %o5	! src[]
2687c478bd9Sstevel@tonic-gate	stb	%o5, [%o2 + %o4]	! dst[] = src[]
2697c478bd9Sstevel@tonic-gate	inccc	%o4			! src++, dst++, n--
2707c478bd9Sstevel@tonic-gate	bz	.doneshort		! if n == 0, done
2717c478bd9Sstevel@tonic-gate	tst	%o5			! src[] == 0 ?
2727c478bd9Sstevel@tonic-gate	bnz,a	.shortcpy		! nope, next byte
2737c478bd9Sstevel@tonic-gate	nop				! empty delay slot
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate.padbyte:
2767c478bd9Sstevel@tonic-gate	stb	%g0, [%o2 + %o4]	! dst[] = 0
2777c478bd9Sstevel@tonic-gate.padbyte2:
2787c478bd9Sstevel@tonic-gate	addcc	%o4, 1, %o4		! dst++, n--
2797c478bd9Sstevel@tonic-gate	bnz,a	.padbyte2		! if n != 0, next byte
2807c478bd9Sstevel@tonic-gate	stb	%g0, [%o2 + %o4]	! dst[] = 0
2817c478bd9Sstevel@tonic-gate	nop				! align label below to 16-byte boundary
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate.doneshort:
2847c478bd9Sstevel@tonic-gate	retl				! return from leaf
2857c478bd9Sstevel@tonic-gate	nop				! empty delay slot
2867c478bd9Sstevel@tonic-gate	SET_SIZE(strncpy)
287