Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
2d3b5166
Commit
2d3b5166
authored
Feb 05, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/BitReverse: generate table with constexpr function
Get rid of the macro hell.
parent
7b03f55c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
11 deletions
+28
-11
BitReverse.cxx
src/util/BitReverse.cxx
+9
-9
BitReverse.hxx
src/util/BitReverse.hxx
+19
-2
No files found.
src/util/BitReverse.cxx
View file @
2d3b5166
...
...
@@ -19,13 +19,13 @@
#include "BitReverse.hxx"
/**
* @see http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
*/
const
uint8_t
bit_reverse_table
[
256
]
=
static
constexpr
BitReverseTable
GenerateBitReverseTable
()
noexcept
{
#define R2(n) n, n + 2*64, n + 1*64, n + 3*64
#define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16)
#define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 )
R6
(
0
),
R6
(
2
),
R6
(
1
),
R6
(
3
)
};
BitReverseTable
table
{};
for
(
unsigned
i
=
0
;
i
<
256
;
++
i
)
table
.
data
[
i
]
=
BitReverseMultiplyModulus
(
i
);
return
table
;
}
const
BitReverseTable
bit_reverse_table
=
GenerateBitReverseTable
();
src/util/BitReverse.hxx
View file @
2d3b5166
...
...
@@ -24,13 +24,30 @@
#include <stdint.h>
extern
const
uint8_t
bit_reverse_table
[
256
];
/**
* @see http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv
*/
constexpr
uint8_t
BitReverseMultiplyModulus
(
uint8_t
_in
)
noexcept
{
uint64_t
in
=
_in
;
return
uint8_t
((
in
*
0x0202020202ULL
&
0x010884422010ULL
)
%
1023
);
}
/* in order to avoid including <array> in this header, this `struct`
is a workaround for GenerateBitReverseTable() being able to return
the plain array */
struct
BitReverseTable
{
uint8_t
data
[
256
];
};
extern
const
BitReverseTable
bit_reverse_table
;
gcc_const
static
inline
uint8_t
bit_reverse
(
uint8_t
x
)
noexcept
{
return
bit_reverse_table
[
x
];
return
bit_reverse_table
.
data
[
x
];
}
#endif
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