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 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
31 / Concatenates s2 on the end of s1. s1
's space must be large enough.
34 / Fast assembly language version of the following C-program strcat
35 / which represents the `standard' for the C-library.
38 / strcat
(char
*s1
, const char
*s2
)
45 / while
(*s1+
+ = *s2+
+)
50 / In this assembly language version
, the following expression is used
51 / to check if
a 32-bit word data contains
a null byte
or not:
52 / (((A & 0x7f7f7f7f) + 0x7f7f7f7f) |
A) & 0x80808080
53 / If the above expression geneates
a value other than
0x80808080,
54 / that means the
32-bit word data contains
a null byte.
60 pushl
%edi
/ save register variable
61 / find
a null byte in destination string
62 movl
8(%esp
), %edi
/ %edi
= destination string address
63 testl $
3, %edi
/ if
%edi
not word aligned
67 movl
(%edi
), %edx
/ move
1 word from
(%edi
) to
%edx
68 movl $
0x7f7f7f7f, %ecx
69 andl
%edx
, %ecx
/ %ecx
= %edx
& 0x7f7f7f7f
70 addl $
4, %edi
/ next word
71 addl $
0x7f7f7f7f, %ecx
/ %ecx
+= 0x7f7f7f7f
72 orl
%edx
, %ecx
/ %ecx |
= %edx
73 andl $
0x80808080, %ecx
/ %ecx
&= 0x80808080
74 cmpl $
0x80808080, %ecx
/ if no null byte in this word
76 subl $
4, %edi
/ post-incremented
78 cmpb $
0, (%edi
) / if
a byte in
(%edi
) is null
81 testl $
3, %edi
/ if
%edi
not word aligned
83 jmp
.L2 / goto .L2 (%edi word aligned)
86 / %edi points to
a null byte in destination string
87 movl
12(%esp
), %eax
/ %eax
= source string address
88 testl $
3, %eax
/ if
%eax
not word aligned
92 movl
(%eax
), %edx
/ move
1 word from
(%eax
) to
%edx
93 movl $
0x7f7f7f7f, %ecx
94 andl
%edx
, %ecx
/ %ecx
= %edx
& 0x7f7f7f7f
95 addl $
4, %eax
/ next word
96 addl $
0x7f7f7f7f, %ecx
/ %ecx
+= 0x7f7f7f7f
97 orl
%edx
, %ecx
/ %ecx |
= %edx
98 andl $
0x80808080, %ecx
/ %ecx
&= 0x80808080
99 cmpl $
0x80808080, %ecx
/ if null byte in this word
101 movl
%edx
, (%edi
) / copy this word to
(%edi
)
102 addl $
4, %edi
/ next word
105 subl $
4, %eax
/ post-incremented
108 movb
(%eax
), %dl
/ %dl
= a byte in
(%eax
)
109 cmpb $
0, %dl
/ compare
%dl with
a null byte
110 movb
%dl
, (%edi
) / copy
%dl to
(%edi
)
111 je
.L6 / if %dl is a null, goto .L6
112 incl
%eax
/ next byte
113 incl
%edi
/ next byte
114 testl $
3, %eax
/ if
%eax
not word aligned
116 jmp
.L5 / goto .L5 (%eax word aligned)
119 movl
8(%esp
), %eax
/ return the destination address
120 popl
%edi
/ restore register variable