1/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <https://www.gnu.org/licenses/>. */
17
18/* Copy no more than N bytes from SRC to DEST, returning the address of
19 the terminating '\0' in DEST. */
20
21#include <sysdep.h>
22
23 .arch ev6
24 .set noat
25 .set noreorder
26 .text
27
28ENTRY(__stpncpy)
29 ldgp gp, 0(pv)
30#ifdef PROF
31 lda AT, _mcount
32 jsr AT, (AT), _mcount
33#endif
34 .prologue 1
35
36 mov a0, v0
37 beq a2, $zerocount
38
39 .align 4
40 nop
41 nop
42 jsr t9, __stxncpy # do the work of the copy
43
44 cttz t8, t4
45 zapnot t0, t8, t5
46 andnot a0, 7, a0
47 bne a2, $multiword # do we have full words left?
48
49 subq t8, 1, t2
50 subq t10, 1, t3
51 cmpult zero, t5, t5
52 addq a0, t4, v0
53
54 or t2, t8, t2
55 or t3, t10, t3
56 addq v0, t5, v0
57 andnot t3, t2, t3
58
59 zap t0, t3, t0
60 nop
61 stq t0, 0(a0)
62 ret
63
64$multiword:
65 subq t8, 1, t7 # clear the final bits in the prev word
66 cmpult zero, t5, t5
67 or t7, t8, t7
68 zapnot t0, t7, t0
69
70 subq a2, 1, a2
71 stq t0, 0(a0)
72 addq a0, 8, a1
73 beq a2, 1f # loop over full words remaining
74
75 nop
76 nop
77 nop
78 blbc a2, 0f
79
80 stq zero, 0(a1)
81 subq a2, 1, a2
82 addq a1, 8, a1
83 beq a2, 1f
84
850: stq zero, 0(a1)
86 subq a2, 2, a2
87 nop
88 nop
89
90 stq zero, 8(a1)
91 addq a1, 16, a1
92 nop
93 bne a2, 0b
94
951: ldq t0, 0(a1) # clear the leading bits in the final word
96 subq t10, 1, t7
97 addq a0, t4, v0
98 nop
99
100 or t7, t10, t7
101 addq v0, t5, v0
102 zap t0, t7, t0
103 stq t0, 0(a1)
104
105$zerocount:
106 nop
107 nop
108 nop
109 ret
110
111 END(__stpncpy)
112
113libc_hidden_def (__stpncpy)
114weak_alias (__stpncpy, stpncpy)
115

source code of glibc/sysdeps/alpha/alphaev67/stpncpy.S