Blame sysdeps/ia64/strlen.S

Packit 6c4009
/* Optimized version of the standard strlen() function.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit 6c4009
   Contributed by Dan Pop <Dan.Pop@cern.ch>.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* Return: the length of the input string
Packit 6c4009
Packit 6c4009
   Input:
Packit 6c4009
        in0:    str
Packit 6c4009
Packit 6c4009
   Look for the null character byte by byte, until we reach a word aligned
Packit 6c4009
   address, then search word by word, using the czx instruction.  We're
Packit 6c4009
   also doing one word of read ahead, which could cause problems if the
Packit 6c4009
   null character is on the last word of a page and the next page is not
Packit 6c4009
   mapped in the process address space.  Hence the use of the speculative
Packit 6c4009
   load.
Packit 6c4009
Packit 6c4009
   This implementation assumes little endian mode.  For big endian mode,
Packit 6c4009
   the instruction czx1.r should be replaced by czx1.l.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#undef ret
Packit 6c4009
Packit 6c4009
#define saved_lc	r18
Packit 6c4009
#define str		r19
Packit 6c4009
#define pos0		r20
Packit 6c4009
#define val1		r21
Packit 6c4009
#define val2		r22
Packit 6c4009
#define origadd		r23
Packit 6c4009
#define tmp		r24
Packit 6c4009
#define loopcnt		r30
Packit 6c4009
#define len		ret0
Packit 6c4009
Packit 6c4009
ENTRY(strlen)
Packit 6c4009
	.prologue
Packit 6c4009
	alloc r2 = ar.pfs, 1, 0, 0, 0
Packit 6c4009
	.save ar.lc, saved_lc
Packit 6c4009
        mov 	saved_lc = ar.lc 	// save the loop counter
Packit 6c4009
	.body
Packit 6c4009
	mov 	str = in0
Packit 6c4009
	mov 	len = r0		// len = 0
Packit 6c4009
	and 	tmp = 7, in0		// tmp = str % 8
Packit 6c4009
	;;
Packit 6c4009
	sub	loopcnt = 8, tmp	// loopcnt = 8 - tmp
Packit 6c4009
	cmp.eq	p6, p0 = tmp, r0
Packit 6c4009
(p6)	br.cond.sptk	.str_aligned;;
Packit 6c4009
	adds	loopcnt = -1, loopcnt;;
Packit 6c4009
	mov	ar.lc = loopcnt
Packit 6c4009
.l1:
Packit 6c4009
	ld1	val2 = [str], 1
Packit 6c4009
	;;
Packit 6c4009
	cmp.eq	p6, p0 = val2, r0
Packit 6c4009
(p6)	br.cond.spnt	.restore_and_exit
Packit 6c4009
	adds	len = 1, len
Packit 6c4009
	br.cloop.dptk	.l1
Packit 6c4009
.str_aligned:
Packit 6c4009
	mov	origadd = str		// origadd = orig
Packit 6c4009
	ld8	val1 = [str], 8;;
Packit 6c4009
	nop.b	0
Packit 6c4009
	nop.b 	0
Packit 6c4009
.l2:	ld8.s	val2 = [str], 8		// don't bomb out here
Packit 6c4009
	czx1.r	pos0 = val1
Packit 6c4009
	;;
Packit 6c4009
	cmp.ne	p6, p0 = 8, pos0
Packit 6c4009
(p6)	br.cond.spnt .foundit
Packit 6c4009
	chk.s	val2, .recovery
Packit 6c4009
.back:
Packit 6c4009
	mov	val1 = val2
Packit 6c4009
	br.cond.dptk	.l2
Packit 6c4009
.foundit:
Packit 6c4009
	sub	tmp = str, origadd	// tmp = crt address - orig
Packit 6c4009
	add	len = len, pos0;;
Packit 6c4009
	add	len = len, tmp;;
Packit 6c4009
	adds	len = -16, len
Packit 6c4009
.restore_and_exit:
Packit 6c4009
	mov ar.lc = saved_lc		// restore the loop counter
Packit 6c4009
	br.ret.sptk.many b0
Packit 6c4009
.recovery:
Packit 6c4009
	adds	str = -8, str;;
Packit 6c4009
	ld8	val2 = [str], 8		// bomb out here
Packit 6c4009
	br.cond.sptk	.back
Packit 6c4009
END(strlen)
Packit 6c4009
libc_hidden_builtin_def (strlen)