Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linux-davinci
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linux
linux-davinci
Commits
65903265
Commit
65903265
authored
Jul 12, 2005
by
Ralf Baechle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use clz / dclz on MIPS32 / MIPS64 processors.
Signed-off-by:
Ralf Baechle
<
ralf@linux-mips.org
>
parent
e5de3b46
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
22 deletions
+115
-22
include/asm-mips/bitops.h
include/asm-mips/bitops.h
+115
-22
No files found.
include/asm-mips/bitops.h
View file @
65903265
...
...
@@ -546,17 +546,60 @@ static inline int test_bit(unsigned long nr, const volatile unsigned long *addr)
return
1UL
&
(
addr
[
nr
>>
SZLONG_LOG
]
>>
(
nr
&
SZLONG_MASK
));
}
#ifdef CONFIG_CPU_MIPS32_R1
/*
* ffz - find first zero in word.
* Return the bit position (0..31) of the most significant 1 bit in a word
* Returns -1 if no 1 bit exists
*/
static
__inline__
int
__ilog2
(
unsigned
long
x
)
{
int
lz
;
__asm__
(
" .set push
\n
"
" .set mips32
\n
"
" clz %0, %1
\n
"
" .set pop
\n
"
:
"=r"
(
lz
)
:
"r"
(
x
));
return
31
-
lz
;
}
#elif defined(CONFIG_CPU_MIPS64_R1)
/*
* Return the bit position (0..63) of the most significant 1 bit in a word
* Returns -1 if no 1 bit exists
*/
static
__inline__
int
__ilog2
(
unsigned
long
x
)
{
int
lz
;
__asm__
(
" .set push
\n
"
" .set mips64
\n
"
" dclz %0, %1
\n
"
" .set pop
\n
"
:
"=r"
(
lz
)
:
"r"
(
x
));
return
63
-
lz
;
}
#endif
/*
* __ffs - find first bit in word.
* @word: The word to search
*
* Undefined if no zero exists, so code should check against ~0UL first.
* Returns 0..SZLONG-1
* Undefined if no bit exists, so code should check against 0 first.
*/
static
inline
unsigned
long
ffz
(
unsigned
long
word
)
static
inline
unsigned
long
__ffs
(
unsigned
long
word
)
{
#if defined(CONFIG_CPU_MIPS32_R1) || defined(CONFIG_CPU_MIPS64_R1)
return
__ilog2
(
word
&
-
word
);
#else
int
b
=
0
,
s
;
word
=
~
word
;
#ifdef CONFIG_32BIT
s
=
16
;
if
(
word
<<
16
!=
0
)
s
=
0
;
b
+=
s
;
word
>>=
s
;
s
=
8
;
if
(
word
<<
24
!=
0
)
s
=
0
;
b
+=
s
;
word
>>=
s
;
...
...
@@ -572,26 +615,87 @@ static inline unsigned long ffz(unsigned long word)
s
=
2
;
if
(
word
<<
62
!=
0
)
s
=
0
;
b
+=
s
;
word
>>=
s
;
s
=
1
;
if
(
word
<<
63
!=
0
)
s
=
0
;
b
+=
s
;
#endif
return
b
;
#endif
}
/*
*
__ffs - find first bit in word
.
*
ffs - find first bit set
.
* @word: The word to search
*
* Undefined if no bit exists, so code should check against 0 first.
* Returns 1..SZLONG
* Returns 0 if no bit exists
*/
static
inline
unsigned
long
__ffs
(
unsigned
long
word
)
static
inline
unsigned
long
ffs
(
unsigned
long
word
)
{
return
ffz
(
~
word
);
if
(
!
word
)
return
0
;
return
__ffs
(
word
)
+
1
;
}
/*
* fls: find last bit set.
* ffz - find first zero in word.
* @word: The word to search
*
* Undefined if no zero exists, so code should check against ~0UL first.
*/
static
inline
unsigned
long
ffz
(
unsigned
long
word
)
{
return
__ffs
(
~
word
);
}
/*
* flz - find last zero in word.
* @word: The word to search
*
* Returns 0..SZLONG-1
* Undefined if no zero exists, so code should check against ~0UL first.
*/
static
inline
unsigned
long
flz
(
unsigned
long
word
)
{
#if defined(CONFIG_CPU_MIPS32_R1) || defined(CONFIG_CPU_MIPS64_R1)
return
__ilog2
(
~
word
);
#else
#if defined(CONFIG_32BIT)
int
r
=
31
,
s
;
word
=
~
word
;
s
=
16
;
if
((
word
&
0xffff0000
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
8
;
if
((
word
&
0xff000000
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
4
;
if
((
word
&
0xf0000000
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
2
;
if
((
word
&
0xc0000000
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
1
;
if
((
word
&
0x80000000
))
s
=
0
;
r
-=
s
;
#endif
#if defined(CONFIG_64BIT)
int
r
=
63
,
s
;
word
=
~
word
;
s
=
32
;
if
((
word
&
0xffffffff00000000UL
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
16
;
if
((
word
&
0xffff000000000000UL
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
8
;
if
((
word
&
0xff00000000000000UL
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
4
;
if
((
word
&
0xf000000000000000UL
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
2
;
if
((
word
&
0xc000000000000000UL
))
s
=
0
;
r
-=
s
;
word
<<=
s
;
s
=
1
;
if
((
word
&
0x8000000000000000UL
))
s
=
0
;
r
-=
s
;
#endif
return
r
;
#endif
}
/*
* fls - find last bit set.
* @word: The word to search
*
* Returns 1..SZLONG
* Returns 0 if no bit exists
*/
static
inline
unsigned
long
fls
(
unsigned
long
word
)
{
if
(
word
==
0
)
return
0
;
return
flz
(
~
word
)
+
1
;
}
#define fls(x) generic_fls(x)
/*
* find_next_zero_bit - find the first zero bit in a memory region
...
...
@@ -727,17 +831,6 @@ static inline int sched_find_first_bit(const unsigned long *b)
#endif
}
/*
* ffs - find first bit set
* @x: the word to search
*
* This is defined the same way as
* the libc and compiler builtin ffs routines, therefore
* differs in spirit from the above ffz (man ffs).
*/
#define ffs(x) generic_ffs(x)
/*
* hweightN - returns the hamming weight of a N-bit word
* @x: the word to weigh
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment