2005-09-26 10:04:21 +04:00
/ *
* String h a n d l i n g f u n c t i o n s f o r P o w e r P C .
*
* Copyright ( C ) 1 9 9 6 P a u l M a c k e r r a s .
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
* /
# include < a s m / p r o c e s s o r . h >
# include < a s m / e r r n o . h >
# include < a s m / p p c _ a s m . h >
.section _ _ ex_ t a b l e ," a "
# ifdef C O N F I G _ P P C 6 4
.align 3
# define E X T B L . l l o n g
# else
.align 2
# define E X T B L . l o n g
# endif
.text
_ GLOBAL( s t r c p y )
addi r5 ,r3 ,- 1
addi r4 ,r4 ,- 1
1 : lbzu r0 ,1 ( r4 )
cmpwi 0 ,r0 ,0
stbu r0 ,1 ( r5 )
bne 1 b
blr
/ * This c l e a r s o u t a n y u n u s e d p a r t o f t h e d e s t i n a t i o n b u f f e r ,
just a s t h e l i b c v e r s i o n d o e s . - - p a u l u s * /
_ GLOBAL( s t r n c p y )
cmpwi 0 ,r5 ,0
beqlr
mtctr r5
addi r6 ,r3 ,- 1
addi r4 ,r4 ,- 1
1 : lbzu r0 ,1 ( r4 )
cmpwi 0 ,r0 ,0
stbu r0 ,1 ( r6 )
bdnzf 2 ,1 b / * d e c c t r , b r a n c h i f c t r ! = 0 & & ! c r0 . e q * /
bnelr / * i f w e d i d n ' t h i t a n u l l c h a r , w e ' r e d o n e * /
mfctr r5
cmpwi 0 ,r5 ,0 / * a n y s p a c e l e f t i n d e s t i n a t i o n b u f f e r ? * /
beqlr / * w e k n o w r0 = = 0 h e r e * /
2 : stbu r0 ,1 ( r6 ) / * c l e a r i t o u t i f s o * /
bdnz 2 b
blr
_ GLOBAL( s t r c a t )
addi r5 ,r3 ,- 1
addi r4 ,r4 ,- 1
1 : lbzu r0 ,1 ( r5 )
cmpwi 0 ,r0 ,0
bne 1 b
addi r5 ,r5 ,- 1
1 : lbzu r0 ,1 ( r4 )
cmpwi 0 ,r0 ,0
stbu r0 ,1 ( r5 )
bne 1 b
blr
_ GLOBAL( s t r c m p )
addi r5 ,r3 ,- 1
addi r4 ,r4 ,- 1
1 : lbzu r3 ,1 ( r5 )
cmpwi 1 ,r3 ,0
lbzu r0 ,1 ( r4 )
subf. r3 ,r0 ,r3
beqlr 1
beq 1 b
blr
2008-02-29 19:04:57 +03:00
_ GLOBAL( s t r n c m p )
PPC_ L C M P I r5 ,0
beqlr
mtctr r5
addi r5 ,r3 ,- 1
addi r4 ,r4 ,- 1
1 : lbzu r3 ,1 ( r5 )
cmpwi 1 ,r3 ,0
lbzu r0 ,1 ( r4 )
subf. r3 ,r0 ,r3
beqlr 1
bdnzt e q ,1 b
blr
2005-09-26 10:04:21 +04:00
_ GLOBAL( s t r l e n )
addi r4 ,r3 ,- 1
1 : lbzu r0 ,1 ( r4 )
cmpwi 0 ,r0 ,0
bne 1 b
subf r3 ,r3 ,r4
blr
_ GLOBAL( m e m c m p )
cmpwi 0 ,r5 ,0
ble- 2 f
mtctr r5
addi r6 ,r3 ,- 1
addi r4 ,r4 ,- 1
1 : lbzu r3 ,1 ( r6 )
lbzu r0 ,1 ( r4 )
subf. r3 ,r0 ,r3
bdnzt 2 ,1 b
blr
2 : li r3 ,0
blr
_ GLOBAL( m e m c h r )
cmpwi 0 ,r5 ,0
ble- 2 f
mtctr r5
addi r3 ,r3 ,- 1
1 : lbzu r0 ,1 ( r3 )
cmpw 0 ,r0 ,r4
bdnzf 2 ,1 b
beqlr
2 : li r3 ,0
blr
_ GLOBAL( _ _ c l e a r _ u s e r )
addi r6 ,r3 ,- 4
li r3 ,0
li r5 ,0
cmplwi 0 ,r4 ,4
blt 7 f
/* clear a single word */
11 : stwu r5 ,4 ( r6 )
beqlr
/* clear word sized chunks */
andi. r0 ,r6 ,3
add r4 ,r0 ,r4
subf r6 ,r0 ,r6
srwi r0 ,r4 ,2
andi. r4 ,r4 ,3
mtctr r0
bdz 7 f
1 : stwu r5 ,4 ( r6 )
bdnz 1 b
/* clear byte sized chunks */
7 : cmpwi 0 ,r4 ,0
beqlr
mtctr r4
addi r6 ,r6 ,3
8 : stbu r5 ,1 ( r6 )
bdnz 8 b
blr
90 : mr r3 ,r4
blr
91 : mfctr r3
slwi r3 ,r3 ,2
add r3 ,r3 ,r4
blr
92 : mfctr r3
blr
.section _ _ ex_ t a b l e ," a "
EXTBL 1 1 b ,9 0 b
EXTBL 1 b ,9 1 b
EXTBL 8 b ,9 2 b
.text
_ GLOBAL( _ _ s t r n c p y _ f r o m _ u s e r )
addi r6 ,r3 ,- 1
addi r4 ,r4 ,- 1
cmpwi 0 ,r5 ,0
beq 2 f
mtctr r5
1 : lbzu r0 ,1 ( r4 )
cmpwi 0 ,r0 ,0
stbu r0 ,1 ( r6 )
bdnzf 2 ,1 b / * d e c c t r , b r a n c h i f c t r ! = 0 & & ! c r0 . e q * /
beq 3 f
2 : addi r6 ,r6 ,1
3 : subf r3 ,r3 ,r6
blr
99 : li r3 ,- E F A U L T
blr
.section _ _ ex_ t a b l e ," a "
EXTBL 1 b ,9 9 b
.text
/* r3 = str, r4 = len (> 0), r5 = top (highest addr) */
_ GLOBAL( _ _ s t r n l e n _ u s e r )
addi r7 ,r3 ,- 1
subf r6 ,r7 ,r5 / * t o p + 1 - s t r * /
cmplw 0 ,r4 ,r6
bge 0 f
mr r6 ,r4
0 : mtctr r6 / * c t r = m i n ( l e n , t o p - s t r ) * /
1 : lbzu r0 ,1 ( r7 ) / * g e t n e x t b y t e * /
cmpwi 0 ,r0 ,0
bdnzf 2 ,1 b / * l o o p i f - - c t r ! = 0 & & b y t e ! = 0 * /
addi r7 ,r7 ,1
subf r3 ,r3 ,r7 / * n u m b e r o f b y t e s w e h a v e l o o k e d a t * /
beqlr / * r e t u r n i f w e f o u n d a 0 b y t e * /
cmpw 0 ,r3 ,r4 / * d i d w e l o o k a t a l l l e n b y t e s ? * /
blt 9 9 f / * i f n o t , m u s t h a v e h i t t o p * /
addi r3 ,r4 ,1 / * r e t u r n l e n + 1 t o i n d i c a t e n o n u l l f o u n d * /
blr
99 : li r3 ,0 / * b a d a d d r e s s , r e t u r n 0 * /
blr
.section _ _ ex_ t a b l e ," a "
EXTBL 1 b ,9 9 b