]>
Commit | Line | Data |
---|---|---|
847b055c AJ |
1 | /* strncpy - copy at most n characters from a string from source to |
2 | destination. For IBM S390 | |
3 | This file is part of the GNU C Library. | |
04277e02 | 4 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
847b055c AJ |
5 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). |
6 | ||
41bdb6e2 AJ |
7 | The GNU C Library is free software; you can redistribute it and/or |
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. | |
847b055c AJ |
11 | |
12 | The GNU C Library is distributed in the hope that it will be useful, | |
41bdb6e2 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
847b055c | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
41bdb6e2 | 15 | Lesser General Public License for more details. |
847b055c | 16 | |
41bdb6e2 | 17 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
18 | License along with the GNU C Library; if not, see |
19 | <http://www.gnu.org/licenses/>. */ | |
847b055c AJ |
20 | |
21 | /* | |
22 | * R2 = address of destination (dst) | |
23 | * R3 = address of source (src) | |
24 | * R4 = max of bytes to copy | |
25 | */ | |
26 | ||
d1bdbf38 | 27 | #include <ifunc-strncpy.h> |
847b055c AJ |
28 | #include "sysdep.h" |
29 | #include "asm-syntax.h" | |
30 | ||
d1bdbf38 SL |
31 | #if HAVE_STRNCPY_Z900_G5 |
32 | ENTRY(STRNCPY_Z900_G5) | |
847b055c AJ |
33 | .text |
34 | st %r2,24(%r15) # save dst pointer | |
35 | slr %r2,%r3 # %r3 points to src, %r2+%r3 to dst | |
36 | lhi %r1,3 | |
37 | nr %r1,%r4 # last 2 bits of # bytes | |
38 | srl %r4,2 | |
39 | ltr %r4,%r4 # less than 4 bytes to copy ? | |
40 | jz .L1 | |
41 | bras %r5,.L0 # enter loop & load address of a 0 | |
42 | .long 0 | |
43 | .L0: icm %r0,8,0(%r3) # first byte | |
44 | jz .L3 | |
45 | icm %r0,4,1(%r3) # second byte | |
46 | jz .L4 | |
47 | icm %r0,2,2(%r3) # third byte | |
48 | jz .L5 | |
49 | icm %r0,1,3(%r3) # fourth byte | |
50 | jz .L6 | |
51 | st %r0,0(%r2,%r3) # store all four to dest. | |
52 | la %r3,4(%r3) | |
53 | brct %r4,.L0 | |
54 | .L1: ltr %r1,%r1 | |
55 | jz .Lexit | |
56 | .L2: icm %r0,1,0(%r3) | |
57 | stc %r0,0(%r2,%r3) | |
58 | la %r3,1(%r3) | |
59 | jz .L7 | |
60 | brct %r1,.L2 | |
61 | j .Lexit | |
62 | .L3: icm %r0,4,0(%r5) | |
63 | .L4: icm %r0,2,0(%r5) | |
64 | .L5: icm %r0,1,0(%r5) | |
65 | .L6: st %r0,0(%r2,%r3) | |
66 | la %r3,4(%r3) | |
67 | ahi %r4,-1 | |
68 | j .L8 | |
69 | .L7: ahi %r1,-1 | |
70 | .L8: sll %r4,2 | |
71 | alr %r4,%r1 | |
72 | alr %r2,%r3 # start of dst area to be zeroed | |
73 | lr %r3,%r4 | |
74 | slr %r4,%r4 | |
75 | slr %r5,%r5 | |
76 | .L9: mvcle %r2,%r4,0 # pad dst with zeroes | |
77 | jo .L9 | |
78 | .Lexit: l %r2,24(%r15) # return dst pointer | |
79 | br %r14 | |
d1bdbf38 SL |
80 | END(STRNCPY_Z900_G5) |
81 | ||
82 | # if ! HAVE_STRNCPY_IFUNC | |
83 | strong_alias (STRNCPY_Z900_G5, strncpy) | |
84 | # endif | |
85 | ||
86 | # if defined SHARED && IS_IN (libc) | |
87 | strong_alias (STRNCPY_Z900_G5, __GI_strncpy) | |
88 | # endif | |
89 | #endif |