vfs: expand support for NCA reading
This commit is contained in:
parent
a8c4f01f6c
commit
86f6b6b7b2
75 changed files with 8055 additions and 1043 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <bit>
|
||||
#include <cstddef>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
|
@ -10,7 +11,7 @@
|
|||
namespace Common {
|
||||
|
||||
template <typename T>
|
||||
requires std::is_unsigned_v<T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T AlignUp(T value, size_t size) {
|
||||
auto mod{static_cast<T>(value % size)};
|
||||
value -= mod;
|
||||
|
@ -24,7 +25,7 @@ template <typename T>
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_unsigned_v<T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T AlignDown(T value, size_t size) {
|
||||
return static_cast<T>(value - value % size);
|
||||
}
|
||||
|
@ -55,6 +56,30 @@ template <typename T, typename U>
|
|||
return (x + (y - 1)) / y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T LeastSignificantOneBit(T x) {
|
||||
return x & ~(x - 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T ResetLeastSignificantOneBit(T x) {
|
||||
return x & (x - 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr bool IsPowerOfTwo(T x) {
|
||||
return x > 0 && ResetLeastSignificantOneBit(x) == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T FloorPowerOfTwo(T x) {
|
||||
return T{1} << (sizeof(T) * 8 - std::countl_zero(x) - 1);
|
||||
}
|
||||
|
||||
template <typename T, size_t Align = 16>
|
||||
class AlignmentAllocator {
|
||||
public:
|
||||
|
|
|
@ -71,4 +71,10 @@ std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed, std::size_t un
|
|||
return uncompressed;
|
||||
}
|
||||
|
||||
int DecompressLZ4(void* dst, size_t dst_size, const void* src, size_t src_size) {
|
||||
// This is just a thin wrapper around LZ4.
|
||||
return LZ4_decompress_safe(reinterpret_cast<const char*>(src), reinterpret_cast<char*>(dst),
|
||||
static_cast<int>(src_size), static_cast<int>(dst_size));
|
||||
}
|
||||
|
||||
} // namespace Common::Compression
|
||||
|
|
|
@ -56,4 +56,6 @@ namespace Common::Compression {
|
|||
[[nodiscard]] std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed,
|
||||
std::size_t uncompressed_size);
|
||||
|
||||
int DecompressLZ4(void* dst, size_t dst_size, const void* src, size_t src_size);
|
||||
|
||||
} // namespace Common::Compression
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue