1 /* Optimized version of the standard strlen() function.
2 This file is part of the GNU C Library.
3 Copyright (C) 2000 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 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.
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.
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 not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Return: the length of the input string
26 Look for the null character byte by byte, until we reach a word aligned
27 address, then search word by word, using the czx instruction. We're
28 also doing one word of read ahead, which could cause problems if the
29 null character is on the last word of a page and the next page is not
30 mapped in the process address space. Hence the use of the speculative
33 This implementation assumes little endian mode. For big endian mode,
34 the instruction czx1.r should be replaced by czx1.l. */
51 alloc saved_pfs = ar.pfs, 1, 0, 0, 0
52 mov saved_lc = ar.lc // save the loop counter
54 mov len = r0 // len = 0
55 and tmp = 7, in0 // tmp = str % 8
57 sub loopcnt = 8, tmp // loopcnt = 8 - tmp
58 cmp.eq p6, p0 = tmp, r0
59 (p6) br.cond.sptk .str_aligned;;
60 adds loopcnt = -1, loopcnt;;
65 cmp.eq p6, p0 = val2, r0
66 (p6) br.cond.spnt .restore_and_exit
70 mov origadd = str // origadd = orig
74 l2: ld8.s val2 = [str], 8 // don't bomb out here
77 cmp.ne p6, p0 = 8, pos0
78 (p6) br.cond.spnt .foundit
84 sub tmp = str, origadd // tmp = crt address - orig
89 mov ar.pfs = saved_pfs // restore the PFS
90 mov ar.lc = saved_lc // restore the loop counter
94 ld8 val2 = [str], 8 // bomb out here