mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-11-24 01:59:18 +01:00
Various smaller code improvements (#1343)
This commit is contained in:
parent
adffd53dbd
commit
8508c62540
@ -222,7 +222,7 @@ if (ENABLE_CUBEB)
|
|||||||
option(BUILD_TOOLS "" OFF)
|
option(BUILD_TOOLS "" OFF)
|
||||||
option(BUNDLE_SPEEX "" OFF)
|
option(BUNDLE_SPEEX "" OFF)
|
||||||
set(USE_WINMM OFF CACHE BOOL "")
|
set(USE_WINMM OFF CACHE BOOL "")
|
||||||
add_subdirectory("dependencies/cubeb" EXCLUDE_FROM_ALL)
|
add_subdirectory("dependencies/cubeb" EXCLUDE_FROM_ALL SYSTEM)
|
||||||
set_property(TARGET cubeb PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
set_property(TARGET cubeb PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||||
add_library(cubeb::cubeb ALIAS cubeb)
|
add_library(cubeb::cubeb ALIAS cubeb)
|
||||||
endif()
|
endif()
|
||||||
|
@ -112,7 +112,7 @@ namespace nn
|
|||||||
|
|
||||||
nnResult _Async_OfflineDB_DownloadPostDataListParam_DownloadPostDataList(coreinit::OSEvent* event, DownloadedTopicData* downloadedTopicData, DownloadedPostData* downloadedPostData, uint32be* postCountOut, uint32 maxCount, DownloadPostDataListParam* param)
|
nnResult _Async_OfflineDB_DownloadPostDataListParam_DownloadPostDataList(coreinit::OSEvent* event, DownloadedTopicData* downloadedTopicData, DownloadedPostData* downloadedPostData, uint32be* postCountOut, uint32 maxCount, DownloadPostDataListParam* param)
|
||||||
{
|
{
|
||||||
scope_exit _se([&](){coreinit::OSSignalEvent(event);});
|
stdx::scope_exit _se([&](){coreinit::OSSignalEvent(event);});
|
||||||
|
|
||||||
uint64 titleId = CafeSystem::GetForegroundTitleId();
|
uint64 titleId = CafeSystem::GetForegroundTitleId();
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ namespace nn
|
|||||||
|
|
||||||
nnResult _Async_OfflineDB_DownloadPostDataListParam_DownloadExternalImageData(coreinit::OSEvent* event, DownloadedDataBase* _this, void* imageDataOut, uint32be* imageSizeOut, uint32 maxSize)
|
nnResult _Async_OfflineDB_DownloadPostDataListParam_DownloadExternalImageData(coreinit::OSEvent* event, DownloadedDataBase* _this, void* imageDataOut, uint32be* imageSizeOut, uint32 maxSize)
|
||||||
{
|
{
|
||||||
scope_exit _se([&](){coreinit::OSSignalEvent(event);});
|
stdx::scope_exit _se([&](){coreinit::OSSignalEvent(event);});
|
||||||
|
|
||||||
if (!_this->TestFlags(_this, DownloadedDataBase::FLAGS::HAS_EXTERNAL_IMAGE))
|
if (!_this->TestFlags(_this, DownloadedDataBase::FLAGS::HAS_EXTERNAL_IMAGE))
|
||||||
return OLV_RESULT_MISSING_DATA;
|
return OLV_RESULT_MISSING_DATA;
|
||||||
|
@ -1017,11 +1017,7 @@ namespace nsyshid
|
|||||||
std::array<uint8, 16> InfinityUSB::GenerateInfinityFigureKey(const std::vector<uint8>& sha1Data)
|
std::array<uint8, 16> InfinityUSB::GenerateInfinityFigureKey(const std::vector<uint8>& sha1Data)
|
||||||
{
|
{
|
||||||
std::array<uint8, 20> digest = {};
|
std::array<uint8, 20> digest = {};
|
||||||
SHA_CTX ctx;
|
SHA1(sha1Data.data(), sha1Data.size(), digest.data());
|
||||||
SHA1_Init(&ctx);
|
|
||||||
SHA1_Update(&ctx, sha1Data.data(), sha1Data.size());
|
|
||||||
SHA1_Final(digest.data(), &ctx);
|
|
||||||
OPENSSL_cleanse(&ctx, sizeof(ctx));
|
|
||||||
// Infinity AES keys are the first 16 bytes of the SHA1 Digest, every set of 4 bytes need to be
|
// Infinity AES keys are the first 16 bytes of the SHA1 Digest, every set of 4 bytes need to be
|
||||||
// reversed due to endianness
|
// reversed due to endianness
|
||||||
std::array<uint8, 16> key = {};
|
std::array<uint8, 16> key = {};
|
||||||
|
@ -509,7 +509,7 @@ namespace ntag
|
|||||||
noftHeader->writeCount = _swapEndianU16(_swapEndianU16(noftHeader->writeCount) + 1);
|
noftHeader->writeCount = _swapEndianU16(_swapEndianU16(noftHeader->writeCount) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(decryptedBuffer + 0x20, noftHeader, sizeof(noftHeader));
|
memcpy(decryptedBuffer + 0x20, noftHeader, sizeof(NTAGNoftHeader));
|
||||||
memcpy(decryptedBuffer + _swapEndianU16(rwHeader->offset), data, dataSize);
|
memcpy(decryptedBuffer + _swapEndianU16(rwHeader->offset), data, dataSize);
|
||||||
|
|
||||||
// Encrypt
|
// Encrypt
|
||||||
|
@ -522,10 +522,10 @@ namespace snd_core
|
|||||||
// called periodically to check for AX updates
|
// called periodically to check for AX updates
|
||||||
void AXOut_update()
|
void AXOut_update()
|
||||||
{
|
{
|
||||||
constexpr auto kTimeout = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(((IAudioAPI::kBlockCount * 3) / 4) * (AX_FRAMES_PER_GROUP * 3)));
|
constexpr static auto kTimeout = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(((IAudioAPI::kBlockCount * 3) / 4) * (AX_FRAMES_PER_GROUP * 3)));
|
||||||
constexpr auto kWaitDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(3));
|
constexpr static auto kWaitDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(3));
|
||||||
constexpr auto kWaitDurationFast = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::microseconds(2900));
|
constexpr static auto kWaitDurationFast = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::microseconds(2900));
|
||||||
constexpr auto kWaitDurationMinimum = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::microseconds(1700));
|
constexpr static auto kWaitDurationMinimum = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::microseconds(1700));
|
||||||
|
|
||||||
// if we haven't buffered any blocks, we will wait less time than usual
|
// if we haven't buffered any blocks, we will wait less time than usual
|
||||||
bool additional_blocks_required = false;
|
bool additional_blocks_required = false;
|
||||||
|
@ -14,25 +14,27 @@ extern uint8* PPCInterpreterGetStackPointer();
|
|||||||
extern uint8* PPCInterpreter_PushAndReturnStackPointer(sint32 offset);
|
extern uint8* PPCInterpreter_PushAndReturnStackPointer(sint32 offset);
|
||||||
extern void PPCInterpreterModifyStackPointer(sint32 offset);
|
extern void PPCInterpreterModifyStackPointer(sint32 offset);
|
||||||
|
|
||||||
class MEMPTRBase {};
|
class MEMPTRBase
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class MEMPTR : MEMPTRBase
|
class MEMPTR : MEMPTRBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr MEMPTR()
|
constexpr MEMPTR() noexcept
|
||||||
: m_value(0) { }
|
: m_value(0) {}
|
||||||
|
|
||||||
explicit constexpr MEMPTR(uint32 offset)
|
explicit constexpr MEMPTR(uint32 offset) noexcept
|
||||||
: m_value(offset) { }
|
: m_value(offset) {}
|
||||||
|
|
||||||
explicit constexpr MEMPTR(const uint32be& offset)
|
explicit constexpr MEMPTR(const uint32be& offset) noexcept
|
||||||
: m_value(offset) { }
|
: m_value(offset) {}
|
||||||
|
|
||||||
constexpr MEMPTR(std::nullptr_t)
|
constexpr MEMPTR(std::nullptr_t) noexcept
|
||||||
: m_value(0) { }
|
: m_value(0) {}
|
||||||
|
|
||||||
MEMPTR(T* ptr)
|
MEMPTR(T* ptr) noexcept
|
||||||
{
|
{
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
m_value = 0;
|
m_value = 0;
|
||||||
@ -43,28 +45,23 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr MEMPTR(const MEMPTR& memptr)
|
constexpr MEMPTR(const MEMPTR&) noexcept = default;
|
||||||
: m_value(memptr.m_value) { }
|
|
||||||
|
|
||||||
constexpr MEMPTR& operator=(const MEMPTR& memptr)
|
constexpr MEMPTR& operator=(const MEMPTR&) noexcept = default;
|
||||||
{
|
|
||||||
m_value = memptr.m_value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr MEMPTR& operator=(const uint32& offset)
|
constexpr MEMPTR& operator=(const uint32& offset) noexcept
|
||||||
{
|
{
|
||||||
m_value = offset;
|
m_value = offset;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr MEMPTR& operator=(const std::nullptr_t rhs)
|
constexpr MEMPTR& operator=(std::nullptr_t) noexcept
|
||||||
{
|
{
|
||||||
m_value = 0;
|
m_value = 0;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEMPTR& operator=(T* ptr)
|
MEMPTR& operator=(T* ptr) noexcept
|
||||||
{
|
{
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
m_value = 0;
|
m_value = 0;
|
||||||
@ -76,75 +73,116 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool atomic_compare_exchange(T* comparePtr, T* newPtr)
|
bool atomic_compare_exchange(T* comparePtr, T* newPtr) noexcept
|
||||||
{
|
{
|
||||||
MEMPTR<T> mp_compare = comparePtr;
|
MEMPTR<T> mp_compare = comparePtr;
|
||||||
MEMPTR<T> mp_new = newPtr;
|
MEMPTR<T> mp_new = newPtr;
|
||||||
std::atomic<uint32be>* thisValueAtomic = (std::atomic<uint32be>*)&m_value;
|
auto* thisValueAtomic = reinterpret_cast<std::atomic<uint32be>*>(&m_value);
|
||||||
return thisValueAtomic->compare_exchange_strong(mp_compare.m_value, mp_new.m_value);
|
return thisValueAtomic->compare_exchange_strong(mp_compare.m_value, mp_new.m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit constexpr operator bool() const noexcept { return m_value != 0; }
|
explicit constexpr operator bool() const noexcept
|
||||||
|
{
|
||||||
|
return m_value != 0;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr operator T*() const noexcept { return GetPtr(); } // allow implicit cast to wrapped pointer type
|
// allow implicit cast to wrapped pointer type
|
||||||
|
constexpr operator T*() const noexcept
|
||||||
|
{
|
||||||
|
return GetPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename X>
|
||||||
|
explicit operator MEMPTR<X>() const noexcept
|
||||||
|
{
|
||||||
|
return MEMPTR<X>(this->m_value);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename X>
|
MEMPTR operator+(const MEMPTR& ptr) noexcept
|
||||||
explicit operator MEMPTR<X>() const { return MEMPTR<X>(this->m_value); }
|
{
|
||||||
|
return MEMPTR(this->GetMPTR() + ptr.GetMPTR());
|
||||||
|
}
|
||||||
|
MEMPTR operator-(const MEMPTR& ptr) noexcept
|
||||||
|
{
|
||||||
|
return MEMPTR(this->GetMPTR() - ptr.GetMPTR());
|
||||||
|
}
|
||||||
|
|
||||||
MEMPTR operator+(const MEMPTR& ptr) { return MEMPTR(this->GetMPTR() + ptr.GetMPTR()); }
|
MEMPTR operator+(sint32 v) noexcept
|
||||||
MEMPTR operator-(const MEMPTR& ptr) { return MEMPTR(this->GetMPTR() - ptr.GetMPTR()); }
|
|
||||||
|
|
||||||
MEMPTR operator+(sint32 v)
|
|
||||||
{
|
{
|
||||||
// pointer arithmetic
|
// pointer arithmetic
|
||||||
return MEMPTR(this->GetMPTR() + v * 4);
|
return MEMPTR(this->GetMPTR() + v * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEMPTR operator-(sint32 v)
|
MEMPTR operator-(sint32 v) noexcept
|
||||||
{
|
{
|
||||||
// pointer arithmetic
|
// pointer arithmetic
|
||||||
return MEMPTR(this->GetMPTR() - v * 4);
|
return MEMPTR(this->GetMPTR() - v * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEMPTR& operator+=(sint32 v)
|
MEMPTR& operator+=(sint32 v) noexcept
|
||||||
{
|
{
|
||||||
m_value += v * sizeof(T);
|
m_value += v * sizeof(T);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Q = T>
|
template<typename Q = T>
|
||||||
typename std::enable_if<!std::is_same<Q, void>::value, Q>::type&
|
std::enable_if_t<!std::is_same_v<Q, void>, Q>& operator*() const noexcept
|
||||||
operator*() const { return *GetPtr(); }
|
{
|
||||||
|
return *GetPtr();
|
||||||
|
}
|
||||||
|
|
||||||
T* operator->() const { return GetPtr(); }
|
constexpr T* operator->() const noexcept
|
||||||
|
{
|
||||||
|
return GetPtr();
|
||||||
|
}
|
||||||
|
|
||||||
template <class Q = T>
|
template<typename Q = T>
|
||||||
typename std::enable_if<!std::is_same<Q, void>::value, Q>::type&
|
std::enable_if_t<!std::is_same_v<Q, void>, Q>& operator[](int index) noexcept
|
||||||
operator[](int index) { return GetPtr()[index]; }
|
{
|
||||||
|
return GetPtr()[index];
|
||||||
|
}
|
||||||
|
|
||||||
T* GetPtr() const { return (T*)(m_value == 0 ? nullptr : memory_base + (uint32)m_value); }
|
T* GetPtr() const noexcept
|
||||||
|
{
|
||||||
|
return (T*)(m_value == 0 ? nullptr : memory_base + (uint32)m_value);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename C>
|
template<typename C>
|
||||||
C* GetPtr() const { return (C*)(GetPtr()); }
|
C* GetPtr() const noexcept
|
||||||
|
{
|
||||||
|
return static_cast<C*>(GetPtr());
|
||||||
|
}
|
||||||
|
|
||||||
constexpr uint32 GetMPTR() const { return m_value.value(); }
|
[[nodiscard]] constexpr uint32 GetMPTR() const noexcept
|
||||||
constexpr const uint32be& GetBEValue() const { return m_value; }
|
{
|
||||||
|
return m_value.value();
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const uint32be& GetBEValue() const noexcept
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr bool IsNull() const { return m_value == 0; }
|
[[nodiscard]] constexpr bool IsNull() const noexcept
|
||||||
|
{
|
||||||
|
return m_value == 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32be m_value;
|
uint32be m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(MEMPTR<void*>) == sizeof(uint32be));
|
static_assert(sizeof(MEMPTR<void*>) == sizeof(uint32be));
|
||||||
|
static_assert(std::is_trivially_copyable_v<MEMPTR<void*>>);
|
||||||
|
|
||||||
#include "StackAllocator.h"
|
#include "StackAllocator.h"
|
||||||
#include "SysAllocator.h"
|
#include "SysAllocator.h"
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct fmt::formatter<MEMPTR<T>> : formatter<string_view>
|
struct fmt::formatter<MEMPTR<T>> : formatter<string_view>
|
||||||
{
|
{
|
||||||
template <typename FormatContext>
|
template<typename FormatContext>
|
||||||
auto format(const MEMPTR<T>& v, FormatContext& ctx) const -> format_context::iterator { return fmt::format_to(ctx.out(), "{:#x}", v.GetMPTR()); }
|
auto format(const MEMPTR<T>& v, FormatContext& ctx) const -> format_context::iterator
|
||||||
|
{
|
||||||
|
return fmt::format_to(ctx.out(), "{:#x}", v.GetMPTR());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -394,16 +394,10 @@ void vectorRemoveByIndex(std::vector<T>& vec, const size_t index)
|
|||||||
vec.erase(vec.begin() + index);
|
vec.erase(vec.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename... Types>
|
||||||
int match_any_of(T1 value, T2 compareTo)
|
bool match_any_of(T1&& value, Types&&... others)
|
||||||
{
|
{
|
||||||
return value == compareTo;
|
return ((value == others) || ...);
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T1, typename T2, typename... Types>
|
|
||||||
bool match_any_of(T1 value, T2 compareTo, Types&&... others)
|
|
||||||
{
|
|
||||||
return value == compareTo || match_any_of(value, others...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we cache the frequency in a static variable
|
// we cache the frequency in a static variable
|
||||||
@ -501,13 +495,6 @@ bool future_is_ready(std::future<T>& f)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace with std::scope_exit once available
|
|
||||||
struct scope_exit
|
|
||||||
{
|
|
||||||
std::function<void()> f_;
|
|
||||||
explicit scope_exit(std::function<void()> f) noexcept : f_(std::move(f)) {}
|
|
||||||
~scope_exit() { if (f_) f_(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// helper function to cast raw pointers to std::atomic
|
// helper function to cast raw pointers to std::atomic
|
||||||
// this is technically not legal but works on most platforms as long as alignment restrictions are met and the implementation of atomic doesnt come with additional members
|
// this is technically not legal but works on most platforms as long as alignment restrictions are met and the implementation of atomic doesnt come with additional members
|
||||||
@ -515,6 +502,8 @@ struct scope_exit
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
std::atomic<T>* _rawPtrToAtomic(T* ptr)
|
std::atomic<T>* _rawPtrToAtomic(T* ptr)
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof(T) == sizeof(std::atomic<T>));
|
||||||
|
cemu_assert_debug((reinterpret_cast<std::uintptr_t>(ptr) % alignof(std::atomic<T>)) == 0);
|
||||||
return reinterpret_cast<std::atomic<T>*>(ptr);
|
return reinterpret_cast<std::atomic<T>*>(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,13 +567,34 @@ struct fmt::formatter<betype<T>> : fmt::formatter<T>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// useful C++23 stuff that isn't yet widely supported
|
// useful future C++ stuff
|
||||||
|
|
||||||
// std::to_underlying
|
|
||||||
namespace stdx
|
namespace stdx
|
||||||
{
|
{
|
||||||
|
// std::to_underlying
|
||||||
template <typename EnumT, typename = std::enable_if_t < std::is_enum<EnumT>{} >>
|
template <typename EnumT, typename = std::enable_if_t < std::is_enum<EnumT>{} >>
|
||||||
constexpr std::underlying_type_t<EnumT> to_underlying(EnumT e) noexcept {
|
constexpr std::underlying_type_t<EnumT> to_underlying(EnumT e) noexcept {
|
||||||
return static_cast<std::underlying_type_t<EnumT>>(e);
|
return static_cast<std::underlying_type_t<EnumT>>(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// std::scope_exit
|
||||||
|
template <typename Fn>
|
||||||
|
class scope_exit
|
||||||
|
{
|
||||||
|
Fn m_func;
|
||||||
|
bool m_released = false;
|
||||||
|
public:
|
||||||
|
explicit scope_exit(Fn&& f) noexcept
|
||||||
|
: m_func(std::forward<Fn>(f))
|
||||||
|
{}
|
||||||
|
~scope_exit()
|
||||||
|
{
|
||||||
|
if (!m_released) m_func();
|
||||||
|
}
|
||||||
|
scope_exit(scope_exit&& other) noexcept
|
||||||
|
: m_func(std::move(other.m_func)), m_released(std::exchange(other.m_released, true))
|
||||||
|
{}
|
||||||
|
scope_exit(const scope_exit&) = delete;
|
||||||
|
scope_exit& operator=(scope_exit) = delete;
|
||||||
|
void release() { m_released = true;}
|
||||||
|
};
|
||||||
}
|
}
|
@ -15,6 +15,9 @@
|
|||||||
#if BOOST_OS_LINUX && HAS_WAYLAND
|
#if BOOST_OS_LINUX && HAS_WAYLAND
|
||||||
#include "gui/helpers/wxWayland.h"
|
#include "gui/helpers/wxWayland.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if __WXGTK__
|
||||||
|
#include <glib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <wx/image.h>
|
#include <wx/image.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
@ -50,7 +50,6 @@ add_library(CemuUtil
|
|||||||
MemMapper/MemMapper.h
|
MemMapper/MemMapper.h
|
||||||
SystemInfo/SystemInfo.cpp
|
SystemInfo/SystemInfo.cpp
|
||||||
SystemInfo/SystemInfo.h
|
SystemInfo/SystemInfo.h
|
||||||
ThreadPool/ThreadPool.cpp
|
|
||||||
ThreadPool/ThreadPool.h
|
ThreadPool/ThreadPool.h
|
||||||
tinyxml2/tinyxml2.cpp
|
tinyxml2/tinyxml2.cpp
|
||||||
tinyxml2/tinyxml2.h
|
tinyxml2/tinyxml2.h
|
||||||
|
@ -194,7 +194,7 @@ namespace robin_hood {
|
|||||||
|
|
||||||
// workaround missing "is_trivially_copyable" in g++ < 5.0
|
// workaround missing "is_trivially_copyable" in g++ < 5.0
|
||||||
// See https://stackoverflow.com/a/31798726/48181
|
// See https://stackoverflow.com/a/31798726/48181
|
||||||
#if defined(__GNUC__) && __GNUC__ < 5
|
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
|
||||||
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__)
|
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value
|
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value
|
||||||
|
@ -1,29 +1,6 @@
|
|||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
constexpr uint32 Crc32Lookup[8][256] =
|
||||||
#define __LITTLE_ENDIAN 1234
|
|
||||||
#define __BIG_ENDIAN 4321
|
|
||||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
|
||||||
|
|
||||||
#include <xmmintrin.h>
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
#define PREFETCH(location) __builtin_prefetch(location)
|
|
||||||
#else
|
|
||||||
#define PREFETCH(location) _mm_prefetch(location, _MM_HINT_T0)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
// defines __BYTE_ORDER as __LITTLE_ENDIAN or __BIG_ENDIAN
|
|
||||||
#include <sys/param.h>
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define PREFETCH(location) __builtin_prefetch(location)
|
|
||||||
#else
|
|
||||||
// no prefetching
|
|
||||||
#define PREFETCH(location) ;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned int Crc32Lookup[8][256] =
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,
|
0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,
|
||||||
@ -301,20 +278,7 @@ unsigned int Crc32Lookup[8][256] =
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// swap endianess
|
uint32 crc32_calc_slice_by_8(uint32 previousCrc32, const void* data, size_t length)
|
||||||
static inline uint32_t swap(uint32_t x)
|
|
||||||
{
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
|
||||||
return __builtin_bswap32(x);
|
|
||||||
#else
|
|
||||||
return (x >> 24) |
|
|
||||||
((x >> 8) & 0x0000FF00) |
|
|
||||||
((x << 8) & 0x00FF0000) |
|
|
||||||
(x << 24);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crc32_calc_slice_by_8(unsigned int previousCrc32, const void* data, int length)
|
|
||||||
{
|
{
|
||||||
uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
|
uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
|
||||||
const uint32_t* current = (const uint32_t*)data;
|
const uint32_t* current = (const uint32_t*)data;
|
||||||
@ -323,7 +287,7 @@ unsigned int crc32_calc_slice_by_8(unsigned int previousCrc32, const void* data,
|
|||||||
while (length >= 8)
|
while (length >= 8)
|
||||||
{
|
{
|
||||||
if constexpr (std::endian::native == std::endian::big){
|
if constexpr (std::endian::native == std::endian::big){
|
||||||
uint32_t one = *current++ ^ swap(crc);
|
uint32_t one = *current++ ^ _swapEndianU32(crc);
|
||||||
uint32_t two = *current++;
|
uint32_t two = *current++;
|
||||||
crc = Crc32Lookup[0][two & 0xFF] ^
|
crc = Crc32Lookup[0][two & 0xFF] ^
|
||||||
Crc32Lookup[1][(two >> 8) & 0xFF] ^
|
Crc32Lookup[1][(two >> 8) & 0xFF] ^
|
||||||
@ -348,13 +312,14 @@ unsigned int crc32_calc_slice_by_8(unsigned int previousCrc32, const void* data,
|
|||||||
Crc32Lookup[7][one & 0xFF];
|
Crc32Lookup[7][one & 0xFF];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cemu_assert(false);
|
static_assert(std::endian::native == std::endian::big || std::endian::native == std::endian::little,
|
||||||
|
"Platform byte-order is unsupported");
|
||||||
}
|
}
|
||||||
|
|
||||||
length -= 8;
|
length -= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t* currentChar = (const uint8_t*)current;
|
const uint8* currentChar = (const uint8*)current;
|
||||||
// remaining 1 to 7 bytes (standard algorithm)
|
// remaining 1 to 7 bytes (standard algorithm)
|
||||||
while (length-- != 0)
|
while (length-- != 0)
|
||||||
crc = (crc >> 8) ^ Crc32Lookup[0][(crc & 0xFF) ^ *currentChar++];
|
crc = (crc >> 8) ^ Crc32Lookup[0][(crc & 0xFF) ^ *currentChar++];
|
||||||
@ -362,20 +327,20 @@ unsigned int crc32_calc_slice_by_8(unsigned int previousCrc32, const void* data,
|
|||||||
return ~crc; // same as crc ^ 0xFFFFFFFF
|
return ~crc; // same as crc ^ 0xFFFFFFFF
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int crc32_calc(unsigned int c, const void* data, int length)
|
uint32 crc32_calc(uint32 c, const void* data, size_t length)
|
||||||
{
|
{
|
||||||
if (length >= 16)
|
if (length >= 16)
|
||||||
{
|
{
|
||||||
return crc32_calc_slice_by_8(c, data, length);
|
return crc32_calc_slice_by_8(c, data, length);
|
||||||
}
|
}
|
||||||
unsigned char* p = (unsigned char*)data;
|
const uint8* p = (const uint8*)data;
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return c;
|
return c;
|
||||||
c ^= 0xFFFFFFFF;
|
c ^= 0xFFFFFFFF;
|
||||||
while (length)
|
while (length)
|
||||||
{
|
{
|
||||||
unsigned char temp = *p;
|
uint8 temp = *p;
|
||||||
temp ^= (unsigned char)c;
|
temp ^= (uint8)c;
|
||||||
c = (c >> 8) ^ Crc32Lookup[0][temp];
|
c = (c >> 8) ^ Crc32Lookup[0][temp];
|
||||||
// next
|
// next
|
||||||
length--;
|
length--;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
unsigned int crc32_calc(unsigned int c, const void* data, int length);
|
uint32 crc32_calc(uint32 c, const void* data, size_t length);
|
||||||
|
|
||||||
inline unsigned int crc32_calc(const void* data, int length)
|
inline uint32 crc32_calc(const void* data, size_t length)
|
||||||
{
|
{
|
||||||
return crc32_calc(0, data, length);
|
return crc32_calc(0, data, length);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user