2008-12-09 12:07:09 +03:00
/ * strlen. S : S p a r c o p t i m i z e d s t r l e n c o d e
2005-04-17 02:20:36 +04:00
* Hand o p t i m i z e d f r o m G N U l i b c ' s s t r l e n
* Copyright ( C ) 1 9 9 1 ,1 9 9 6 F r e e S o f t w a r e F o u n d a t i o n
2008-12-09 12:07:09 +03:00
* Copyright ( C ) 1 9 9 6 ,2 0 0 8 D a v i d S . M i l l e r ( d a v e m @davemloft.net)
2005-04-17 02:20:36 +04:00
* Copyright ( C ) 1 9 9 6 , 1 9 9 7 J a k u b J e l i n e k ( j j @sunsite.mff.cuni.cz)
* /
2008-12-09 12:07:09 +03:00
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s m . h >
2005-04-17 02:20:36 +04:00
# define L O _ M A G I C 0 x01 0 1 0 1 0 1
# define H I _ M A G I C 0 x80 8 0 8 0 8 0
2008-12-09 12:07:09 +03:00
.text
ENTRY( s t r l e n )
2005-04-17 02:20:36 +04:00
mov % o 0 , % o 1
andcc % o 0 , 3 , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p t , 9 f )
2005-04-17 02:20:36 +04:00
sethi % h i ( H I _ M A G I C ) , % o 4
ldub [ % o 0 ] , % o 5
2008-12-09 12:07:09 +03:00
BRANCH_ R E G _ Z E R O ( p n , % o 5 , 1 1 f )
2005-04-17 02:20:36 +04:00
add % o 0 , 1 , % o 0
andcc % o 0 , 3 , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p n , 4 f )
2005-04-17 02:20:36 +04:00
or % o 4 , % l o ( H I _ M A G I C ) , % o 3
ldub [ % o 0 ] , % o 5
2008-12-09 12:07:09 +03:00
BRANCH_ R E G _ Z E R O ( p n , % o 5 , 1 2 f )
2005-04-17 02:20:36 +04:00
add % o 0 , 1 , % o 0
andcc % o 0 , 3 , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p t , 5 f )
2005-04-17 02:20:36 +04:00
sethi % h i ( L O _ M A G I C ) , % o 4
ldub [ % o 0 ] , % o 5
2008-12-09 12:07:09 +03:00
BRANCH_ R E G _ Z E R O ( p n , % o 5 , 1 3 f )
2005-04-17 02:20:36 +04:00
add % o 0 , 1 , % o 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b a , p t , 8 f )
2005-04-17 02:20:36 +04:00
or % o 4 , % l o ( L O _ M A G I C ) , % o 2
9 :
or % o 4 , % l o ( H I _ M A G I C ) , % o 3
4 :
sethi % h i ( L O _ M A G I C ) , % o 4
5 :
or % o 4 , % l o ( L O _ M A G I C ) , % o 2
8 :
ld [ % o 0 ] , % o 5
2 :
sub % o 5 , % o 2 , % o 4
andcc % o 4 , % o 3 , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p t , 8 b )
2005-04-17 02:20:36 +04:00
add % o 0 , 4 , % o 0
/* Check every byte. */
srl % o 5 , 2 4 , % g 7
andcc % g 7 , 0 x f f , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p n , 1 f )
2005-04-17 02:20:36 +04:00
add % o 0 , - 4 , % o 4
srl % o 5 , 1 6 , % g 7
andcc % g 7 , 0 x f f , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p n , 1 f )
2005-04-17 02:20:36 +04:00
add % o 4 , 1 , % o 4
srl % o 5 , 8 , % g 7
andcc % g 7 , 0 x f f , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 ( b e , p n , 1 f )
2005-04-17 02:20:36 +04:00
add % o 4 , 1 , % o 4
andcc % o 5 , 0 x f f , % g 0
2008-12-09 12:07:09 +03:00
BRANCH3 2 _ A N N U L ( b n e , p t , 2 b )
2005-04-17 02:20:36 +04:00
ld [ % o 0 ] , % o 5
add % o 4 , 1 , % o 4
1 :
retl
sub % o 4 , % o 1 , % o 0
11 :
retl
mov 0 , % o 0
12 :
retl
mov 1 , % o 0
13 :
retl
mov 2 , % o 0
2008-12-09 12:07:09 +03:00
ENDPROC( s t r l e n )