1 /* Copyright (C) 1996-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 /* Copy no more than COUNT bytes of the null-terminated string from
19 SRC to DST. If SRC does not cover all of COUNT, the balance is
20 zeroed. Return the address of the terminating null in DEST, if
21 any, else DEST + COUNT. */
39 jsr t9, __stxncpy # do the work of the copy
41 and t8, 0xf0, t3 # binary search for byte offset of the
42 and t8, 0xcc, t2 # last byte written.
52 bne a2, $multiword # do we have full words left?
55 zapnot t0, t8, t4 # e0 : was last byte a null?
56 subq t8, 1, t2 # .. e1 :
58 subq t10, 1, t3 # .. e1 :
59 or t2, t8, t2 # e0 : clear the bits between the last
60 or t3, t10, t3 # .. e1 : written byte and the last byte in
61 andnot t3, t2, t3 # e0 : COUNT
62 cmovne t4, t5, v0 # .. e1 : if last written wasnt null, inc v0
64 stq_u t0, 0(a0) # e1 :
69 subq t8, 1, t7 # e0 : clear the final bits in the prev
70 or t7, t8, t7 # e1 : word
71 zapnot t0, t7, t0 # e0 :
72 subq a2, 1, a2 # .. e1 :
73 stq_u t0, 0(a0) # e0 :
74 addq a0, 8, a0 # .. e1 :
79 stq_u zero, 0(a0) # e0 : zero one word
80 subq a2, 1, a2 # .. e1 :
84 0: stq_u zero, 0(a0) # e0 : zero two words
85 subq a2, 2, a2 # .. e1 :
86 stq_u zero, 8(a0) # e0 :
87 addq a0, 16, a0 # .. e1 :
91 1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final
92 subq t10, 1, t7 # .. e1 : word
94 zap t0, t7, t0 # e1 (stall)
95 stq_u t0, 0(a0) # e0 :
104 libc_hidden_def (__stpncpy)
105 weak_alias (__stpncpy, stpncpy)