2019-06-03 07:44:50 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2013-03-21 16:16:43 +00:00
/ *
2021-05-27 16:34:47 +01:00
* Copyright ( C ) 2 0 2 1 A r m L t d .
2013-03-21 16:16:43 +00:00
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
/ *
* Find a c h a r a c t e r i n a n a r e a o f m e m o r y .
*
* Parameters :
* x0 - b u f
* x1 - c
* x2 - n
* Returns :
* x0 - a d d r e s s o f f i r s t o c c u r r e n c e o f ' c ' o r 0
* /
2021-05-27 16:34:47 +01:00
# define L ( l a b e l ) . L ## l a b e l
# define R E P 8 _ 0 1 0 x01 0 1 0 1 0 1 0 1 0 1 0 1 0 1
# define R E P 8 _ 7 f 0 x7 f7 f7 f7 f7 f7 f7 f7 f
# define s r c i n x0
# define c h r i n w1
# define c n t i n x2
# define r e s u l t x0
# define w o r d c n t x3
# define r e p01 x4
# define r e p c h r x5
# define c u r _ w o r d x6
# define c u r _ b y t e w6
# define t m p x7
# define t m p2 x8
.p2align 4
nop
2020-01-06 19:58:17 +00:00
SYM_ F U N C _ S T A R T _ W E A K _ P I ( m e m c h r )
2021-05-27 16:34:47 +01:00
and c h r i n , c h r i n , #0xff
lsr w o r d c n t , c n t i n , #3
cbz w o r d c n t , L ( b y t e _ l o o p )
mov r e p01 , #R E P 8 _ 0 1
mul r e p c h r , x1 , r e p01
and c n t i n , c n t i n , #7
L( w o r d _ l o o p ) :
ldr c u r _ w o r d , [ s r c i n ] , #8
sub w o r d c n t , w o r d c n t , #1
eor c u r _ w o r d , c u r _ w o r d , r e p c h r
sub t m p , c u r _ w o r d , r e p01
orr t m p2 , c u r _ w o r d , #R E P 8 _ 7 f
bics t m p , t m p , t m p2
b. n e L ( f o u n d _ w o r d )
cbnz w o r d c n t , L ( w o r d _ l o o p )
L( b y t e _ l o o p ) :
cbz c n t i n , L ( n o t _ f o u n d )
ldrb c u r _ b y t e , [ s r c i n ] , #1
sub c n t i n , c n t i n , #1
cmp c u r _ b y t e , c h r i n
b. n e L ( b y t e _ l o o p )
sub s r c i n , s r c i n , #1
ret
L( f o u n d _ w o r d ) :
CPU_ L E ( r e v t m p , t m p )
clz t m p , t m p
sub t m p , t m p , #64
add r e s u l t , s r c i n , t m p , a s r #3
2013-03-21 16:16:43 +00:00
ret
2021-05-27 16:34:47 +01:00
L( n o t _ f o u n d ) :
mov r e s u l t , #0
2013-03-21 16:16:43 +00:00
ret
2020-01-06 19:58:17 +00:00
SYM_ F U N C _ E N D _ P I ( m e m c h r )
2018-12-07 18:08:21 +00:00
EXPORT_ S Y M B O L _ N O K A S A N ( m e m c h r )