1 /* Optimized version of the standard strncpy() function.
2 This file is part of the GNU C Library.
3 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Dan Pop <Dan.Pop@cern.ch>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 If n >= 24, do a memcpy(dest, src, min(strnlen(src, n)+1, n)), followed by a
29 memset(dest + strlen(src, n), 0, n - strlen(src, n) - 1) if necessary.
31 Otherwise, copy characters one by one and fill with nulls if necessary. */
37 #define saved_pfs loc1
50 .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(3)
51 alloc saved_pfs = ar.pfs, 3, 6, 3, 0
58 cmp.gtu p6, p0 = 24, n
59 (p6) br.cond.spnt .cpyfew
63 br.call.sptk.many b0 = strnlen# ;; // rc = strnlen(src, n);
64 add len = 1, rc // include the null in len
67 cmp.ltu p4, p5 = len, n
71 br.call.sptk.many b0 = memcpy# ;; // memcpy(dest, src, min(len, n));
73 (p4) add out0 = dest, len
75 (p4) sub out2 = n, len
76 (p4) br.call.sptk.many b0 = memset# ;; // fill the rest with nulls
80 mov ar.pfs = saved_pfs
87 (p6) br.cond.spnt .restore_and_exit ;; // do nothing if n == 0
89 cmp.eq p6, p0 = r0, r0 ;; // set p6
91 (p6) ld1 tmp = [src],1
94 (p6) cmp.ne p6, p0 = tmp, r0 // clear p6 after encountering the
95 br.cloop.dptk .loop ;; // null character in src
98 mov ar.pfs = saved_pfs