Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VVCSoftware_VTM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Remy Foray
VVCSoftware_VTM
Commits
12713818
Commit
12713818
authored
6 years ago
by
Frank Bossen
Browse files
Options
Downloads
Patches
Plain Diff
Add floor(log2(x)) helper function
parent
ecd52fc2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/Lib/CommonLib/CommonDef.h
+39
-0
39 additions, 0 deletions
source/Lib/CommonLib/CommonDef.h
with
39 additions
and
0 deletions
source/Lib/CommonLib/CommonDef.h
+
39
−
0
View file @
12713818
...
...
@@ -544,6 +544,45 @@ template <typename ValueType> inline ValueType rightShift (const ValueType
template
<
typename
ValueType
>
inline
ValueType
leftShift_round
(
const
ValueType
value
,
const
int
shift
)
{
return
(
shift
>=
0
)
?
(
value
<<
shift
)
:
((
value
+
(
ValueType
(
1
)
<<
(
-
shift
-
1
)))
>>
-
shift
);
}
template
<
typename
ValueType
>
inline
ValueType
rightShift_round
(
const
ValueType
value
,
const
int
shift
)
{
return
(
shift
>=
0
)
?
((
value
+
(
ValueType
(
1
)
<<
(
shift
-
1
)))
>>
shift
)
:
(
value
<<
-
shift
);
}
static
inline
int
floorLog2
(
uint32_t
x
)
{
if
(
x
==
0
)
{
return
-
1
;
}
#ifdef __GNUC__
return
31
-
__builtin_clz
(
x
);
#else
int
result
=
0
;
if
(
x
&
0xffff0000
)
{
x
>>=
16
;
result
+=
16
;
}
if
(
x
&
0xff00
)
{
x
>>=
8
;
result
+=
8
;
}
if
(
x
&
0xf0
)
{
x
>>=
4
;
result
+=
4
;
}
if
(
x
&
0xc
)
{
x
>>=
2
;
result
+=
2
;
}
if
(
x
&
0x2
)
{
x
>>=
1
;
result
+=
1
;
}
return
result
;
#endif
}
//CASE-BREAK for breakpoints
#if defined ( _MSC_VER ) && defined ( _DEBUG )
#define _CASE(_x) if(_x)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment