]>
Commit | Line | Data |
---|---|---|
ffeac417 UD |
1 | /* strncpy - copy at most n characters from a string from source to |
2 | destination. 64 bit S/390 version | |
04277e02 | 3 | Copyright (C) 2001-2019 Free Software Foundation, Inc. |
ffeac417 UD |
4 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). |
5 | This file is part of the GNU C Library. | |
6 | ||
7 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
8 | modify it under the terms of the GNU Lesser General Public |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
ffeac417 UD |
11 | |
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 15 | Lesser General Public License for more details. |
ffeac417 | 16 | |
41bdb6e2 | 17 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 18 | License along with the GNU C Library; if not, see |
5a82c748 | 19 | <https://www.gnu.org/licenses/>. */ |
ffeac417 UD |
20 | |
21 | /* INPUT PARAMETERS | |
22 | %r2 = address of destination (dst) | |
23 | %r3 = address of source (src) | |
24 | %r4 = max of bytes to copy. */ | |
25 | ||
d1bdbf38 | 26 | #include <ifunc-strncpy.h> |
ffeac417 UD |
27 | #include "sysdep.h" |
28 | #include "asm-syntax.h" | |
29 | ||
d1bdbf38 SL |
30 | #if HAVE_STRNCPY_Z900_G5 |
31 | ENTRY(STRNCPY_Z900_G5) | |
ffeac417 UD |
32 | .text |
33 | stg %r2,48(%r15) # save dst pointer | |
34 | slgr %r2,%r3 # %r3 points to src, %r2+%r3 to dst | |
35 | lghi %r1,7 | |
36 | ngr %r1,%r4 # last 3 bits of # bytes | |
37 | srlg %r4,%r4,3 | |
38 | ltgr %r4,%r4 # less than 8 bytes to copy ? | |
39 | jz .L1 | |
40 | bras %r5,.L0 # enter loop & load address of a 0 | |
41 | .long 0 | |
42 | .L0: icmh %r0,8,0(%r3) # first byte | |
43 | jz .L3 | |
44 | icmh %r0,4,1(%r3) # second byte | |
45 | jz .L4 | |
46 | icmh %r0,2,2(%r3) # third byte | |
47 | jz .L5 | |
48 | icmh %r0,1,3(%r3) # fourth byte | |
49 | jz .L6 | |
50 | icm %r0,8,4(%r3) # fifth byte | |
51 | jz .L7 | |
52 | icm %r0,4,5(%r3) # sixth byte | |
53 | jz .L8 | |
54 | icm %r0,2,6(%r3) # seventh byte | |
55 | jz .L9 | |
56 | icm %r0,1,7(%r3) # eigth byte | |
57 | jz .L10 | |
58 | stg %r0,0(%r2,%r3) # store all eight to dest. | |
59 | la %r3,8(%r3) | |
60 | brct %r4,.L0 | |
61 | .L1: ltgr %r1,%r1 | |
62 | jz .Lexit | |
63 | .L2: icm %r0,1,0(%r3) | |
64 | stc %r0,0(%r2,%r3) | |
65 | la %r3,1(%r3) | |
66 | jz .L11 | |
67 | brct %r1,.L2 | |
68 | j .Lexit | |
69 | .L3: icmh %r0,4,0(%r5) | |
70 | .L4: icmh %r0,2,0(%r5) | |
71 | .L5: icmh %r0,1,0(%r5) | |
72 | .L6: icm %r0,8,0(%r5) | |
73 | .L7: icm %r0,4,0(%r5) | |
74 | .L8: icm %r0,2,0(%r5) | |
75 | .L9: icm %r0,1,0(%r5) | |
76 | .L10: stg %r0,0(%r2,%r3) | |
77 | la %r3,8(%r3) | |
78 | aghi %r4,-1 | |
79 | j .L12 | |
80 | .L11: aghi %r1,-1 | |
81 | .L12: sllg %r4,%r4,3 | |
82 | algr %r4,%r1 | |
83 | algr %r2,%r3 # start of dst area to be zeroed | |
84 | lgr %r3,%r4 | |
85 | slgr %r4,%r4 | |
86 | slgr %r5,%r5 | |
87 | .L13: mvcle %r2,%r4,0 # pad dst with zeroes | |
88 | jo .L13 | |
89 | .Lexit: lg %r2,48(%r15) # return dst pointer | |
90 | br %r14 | |
d1bdbf38 SL |
91 | END(STRNCPY_Z900_G5) |
92 | ||
93 | # if ! HAVE_STRNCPY_IFUNC | |
94 | strong_alias (STRNCPY_Z900_G5, strncpy) | |
95 | # endif | |
96 | ||
97 | # if defined SHARED && IS_IN (libc) | |
98 | strong_alias (STRNCPY_Z900_G5, __GI_strncpy) | |
99 | # endif | |
100 | #endif |