2005-04-16 15:20:36 -07:00
/ *
* arch/ a l p h a / l i b / e v67 - s t r r c h r . S
* 2 1 2 6 4 version b y R i c k G o r t o n < r i c k . g o r t o n @alpha-processor.com>
*
* Finds l e n g t h o f a 0 - t e r m i n a t e d s t r i n g . O p t i m i z e d f o r t h e
* Alpha a r c h i t e c t u r e :
*
* - memory a c c e s s e d a s a l i g n e d q u a d w o r d s o n l y
* - uses b c m p g e t o c o m p a r e 8 b y t e s i n p a r a l l e l
*
* Much o f t h e i n f o r m a t i o n a b o u t 2 1 2 6 4 s c h e d u l i n g / c o d i n g c o m e s f r o m :
* Compiler W r i t e r ' s G u i d e f o r t h e A l p h a 2 1 2 6 4
* abbreviated a s ' C W G ' i n o t h e r c o m m e n t s h e r e
* ftp. d i g i t a l . c o m / p u b / D i g i t a l / i n f o / s e m i c o n d u c t o r / l i t e r a t u r e / d s c - l i b r a r y . h t m l
* Scheduling n o t a t i o n :
* E - e i t h e r c l u s t e r
* U - u p p e r s u b c l u s t e r ; U0 - subcluster U0; U1 - subcluster U1
* L - l o w e r s u b c l u s t e r ; L0 - subcluster L0; L1 - subcluster L1
* /
# include < a s m / r e g d e f . h >
.set noreorder
.set noat
.align 4
.ent strrchr
.globl strrchr
strrchr :
.frame sp, 0 , r a
.prologue 0
and a1 , 0 x f f , t 2 # E : 00000000000000 c h
insbl a1 , 1 , t 4 # U : 000000000000 c h00
insbl a1 , 2 , t 5 # U : 0000000000 c h00 0 0
ldq_ u t 0 , 0 ( a0 ) # L : l o a d f i r s t q u a d w o r d L a t e n c y = 3
mov z e r o , t 6 # E : t 6 i s l a s t m a t c h a l i g n e d a d d r
or t 2 , t 4 , a1 # E : 000000000000 c h c h
sll t 5 , 8 , t 3 # U : 00000000 c h00 0 0 0 0
mov z e r o , t 8 # E : t 8 i s l a s t m a t c h b y t e c o m p a r e m a s k
andnot a0 , 7 , v0 # E : a l i g n s o u r c e a d d r
or t 5 , t 3 , t 3 # E : 00000000 c h c h00 0 0
sll a1 , 3 2 , t 2 # U : 0000 c h c h00 0 0 0 0 0 0
sll a1 , 4 8 , t 4 # U : c h c h 000000000000
or t 4 , a1 , a1 # E : c h c h 00000000 c h c h
or t 2 , t 3 , t 2 # E : 0000 c h c h c h c h00 0 0
or a1 , t 2 , a1 # E : c h c h c h c h c h c h c h c h
lda t 5 , - 1 # E : b u i l d g a r b a g e m a s k
cmpbge z e r o , t 0 , t 1 # E : b i t s s e t i f f b y t e = = z e r o
mskqh t 5 , a0 , t 4 # E : C o m p l e t e g a r b a g e m a s k
xor t 0 , a1 , t 2 # E : m a k e b y t e s = = c z e r o
cmpbge z e r o , t 4 , t 4 # E : b i t s s e t i f f b y t e i s g a r b a g e
cmpbge z e r o , t 2 , t 3 # E : b i t s s e t i f f b y t e = = c
andnot t 1 , t 4 , t 1 # E : c l e a r g a r b a g e f r o m n u l l t e s t
andnot t 3 , t 4 , t 3 # E : c l e a r g a r b a g e f r o m c h a r t e s t
bne t 1 , $ e o s # U : d i d w e a l r e a d y h i t t h e t e r m i n a t o r ?
/* Character search main loop */
$ loop :
ldq t 0 , 8 ( v0 ) # L : l o a d n e x t q u a d w o r d
cmovne t 3 , v0 , t 6 # E : s a v e p r e v i o u s c o m p a r i s o n s m a t c h
nop # : L a t e n c y = 2 , e x t r a m a p s l o t ( k e e p n o p w i t h c m o v )
nop
cmovne t 3 , t 3 , t 8 # E : L a t e n c y = 2 , e x t r a m a p s l o t
nop # : k e e p w i t h c m o v n e
addq v0 , 8 , v0 # E :
xor t 0 , a1 , t 2 # E :
cmpbge z e r o , t 0 , t 1 # E : b i t s s e t i f f b y t e = = z e r o
cmpbge z e r o , t 2 , t 3 # E : b i t s s e t i f f b y t e = = c
beq t 1 , $ l o o p # U : i f w e h a v n t s e e n a n u l l , l o o p
nop
/* Mask out character matches after terminator */
$ eos :
negq t 1 , t 4 # E : i s o l a t e f i r s t n u l l b y t e m a t c h
and t 1 , t 4 , t 4 # E :
2011-03-30 22:57:33 -03:00
subq t 4 , 1 , t 5 # E : b u i l d a m a s k o f t h e b y t e s u p t o . . .
2005-04-16 15:20:36 -07:00
or t 4 , t 5 , t 4 # E : . . . a n d i n c l u d i n g t h e n u l l
and t 3 , t 4 , t 3 # E : m a s k o u t c h a r m a t c h e s a f t e r n u l l
cmovne t 3 , t 3 , t 8 # E : s a v e i t , i f m a t c h f o u n d L a t e n c y = 2 , e x t r a m a p s l o t
nop # : K e e p w i t h c m o v n e
nop
cmovne t 3 , v0 , t 6 # E :
nop # : K e e p w i t h c m o v n e
/* Locate the address of the last matched character */
ctlz t 8 , t 2 # U 0 : L a t e n c y =3 ( 0 x40 f o r t 8 =0 )
nop
cmoveq t 8 , 0 x3 f , t 2 # E : C o m p e n s a t e f o r c a s e w h e n n o m a t c h i s s e e n
nop # E : h i d e t h e c m o v l a t e n c y ( 2 ) b e h i n d c t l z l a t e n c y
lda t 5 , 0 x3 f ( $ 3 1 ) # E :
subq t 5 , t 2 , t 5 # E : N o r m a l i z e l e a d i n g z e r o c o u n t
addq t 6 , t 5 , v0 # E : a n d a d d t o q u a d w o r d a d d r e s s
ret # L 0 : L a t e n c y =3
nop
nop
.end strrchr