Blame sysdeps/alpha/strchr.S

Packit Service 82fcde
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
   Contributed by Richard Henderson (rth@tamu.edu)
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library.  If not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
/* Return the address of a given character within a null-terminated
Packit Service 82fcde
   string, or null if it is not found.
Packit Service 82fcde
Packit Service 82fcde
   This is generally scheduled for the EV5 (got to look out for my own
Packit Service 82fcde
   interests :-), but with EV4 needs in mind.  There *should* be no more
Packit Service 82fcde
   stalls for the EV4 than there are for the EV5.
Packit Service 82fcde
*/
Packit Service 82fcde
Packit Service 82fcde
#include <sysdep.h>
Packit Service 82fcde
Packit Service 82fcde
	.set noreorder
Packit Service 82fcde
	.set noat
Packit Service 82fcde
Packit Service 82fcde
ENTRY(strchr)
Packit Service 82fcde
#ifdef PROF
Packit Service 82fcde
	ldgp	gp, 0(pv)
Packit Service 82fcde
	lda	AT, _mcount
Packit Service 82fcde
	jsr	AT, (AT), _mcount
Packit Service 82fcde
	.prologue 1
Packit Service 82fcde
#else
Packit Service 82fcde
	.prologue 0
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
	zapnot	a1, 1, a1	# e0    : zero extend the search character
Packit Service 82fcde
	ldq_u   t0, 0(a0)	# .. e1 : load first quadword
Packit Service 82fcde
	sll	a1, 8, t5	# e0    : replicate the search character
Packit Service 82fcde
	andnot  a0, 7, v0	# .. e1 : align our loop pointer
Packit Service 82fcde
	or	t5, a1, a1	# e0    :
Packit Service 82fcde
	lda	t4, -1		# .. e1 : build garbage mask
Packit Service 82fcde
	sll	a1, 16, t5	# e0    :
Packit Service 82fcde
	cmpbge  zero, t0, t2	# .. e1 : bits set iff byte == zero
Packit Service 82fcde
	mskqh	t4, a0, t4	# e0    :
Packit Service 82fcde
	or	t5, a1, a1	# .. e1 :
Packit Service 82fcde
	sll	a1, 32, t5	# e0    :
Packit Service 82fcde
	cmpbge	zero, t4, t4	# .. e1 : bits set iff byte is garbage
Packit Service 82fcde
	or	t5, a1, a1	# e0    :
Packit Service 82fcde
	xor	t0, a1, t1	# .. e1 : make bytes == c zero
Packit Service 82fcde
	cmpbge  zero, t1, t3	# e0    : bits set iff byte == c
Packit Service 82fcde
	or	t2, t3, t0	# e1    : bits set iff char match or zero match
Packit Service 82fcde
	andnot	t0, t4, t0	# e0    : clear garbage bits
Packit Service 82fcde
	bne	t0, $found	# .. e1 (zdb)
Packit Service 82fcde
Packit Service 82fcde
$loop:	ldq	t0, 8(v0)	# e0    :
Packit Service 82fcde
	addq	v0, 8, v0	# .. e1 :
Packit Service 82fcde
	nop			# e0    :
Packit Service 82fcde
	xor	t0, a1, t1	# .. e1 (ev5 data stall)
Packit Service 82fcde
	cmpbge	zero, t0, t2	# e0    : bits set iff byte == 0
Packit Service 82fcde
	cmpbge	zero, t1, t3	# .. e1 : bits set iff byte == c
Packit Service 82fcde
	or	t2, t3, t0	# e0    :
Packit Service 82fcde
	beq	t0, $loop	# .. e1 (zdb)
Packit Service 82fcde
Packit Service 82fcde
$found:	negq    t0, t1		# e0    : clear all but least set bit
Packit Service 82fcde
	and     t0, t1, t0	# e1 (stall)
Packit Service 82fcde
Packit Service 82fcde
	and	t0, t3, t1	# e0    : bit set iff byte was the char
Packit Service 82fcde
	beq	t1, $retnull	# .. e1 (zdb)
Packit Service 82fcde
Packit Service 82fcde
	and     t0, 0xf0, t2	# e0    : binary search for that set bit
Packit Service 82fcde
	and	t0, 0xcc, t3	# .. e1 :
Packit Service 82fcde
	and	t0, 0xaa, t4	# e0    :
Packit Service 82fcde
	cmovne	t2, 4, t2	# .. e1 :
Packit Service 82fcde
	cmovne	t3, 2, t3	# e0    :
Packit Service 82fcde
	cmovne	t4, 1, t4	# .. e1 :
Packit Service 82fcde
	addq	t2, t3, t2	# e0    :
Packit Service 82fcde
	addq	v0, t4, v0	# .. e1 :
Packit Service 82fcde
	addq	v0, t2, v0	# e0    :
Packit Service 82fcde
	ret			# .. e1 :
Packit Service 82fcde
Packit Service 82fcde
$retnull:
Packit Service 82fcde
	mov	zero, v0	# e0    :
Packit Service 82fcde
	ret			# .. e1 :
Packit Service 82fcde
Packit Service 82fcde
	END(strchr)
Packit Service 82fcde
Packit Service 82fcde
weak_alias (strchr, index)
Packit Service 82fcde
libc_hidden_builtin_def (strchr)