Blame sysdeps/alpha/strchr.S

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Richard Henderson (rth@tamu.edu)
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 address of a given character within a null-terminated
Packit 6c4009
   string, or null if it is not found.
Packit 6c4009
Packit 6c4009
   This is generally scheduled for the EV5 (got to look out for my own
Packit 6c4009
   interests :-), but with EV4 needs in mind.  There *should* be no more
Packit 6c4009
   stalls for the EV4 than there are for the EV5.
Packit 6c4009
*/
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
	.set noreorder
Packit 6c4009
	.set noat
Packit 6c4009
Packit 6c4009
ENTRY(strchr)
Packit 6c4009
#ifdef PROF
Packit 6c4009
	ldgp	gp, 0(pv)
Packit 6c4009
	lda	AT, _mcount
Packit 6c4009
	jsr	AT, (AT), _mcount
Packit 6c4009
	.prologue 1
Packit 6c4009
#else
Packit 6c4009
	.prologue 0
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
	zapnot	a1, 1, a1	# e0    : zero extend the search character
Packit 6c4009
	ldq_u   t0, 0(a0)	# .. e1 : load first quadword
Packit 6c4009
	sll	a1, 8, t5	# e0    : replicate the search character
Packit 6c4009
	andnot  a0, 7, v0	# .. e1 : align our loop pointer
Packit 6c4009
	or	t5, a1, a1	# e0    :
Packit 6c4009
	lda	t4, -1		# .. e1 : build garbage mask
Packit 6c4009
	sll	a1, 16, t5	# e0    :
Packit 6c4009
	cmpbge  zero, t0, t2	# .. e1 : bits set iff byte == zero
Packit 6c4009
	mskqh	t4, a0, t4	# e0    :
Packit 6c4009
	or	t5, a1, a1	# .. e1 :
Packit 6c4009
	sll	a1, 32, t5	# e0    :
Packit 6c4009
	cmpbge	zero, t4, t4	# .. e1 : bits set iff byte is garbage
Packit 6c4009
	or	t5, a1, a1	# e0    :
Packit 6c4009
	xor	t0, a1, t1	# .. e1 : make bytes == c zero
Packit 6c4009
	cmpbge  zero, t1, t3	# e0    : bits set iff byte == c
Packit 6c4009
	or	t2, t3, t0	# e1    : bits set iff char match or zero match
Packit 6c4009
	andnot	t0, t4, t0	# e0    : clear garbage bits
Packit 6c4009
	bne	t0, $found	# .. e1 (zdb)
Packit 6c4009
Packit 6c4009
$loop:	ldq	t0, 8(v0)	# e0    :
Packit 6c4009
	addq	v0, 8, v0	# .. e1 :
Packit 6c4009
	nop			# e0    :
Packit 6c4009
	xor	t0, a1, t1	# .. e1 (ev5 data stall)
Packit 6c4009
	cmpbge	zero, t0, t2	# e0    : bits set iff byte == 0
Packit 6c4009
	cmpbge	zero, t1, t3	# .. e1 : bits set iff byte == c
Packit 6c4009
	or	t2, t3, t0	# e0    :
Packit 6c4009
	beq	t0, $loop	# .. e1 (zdb)
Packit 6c4009
Packit 6c4009
$found:	negq    t0, t1		# e0    : clear all but least set bit
Packit 6c4009
	and     t0, t1, t0	# e1 (stall)
Packit 6c4009
Packit 6c4009
	and	t0, t3, t1	# e0    : bit set iff byte was the char
Packit 6c4009
	beq	t1, $retnull	# .. e1 (zdb)
Packit 6c4009
Packit 6c4009
	and     t0, 0xf0, t2	# e0    : binary search for that set bit
Packit 6c4009
	and	t0, 0xcc, t3	# .. e1 :
Packit 6c4009
	and	t0, 0xaa, t4	# e0    :
Packit 6c4009
	cmovne	t2, 4, t2	# .. e1 :
Packit 6c4009
	cmovne	t3, 2, t3	# e0    :
Packit 6c4009
	cmovne	t4, 1, t4	# .. e1 :
Packit 6c4009
	addq	t2, t3, t2	# e0    :
Packit 6c4009
	addq	v0, t4, v0	# .. e1 :
Packit 6c4009
	addq	v0, t2, v0	# e0    :
Packit 6c4009
	ret			# .. e1 :
Packit 6c4009
Packit 6c4009
$retnull:
Packit 6c4009
	mov	zero, v0	# e0    :
Packit 6c4009
	ret			# .. e1 :
Packit 6c4009
Packit 6c4009
	END(strchr)
Packit 6c4009
Packit 6c4009
weak_alias (strchr, index)
Packit 6c4009
libc_hidden_builtin_def (strchr)