2019-06-04 11:11:33 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
2011-01-15 13:23:09 +03:00
/ *
* linux/ a r c h / u n i c o r e 3 2 / l i b / f i n d b i t . S
*
* Code s p e c i f i c t o P K U n i t y S o C a n d U n i C o r e I S A
*
* Copyright ( C ) 2 0 0 1 - 2 0 1 0 G U A N X u e - t a o
* /
# 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 >
.text
/ *
* Purpose : F i n d a ' z e r o ' b i t
* Prototype : int f i n d _ f i r s t _ z e r o _ b i t ( v o i d * a d d r , u n s i g n e d i n t m a x b i t ) ;
* /
2011-06-13 07:44:49 +04:00
ENTRY( f i n d _ f i r s t _ z e r o _ b i t )
2011-01-15 13:23:09 +03:00
cxor. a r1 , #0
beq 3 f
mov r2 , #0
1 : ldb r3 , [ r0 + ] , r2 > > #3
xor. a r3 , r3 , #0xff @ invert bits
bne . L _ f o u n d @ any now set - found zero bit
add r2 , r2 , #8 @ next bit pointer
2 : csub. a r2 , r1 @ any more?
bub 1 b
3 : mov r0 , r1 @ no free bits
mov p c , l r
2011-06-13 07:44:49 +04:00
ENDPROC( f i n d _ f i r s t _ z e r o _ b i t )
2011-01-15 13:23:09 +03:00
/ *
* Purpose : F i n d n e x t ' z e r o ' b i t
* Prototype : int f i n d _ n e x t _ z e r o _ b i t
* ( void * a d d r , u n s i g n e d i n t m a x b i t , i n t o f f s e t )
* /
2011-06-13 07:44:49 +04:00
ENTRY( f i n d _ n e x t _ z e r o _ b i t )
2011-01-15 13:23:09 +03:00
cxor. a r1 , #0
beq 3 b
and. a i p , r2 , #7
beq 1 b @ If new byte, goto old routine
ldb r3 , [ r0 + ] , r2 > > #3
xor r3 , r3 , #0xff @ now looking for a 1 bit
mov. a r3 , r3 > > i p @ shift off unused bits
bne . L _ f o u n d
or r2 , r2 , #7 @ if zero, then no bits here
add r2 , r2 , #1 @ align bit pointer
b 2 b @ loop for next bit
2011-06-13 07:44:49 +04:00
ENDPROC( f i n d _ n e x t _ z e r o _ b i t )
2011-01-15 13:23:09 +03:00
/ *
* Purpose : F i n d a ' o n e ' b i t
* Prototype : int f i n d _ f i r s t _ b i t
* ( const u n s i g n e d l o n g * a d d r , u n s i g n e d i n t m a x b i t ) ;
* /
2011-06-13 07:44:49 +04:00
ENTRY( f i n d _ f i r s t _ b i t )
2011-01-15 13:23:09 +03:00
cxor. a r1 , #0
beq 3 f
mov r2 , #0
1 : ldb r3 , [ r0 + ] , r2 > > #3
mov. a r3 , r3
bne . L _ f o u n d @ any now set - found zero bit
add r2 , r2 , #8 @ next bit pointer
2 : csub. a r2 , r1 @ any more?
bub 1 b
3 : mov r0 , r1 @ no free bits
mov p c , l r
2011-06-13 07:44:49 +04:00
ENDPROC( f i n d _ f i r s t _ b i t )
2011-01-15 13:23:09 +03:00
/ *
* Purpose : F i n d n e x t ' o n e ' b i t
* Prototype : int f i n d _ n e x t _ z e r o _ b i t
* ( void * a d d r , u n s i g n e d i n t m a x b i t , i n t o f f s e t )
* /
2011-06-13 07:44:49 +04:00
ENTRY( f i n d _ n e x t _ b i t )
2011-01-15 13:23:09 +03:00
cxor. a r1 , #0
beq 3 b
and. a i p , r2 , #7
beq 1 b @ If new byte, goto old routine
ldb r3 , [ r0 + ] , r2 > > #3
mov. a r3 , r3 > > i p @ shift off unused bits
bne . L _ f o u n d
or r2 , r2 , #7 @ if zero, then no bits here
add r2 , r2 , #1 @ align bit pointer
b 2 b @ loop for next bit
2011-06-13 07:44:49 +04:00
ENDPROC( f i n d _ n e x t _ b i t )
2011-01-15 13:23:09 +03:00
/ *
* One o r m o r e b i t s i n t h e L S B o f r3 a r e a s s u m e d t o b e s e t .
* /
.L_found :
rsub r1 , r3 , #0
and r3 , r3 , r1
cntlz r3 , r3
rsub r3 , r3 , #31
add r0 , r2 , r3
mov p c , l r