2.9
[glibc/nacl-glibc.git] / sysdeps / s390 / s390-64 / strncpy.S
blobcc6986fb402bad8384944c66a25a246fc9b6b432
1 /* strncpy - copy at most n characters from a string from source to
2    destination.  64 bit S/390 version
3    Copyright (C) 2001, 2003 Free Software Foundation, Inc.
4    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5    This file is part of the GNU C Library.
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.
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
15    Lesser General Public License for more details.
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, write to the Free
19    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20    02111-1307 USA.  */
22 /* INPUT PARAMETERS
23      %r2 = address of destination (dst)
24      %r3 = address of source (src)
25      %r4 = max of bytes to copy.  */
27 #include "sysdep.h"
28 #include "asm-syntax.h"
30 ENTRY(strncpy)
31         .text
32         stg   %r2,48(%r15)          # save dst pointer
33         slgr  %r2,%r3               # %r3 points to src, %r2+%r3 to dst
34         lghi  %r1,7
35         ngr   %r1,%r4               # last 3 bits of # bytes
36         srlg  %r4,%r4,3
37         ltgr  %r4,%r4               # less than 8 bytes to copy ?
38         jz    .L1
39         bras  %r5,.L0               # enter loop & load address of a 0
40         .long 0
41 .L0:    icmh  %r0,8,0(%r3)          # first byte
42         jz    .L3
43         icmh  %r0,4,1(%r3)          # second byte
44         jz    .L4
45         icmh  %r0,2,2(%r3)          # third byte
46         jz    .L5
47         icmh  %r0,1,3(%r3)          # fourth byte
48         jz    .L6
49         icm   %r0,8,4(%r3)          # fifth byte
50         jz    .L7
51         icm   %r0,4,5(%r3)          # sixth byte
52         jz    .L8
53         icm   %r0,2,6(%r3)          # seventh byte
54         jz    .L9
55         icm   %r0,1,7(%r3)          # eigth byte
56         jz    .L10
57         stg   %r0,0(%r2,%r3)        # store all eight to dest.
58         la    %r3,8(%r3)
59         brct  %r4,.L0
60 .L1:    ltgr  %r1,%r1
61         jz    .Lexit
62 .L2:    icm   %r0,1,0(%r3)
63         stc   %r0,0(%r2,%r3)
64         la    %r3,1(%r3)
65         jz    .L11
66         brct  %r1,.L2
67         j     .Lexit
68 .L3:    icmh  %r0,4,0(%r5)
69 .L4:    icmh  %r0,2,0(%r5)
70 .L5:    icmh  %r0,1,0(%r5)
71 .L6:    icm   %r0,8,0(%r5)
72 .L7:    icm   %r0,4,0(%r5)
73 .L8:    icm   %r0,2,0(%r5)
74 .L9:    icm   %r0,1,0(%r5)
75 .L10:   stg   %r0,0(%r2,%r3)
76         la    %r3,8(%r3)
77         aghi  %r4,-1
78         j     .L12
79 .L11:   aghi  %r1,-1
80 .L12:   sllg  %r4,%r4,3
81         algr  %r4,%r1
82         algr  %r2,%r3               # start of dst area to be zeroed
83         lgr   %r3,%r4
84         slgr  %r4,%r4
85         slgr  %r5,%r5
86 .L13:   mvcle %r2,%r4,0             # pad dst with zeroes
87         jo    .L13
88 .Lexit: lg    %r2,48(%r15)          # return dst pointer
89         br    %r14
90 END(strncpy)
91 libc_hidden_builtin_def (strncpy)