2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2012-03-21 08:44:43 +01:00
|
|
|
|
2023-03-06 18:27:16 +01:00
|
|
|
#pragma once
|
2012-03-21 08:44:43 +01:00
|
|
|
|
2023-03-06 18:27:16 +01:00
|
|
|
#include <cstddef>
|
2020-03-13 01:08:53 +01:00
|
|
|
#include <cstdint>
|
2012-03-21 08:44:43 +01:00
|
|
|
|
2020-02-05 19:51:46 +01:00
|
|
|
/**
|
|
|
|
* @see http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv
|
|
|
|
*/
|
2023-03-06 18:27:16 +01:00
|
|
|
constexpr std::byte
|
|
|
|
BitReverseMultiplyModulus(std::byte _in) noexcept
|
2020-02-05 19:51:46 +01:00
|
|
|
{
|
2023-03-06 18:27:16 +01:00
|
|
|
uint64_t in = static_cast<uint64_t>(_in);
|
|
|
|
return static_cast<std::byte>((in * 0x0202020202ULL & 0x010884422010ULL) % 1023);
|
2020-02-05 19:51:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 {
|
2023-03-06 18:27:16 +01:00
|
|
|
std::byte data[256];
|
2020-02-05 19:51:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const BitReverseTable bit_reverse_table;
|
2012-03-21 08:44:43 +01:00
|
|
|
|
2021-10-13 11:28:04 +02:00
|
|
|
[[gnu::const]]
|
2023-03-06 18:27:16 +01:00
|
|
|
static inline std::byte
|
|
|
|
BitReverse(std::byte x) noexcept
|
2012-03-21 08:44:43 +01:00
|
|
|
{
|
2023-03-06 18:27:16 +01:00
|
|
|
return bit_reverse_table.data[static_cast<std::size_t>(x)];
|
2012-03-21 08:44:43 +01:00
|
|
|
}
|