]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/alpha/strncpy.S
update from main archive 961105
[thirdparty/glibc.git] / sysdeps / alpha / strncpy.S
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 Contributed by Richard Henderson (rth@tamu.edu)
3
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA. */
20
21 /* Copy no more than COUNT bytes of the null-terminated string from
22 SRC to DST. If SRC does not cover all of COUNT, the balance is
23 zeroed. */
24
25 #include <sysdep.h>
26
27 .set noat
28 .set noreorder
29
30 .text
31
32 ENTRY(strncpy)
33 ldgp gp, 0(pv)
34 #ifdef PROF
35 lda AT, _mcount
36 jsr AT, (AT), _mcount
37 #endif
38 .prologue 1
39
40 mov a0, v0 # set return value now
41 beq a2, $zerocount
42 jsr t9, __stxncpy # do the work of the copy
43
44 bne a2, $multiword # do we have full words left?
45
46 .align 3
47 subq t8, 1, t2 # e0 : guess not
48 subq t10, 1, t3 # .. e1 :
49 or t2, t8, t2 # e0 : clear the bits between the last
50 or t3, t10, t3 # .. e1 : written byte and the last byte in
51 andnot t3, t2, t3 # e0 : COUNT
52 zap t0, t3, t0 # e1 :
53 stq_u t0, 0(a0) # e0 :
54 ret # .. e1 :
55
56 $multiword:
57
58 subq t8, 1, t7 # e0 : clear the final bits in the prev
59 or t7, t8, t7 # e1 : word
60 zapnot t0, t7, t0 # e0 :
61 subq a2, 1, a2 # .. e1 :
62 stq_u t0, 0(a0) # e0 :
63 addq a0, 8, a0 # .. e1 :
64
65 beq a2, 1f # e1 :
66 blbc a2, 0f # e1 :
67
68 stq_u zero, 0(a0) # e0 : zero one word
69 subq a2, 1, a2 # .. e1 :
70 addq a0, 8, a0 # e0 :
71 beq a2, 1f # .. e1 :
72
73 0: stq_u zero, 0(a0) # e0 : zero two words
74 subq a2, 2, a2 # .. e1 :
75 stq_u zero, 8(a0) # e0 :
76 addq a0, 16, a0 # .. e1 :
77 bne a2, 0b # e1 :
78 unop
79
80 1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final
81 subq t10, 1, t7 # .. e1 : word
82 or t7, t10, t7 # e0 :
83 zap t0, t7, t0 # e1 (stall)
84 stq_u t0, 0(a0) # e0 :
85
86 $zerocount:
87 ret # .. e1 :
88
89 END(strncpy)