2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / alphaev67 / stpncpy.S
blob4d61d7131706d98ec4c793cbe5ba6df784494afb
1 /* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
2    Contributed by Richard Henderson (rth@redhat.com)
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 /* Copy no more then N bytes from SRC to DEST, returning the address of
21    the terminating '\0' in DEST.  */
23 #include <sysdep.h>
25         .arch ev6
26         .set noat
27         .set noreorder
28         .text
30 ENTRY(__stpncpy)
31         ldgp    gp, 0(pv)
32 #ifdef PROF
33         lda     AT, _mcount
34         jsr     AT, (AT), _mcount
35 #endif
36         .prologue 1
38         mov     a0, v0
39         beq     a2, $zerocount
41         .align 4
42         nop
43         nop
44         jsr     t9, __stxncpy   # do the work of the copy
46         cttz    t8, t4
47         zapnot  t0, t8, t5
48         andnot  a0, 7, a0
49         bne     a2, $multiword  # do we have full words left?
51         subq    t8, 1, t2
52         subq    t10, 1, t3
53         cmpult  zero, t5, t5
54         addq    a0, t4, v0
56         or      t2, t8, t2
57         or      t3, t10, t3
58         addq    v0, t5, v0
59         andnot  t3, t2, t3
61         zap     t0, t3, t0
62         nop
63         stq     t0, 0(a0)
64         ret
66 $multiword:
67         subq    t8, 1, t7       # clear the final bits in the prev word
68         cmpult  zero, t5, t5
69         or      t7, t8, t7
70         zapnot  t0, t7, t0
72         subq    a2, 1, a2
73         stq     t0, 0(a0)
74         addq    a0, 8, a1
75         beq     a2, 1f          # loop over full words remaining
77         nop
78         nop
79         nop
80         blbc    a2, 0f
82         stq     zero, 0(a1)
83         subq    a2, 1, a2
84         addq    a1, 8, a1
85         beq     a2, 1f
87 0:      stq     zero, 0(a1)
88         subq    a2, 2, a2
89         nop
90         nop
92         stq     zero, 8(a1)
93         addq    a1, 16, a1
94         nop
95         bne     a2, 0b
97 1:      ldq     t0, 0(a1)       # clear the leading bits in the final word
98         subq    t10, 1, t7
99         addq    a0, t4, v0
100         nop
102         or      t7, t10, t7
103         addq    v0, t5, v0
104         zap     t0, t7, t0
105         stq     t0, 0(a1)
107 $zerocount:
108         nop
109         nop
110         nop
111         ret
113         END(__stpncpy)
115 libc_hidden_def (__stpncpy)
116 weak_alias (__stpncpy, stpncpy)