4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
31 / Copies string s2 to s1. s1 must
be large enough.
35 / Fast assembly language version of the following C-program strcpy
36 / which represents the `standard
' for the C-library.
39 / strcpy(char *s1, const char *s2)
43 / while (*s1++ = *s2++)
48 / In this assembly language version, the following expression is used
49 / to check if a 32-bit word data contains a null byte or not:
50 / (((A & 0x7f7f7f7f) + 0x7f7f7f7f) | A) & 0x80808080
51 / If the above expression geneates a value other than 0x80808080,
52 / that means the 32-bit word data contains a null byte.
58 push %edi / save reg as per calling cvntn
59 mov 12(%esp), %ecx / src ptr
60 mov 8(%esp), %edi / dst ptr
62 sub %edi, %ecx / src - dst
63 and $3, %eax / check src alignment
68 movb (%edi, %ecx, 1), %dl / load src byte
69 movb %dl, (%edi) / load dest byte
70 inc %edi / increment src and dest
71 testb %dl, %dl / is src zero?
73 inc %eax / check src alignment
78 mov %eax, (%edi) / store word
79 add $4, %edi / incrment src and dest by 4
81 mov (%edi, %ecx, 1), %eax / load word
82 lea -0x01010101(%eax), %edx / (word - 0x01010101)
84 and %eax, %edx / (word - 0x01010101) & ~word
86 and $0x80808080, %edx / (wd - 0x01010101) & ~wd & 0x80808080
87 jz store / store word w/o zero byte
90 movb %al, (%edi) / store first byte
91 testb %al, %al / check first byte for zero
93 movb %ah, 1(%edi) / continue storing and checking
96 shr $16, %eax / grab last two bytes
102 mov 8(%esp), %eax / return ptr to dest
103 pop %edi / restore as per calling cvntn