|
Packit Service |
82fcde |
/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
EV67 optimized by Rick Gorton <rick.gorton@alpha-processor.com>.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
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 the last occurrence of a given character
|
|
Packit Service |
82fcde |
within a null-terminated string, or null if it is not found. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <sysdep.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
.arch ev6
|
|
Packit Service |
82fcde |
.set noreorder
|
|
Packit Service |
82fcde |
.set noat
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
ENTRY(strrchr)
|
|
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 |
and a1, 0xff, t2 # E : 00000000000000ch
|
|
Packit Service |
82fcde |
insbl a1, 1, t4 # U : 000000000000ch00
|
|
Packit Service |
82fcde |
insbl a1, 2, t5 # U : 0000000000ch0000
|
|
Packit Service |
82fcde |
ldq_u t0, 0(a0) # L : load first quadword Latency=3
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
mov zero, t6 # E : t6 is last match aligned addr
|
|
Packit Service |
82fcde |
or t2, t4, a1 # E : 000000000000chch
|
|
Packit Service |
82fcde |
sll t5, 8, t3 # U : 00000000ch000000
|
|
Packit Service |
82fcde |
mov zero, t8 # E : t8 is last match byte compare mask
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
andnot a0, 7, v0 # E : align source addr
|
|
Packit Service |
82fcde |
or t5, t3, t3 # E : 00000000chch0000
|
|
Packit Service |
82fcde |
sll a1, 32, t2 # U : 0000chch00000000
|
|
Packit Service |
82fcde |
sll a1, 48, t4 # U : chch000000000000
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
or t4, a1, a1 # E : chch00000000chch
|
|
Packit Service |
82fcde |
or t2, t3, t2 # E : 0000chchchch0000
|
|
Packit Service |
82fcde |
or a1, t2, a1 # E : chchchchchchchch
|
|
Packit Service |
82fcde |
lda t5, -1 # E : build garbage mask
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmpbge zero, t0, t1 # E : bits set iff byte == zero
|
|
Packit Service |
82fcde |
mskqh t5, a0, t4 # E : Complete garbage mask
|
|
Packit Service |
82fcde |
xor t0, a1, t2 # E : make bytes == c zero
|
|
Packit Service |
82fcde |
cmpbge zero, t4, t4 # E : bits set iff byte is garbage
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmpbge zero, t2, t3 # E : bits set iff byte == c
|
|
Packit Service |
82fcde |
andnot t1, t4, t1 # E : clear garbage from null test
|
|
Packit Service |
82fcde |
andnot t3, t4, t3 # E : clear garbage from char test
|
|
Packit Service |
82fcde |
bne t1, $eos # U : did we already hit the terminator?
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Character search main loop */
|
|
Packit Service |
82fcde |
$loop:
|
|
Packit Service |
82fcde |
ldq t0, 8(v0) # L : load next quadword
|
|
Packit Service |
82fcde |
cmovne t3, v0, t6 # E : save previous comparisons match
|
|
Packit Service |
82fcde |
nop # : Latency=2, extra map slot (keep nop with cmov)
|
|
Packit Service |
82fcde |
nop
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmovne t3, t3, t8 # E : Latency=2, extra map slot
|
|
Packit Service |
82fcde |
nop # : keep with cmovne
|
|
Packit Service |
82fcde |
addq v0, 8, v0 # E :
|
|
Packit Service |
82fcde |
xor t0, a1, t2 # E :
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmpbge zero, t0, t1 # E : bits set iff byte == zero
|
|
Packit Service |
82fcde |
cmpbge zero, t2, t3 # E : bits set iff byte == c
|
|
Packit Service |
82fcde |
beq t1, $loop # U : if we havnt seen a null, loop
|
|
Packit Service |
82fcde |
nop
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Mask out character matches after terminator */
|
|
Packit Service |
82fcde |
$eos:
|
|
Packit Service |
82fcde |
negq t1, t4 # E : isolate first null byte match
|
|
Packit Service |
82fcde |
and t1, t4, t4 # E :
|
|
Packit Service |
82fcde |
subq t4, 1, t5 # E : build a mask of the bytes upto...
|
|
Packit Service |
82fcde |
or t4, t5, t4 # E : ... and including the null
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
and t3, t4, t3 # E : mask out char matches after null
|
|
Packit Service |
82fcde |
cmovne t3, t3, t8 # E : save it, if match found Latency=2, extra map slot
|
|
Packit Service |
82fcde |
nop # : Keep with cmovne
|
|
Packit Service |
82fcde |
nop
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmovne t3, v0, t6 # E :
|
|
Packit Service |
82fcde |
nop # : Keep with cmovne
|
|
Packit Service |
82fcde |
/* Locate the address of the last matched character */
|
|
Packit Service |
82fcde |
ctlz t8, t2 # U0 : Latency=3 (0x40 for t8=0)
|
|
Packit Service |
82fcde |
nop
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmoveq t8, 0x3f, t2 # E : Compensate for case when no match is seen
|
|
Packit Service |
82fcde |
nop # E : hide the cmov latency (2) behind ctlz latency
|
|
Packit Service |
82fcde |
lda t5, 0x3f($31) # E :
|
|
Packit Service |
82fcde |
subq t5, t2, t5 # E : Normalize leading zero count
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
addq t6, t5, v0 # E : and add to quadword address
|
|
Packit Service |
82fcde |
ret # L0 : Latency=3
|
|
Packit Service |
82fcde |
nop
|
|
Packit Service |
82fcde |
nop
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
END(strrchr)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
weak_alias (strrchr, rindex)
|
|
Packit Service |
82fcde |
libc_hidden_builtin_def (strrchr)
|