2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / strncpy.S
blob5d3e72e280067c0ef3e339088fcad0059f46cfe5
1 /* Copyright (C) 1996, 1997, 2003 Free Software Foundation, Inc.
2    Contributed by Richard Henderson (rth@tamu.edu)
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 than COUNT bytes of the null-terminated string from
21    SRC to DST.  If SRC does not cover all of COUNT, the balance is
22    zeroed.  */
24 #include <sysdep.h>
26         .set noat
27         .set noreorder
29         .text
31 ENTRY(strncpy)
32         ldgp    gp, 0(pv)
33 #ifdef PROF
34         lda     AT, _mcount
35         jsr     AT, (AT), _mcount
36 #endif
37         .prologue 1
39         mov     a0, v0          # set return value now
40         beq     a2, $zerocount
41         jsr     t9, __stxncpy   # do the work of the copy
43         bne     a2, $multiword  # do we have full words left?
45         .align 3
46         subq    t8, 1, t2       # e0    : guess not
47         subq    t10, 1, t3      # .. e1 :
48         or      t2, t8, t2      # e0    : clear the bits between the last
49         or      t3, t10, t3     # .. e1 : written byte and the last byte in
50         andnot  t3, t2, t3      # e0    : COUNT
51         zap     t0, t3, t0      # e1    :
52         stq_u   t0, 0(a0)       # e0    :
53         ret                     # .. e1 :
55 $multiword:
56         subq    t8, 1, t7       # e0    : clear the final bits in the prev
57         or      t7, t8, t7      # e1    : word
58         zapnot  t0, t7, t0      # e0    :
59         subq    a2, 1, a2       # .. e1 :
60         stq_u   t0, 0(a0)       # e0    :
61         addq    a0, 8, a0       # .. e1 :
63         beq     a2, 1f          # e1    :
64         blbc    a2, 0f          # e1    :
66         stq_u   zero, 0(a0)     # e0    : zero one word
67         subq    a2, 1, a2       # .. e1 :
68         addq    a0, 8, a0       # e0    :
69         beq     a2, 1f          # .. e1 :
71 0:      stq_u   zero, 0(a0)     # e0    : zero two words
72         subq    a2, 2, a2       # .. e1 :
73         stq_u   zero, 8(a0)     # e0    :
74         addq    a0, 16, a0      # .. e1 :
75         bne     a2, 0b          # e1    :
76         unop
78 1:      ldq_u   t0, 0(a0)       # e0    : clear the leading bits in the final
79         subq    t10, 1, t7      # .. e1 : word
80         or      t7, t10, t7     # e0    :
81         zap     t0, t7, t0      # e1 (stall)
82         stq_u   t0, 0(a0)       # e0    :
84 $zerocount:
85         ret                     # .. e1 :
87         END(strncpy)
88 libc_hidden_builtin_def (strncpy)