1 /* strncpy - copy at most n characters from a string from source to
2 destination. 64 bit S/390 version
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
21 %r2 = address of destination (dst)
22 %r3 = address of source (src)
23 %r4 = max of bytes to copy. */
25 #include <ifunc-strncpy.h>
27 #include "asm-syntax.h"
29 #if HAVE_STRNCPY_Z900_G5
30 ENTRY(STRNCPY_Z900_G5)
32 stg %r2,48(%r15) # save dst pointer
33 slgr %r2,%r3 # %r3 points to src, %r2+%r3 to dst
35 ngr %r1,%r4 # last 3 bits of # bytes
37 ltgr %r4,%r4 # less than 8 bytes to copy ?
39 bras %r5,.L0 # enter loop & load address of a 0
41 .L0: icmh %r0,8,0(%r3) # first byte
43 icmh %r0,4,1(%r3) # second byte
45 icmh %r0,2,2(%r3) # third byte
47 icmh %r0,1,3(%r3) # fourth byte
49 icm %r0,8,4(%r3) # fifth byte
51 icm %r0,4,5(%r3) # sixth byte
53 icm %r0,2,6(%r3) # seventh byte
55 icm %r0,1,7(%r3) # eighth byte
57 stg %r0,0(%r2,%r3) # store all eight to dest.
68 .L3: icmh %r0,4,0(%r5)
69 .L4: icmh %r0,2,0(%r5)
70 .L5: icmh %r0,1,0(%r5)
75 .L10: stg %r0,0(%r2,%r3)
82 algr %r2,%r3 # start of dst area to be zeroed
86 .L13: mvcle %r2,%r4,0 # pad dst with zeroes
88 .Lexit: lg %r2,48(%r15) # return dst pointer
92 # if ! HAVE_STRNCPY_IFUNC
93 strong_alias (STRNCPY_Z900_G5, strncpy)
96 # if defined SHARED && IS_IN (libc)
97 strong_alias (STRNCPY_Z900_G5, __GI_strncpy)