2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / stpncpy.S
blobe877cf176a9666a067a4c839c0d717d6be24239c
1 /* Copyright (C) 1996, 2002 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Richard Henderson (rth@tamu.edu)
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.  Return the address of the terminating null in DEST, if
23    any, else DEST + COUNT.  */
25 #include <sysdep.h>
27         .set noat
28         .set noreorder
30         .text
32 ENTRY(__stpncpy)
33         ldgp    gp, 0(pv)
34 #ifdef PROF
35         lda     AT, _mcount
36         jsr     AT, (AT), _mcount
37 #endif
38         .prologue 1
40         beq     a2, $zerocount
41         jsr     t9, __stxncpy   # do the work of the copy
43         and     t8, 0xf0, t3    # binary search for byte offset of the
44         and     t8, 0xcc, t2    # last byte written.
45         and     t8, 0xaa, t1
46         andnot  a0, 7, v0
47         cmovne  t3, 4, t3
48         cmovne  t2, 2, t2
49         cmovne  t1, 1, t1
50         addq    v0, t3, v0
51         addq    t1, t2, t1
52         addq    v0, t1, v0
54         bne     a2, $multiword  # do we have full words left?
56         .align 3
57         zapnot  t0, t8, t4      # e0    : was last byte a null?
58         subq    t8, 1, t2       # .. e1 :
59         addq    v0, 1, t5       # e0    :
60         subq    t10, 1, t3      # .. e1 :
61         or      t2, t8, t2      # e0    : clear the bits between the last
62         or      t3, t10, t3     # .. e1 : written byte and the last byte in
63         andnot  t3, t2, t3      # e0    : COUNT
64         cmovne  t4, t5, v0      # .. e1 : if last written wasnt null, inc v0
65         zap     t0, t3, t0      # e0    :
66         stq_u   t0, 0(a0)       # e1    :
67         ret                     # .. e1 :
69         .align 3
70 $multiword:
71         subq    t8, 1, t7       # e0    : clear the final bits in the prev
72         or      t7, t8, t7      # e1    : word
73         zapnot  t0, t7, t0      # e0    :
74         subq    a2, 1, a2       # .. e1 :
75         stq_u   t0, 0(a0)       # e0    :
76         addq    a0, 8, a0       # .. e1 :
78         beq     a2, 1f          # e1    :
79         blbc    a2, 0f          # e1    :
81         stq_u   zero, 0(a0)     # e0    : zero one word
82         subq    a2, 1, a2       # .. e1 :
83         addq    a0, 8, a0       # e0    :
84         beq     a2, 1f          # .. e1 :
86 0:      stq_u   zero, 0(a0)     # e0    : zero two words
87         subq    a2, 2, a2       # .. e1 :
88         stq_u   zero, 8(a0)     # e0    :
89         addq    a0, 16, a0      # .. e1 :
90         bne     a2, 0b          # e1    :
91         unop
93 1:      ldq_u   t0, 0(a0)       # e0    : clear the leading bits in the final
94         subq    t10, 1, t7      # .. e1 : word
95         or      t7, t10, t7     # e0    :
96         zap     t0, t7, t0      # e1 (stall)
97         stq_u   t0, 0(a0)       # e0    :
98         ret                     # .. e1 :
100 $zerocount:
101         mov     a0, v0
102         ret
104         END(__stpncpy)
106 libc_hidden_def (__stpncpy)
107 weak_alias (__stpncpy, stpncpy)