diff --git a/.gitignore b/.gitignore index 93d2b94e..85a59243 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ build/ out/ .cache/ +bin/Cemu # Cemu bin files bin/otp.bin diff --git a/dependencies/ih264d/decoder/x86/ih264d_function_selector.c b/dependencies/ih264d/decoder/x86/ih264d_function_selector.c index 8b4b0ca3..6f3119db 100644 --- a/dependencies/ih264d/decoder/x86/ih264d_function_selector.c +++ b/dependencies/ih264d/decoder/x86/ih264d_function_selector.c @@ -77,7 +77,7 @@ void ih264d_init_function_ptr(dec_struct_t *ps_codec) } } -#ifdef __clang__ +#ifdef __GNUC__ #include void __cpuid2(signed int* cpuInfo, unsigned int level) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index adebc32c..fd2c4add 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,11 +25,14 @@ elseif(UNIX) add_definitions(-DVK_USE_PLATFORM_XCB_KHR) endif() add_definitions(-fms-extensions) - add_definitions(-fms-compatibility-version=19.14) - add_definitions(-fdelayed-template-parsing) + add_definitions(-fpermissive) add_definitions(-maes) # warnings - add_compile_options(-Wno-switch -Wno-ignored-attributes -Wno-deprecated-enum-enum-conversion -Wno-ambiguous-reversed-operator) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wno-ambiguous-reversed-operator) + endif() + + add_compile_options(-Wno-switch -Wno-ignored-attributes -Wno-deprecated-enum-enum-conversion) endif() add_definitions(-DVK_NO_PROTOTYPES) diff --git a/src/Cafe/Account/Account.cpp b/src/Cafe/Account/Account.cpp index 2bbd35a2..bf049bf6 100644 --- a/src/Cafe/Account/Account.cpp +++ b/src/Cafe/Account/Account.cpp @@ -417,7 +417,7 @@ fs::path Account::GetFileName(uint32 persistent_id) if (persistent_id < kMinPersistendId) throw std::invalid_argument(fmt::format("persistent id {:#x} is invalid", persistent_id)); - return CemuApp::GetMLCPath(fmt::format(L"usr\\save\\system\\act\\{:08x}\\account.dat", persistent_id)).ToStdWstring(); + return CemuApp::GetMLCPath(fmt::format(L"usr/save/system/act/{:08x}/account.dat", persistent_id)).ToStdWstring(); } OnlineValidator Account::ValidateOnlineFiles() const diff --git a/src/Cafe/CMakeLists.txt b/src/Cafe/CMakeLists.txt index ff0f3e11..ae0b3e60 100644 --- a/src/Cafe/CMakeLists.txt +++ b/src/Cafe/CMakeLists.txt @@ -1,6 +1,11 @@ project(CemuCafe) include_directories(".") + +if((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR (CMAKE_C_COMPILER_ID STREQUAL "Clang")) + add_compile_options(-mssse3 -mavx2) +endif() + file(GLOB_RECURSE CPP_FILES *.cpp) file(GLOB_RECURSE H_FILES *.h) add_library(CemuCafe ${CPP_FILES} ${H_FILES}) @@ -23,7 +28,6 @@ target_link_libraries(CemuCafe glslang SPIRV) target_link_libraries(CemuCafe ih264d zarchive) #target_link_libraries(CemuCafe zstd::libzstd_static) - IF(WIN32) target_link_libraries(CemuCafe iphlpapi) ENDIF() \ No newline at end of file diff --git a/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp b/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp index c130ec8f..2d808fef 100644 --- a/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp +++ b/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterMain.cpp @@ -34,7 +34,7 @@ PPCInterpreter_t* PPCInterpreter_getCurrentInstance() return ppcInterpreterCurrentInstance; } -__declspec(noinline) uint64 PPCInterpreter_getMainCoreCycleCounter() +uint64 PPCInterpreter_getMainCoreCycleCounter() { return PPCTimer_getFromRDTSC(); } diff --git a/src/Cafe/HW/Espresso/PPCTimer.cpp b/src/Cafe/HW/Espresso/PPCTimer.cpp index cf0b60ef..8e1ed136 100644 --- a/src/Cafe/HW/Espresso/PPCTimer.cpp +++ b/src/Cafe/HW/Espresso/PPCTimer.cpp @@ -5,13 +5,6 @@ #include "util/helpers/fspinlock.h" #include "util/highresolutiontimer/HighResolutionTimer.h" -#if BOOST_OS_LINUX || BOOST_OS_MACOS -static __inline__ -unsigned __int64 _umul128(unsigned __int64, - unsigned __int64, - unsigned __int64*); -#endif - uint64 _rdtscLastMeasure = 0; uint64 _rdtscFrequency = 0; @@ -49,7 +42,7 @@ uint64 PPCTimer_estimateRDTSCFrequency() forceLog_printf("Invariant TSC not supported"); _mm_mfence(); - unsigned __int64 tscStart = __rdtsc(); + uint64 tscStart = __rdtsc(); unsigned int startTime = GetTickCount(); HRTick startTick = HighResolutionTimer::now().getTick(); // wait roughly 3 seconds @@ -61,7 +54,7 @@ uint64 PPCTimer_estimateRDTSCFrequency() } _mm_mfence(); HRTick stopTick = HighResolutionTimer::now().getTick(); - unsigned __int64 tscEnd = __rdtsc(); + uint64 tscEnd = __rdtsc(); // derive frequency approximation from measured time difference uint64 tsc_diff = tscEnd - tscStart; uint64 hrtFreq = 0; diff --git a/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.h b/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.h index 9663c2a4..ee0454ce 100644 --- a/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.h +++ b/src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.h @@ -345,20 +345,20 @@ typedef struct PPCRecFunction_t* ppcRecompilerFuncTable[PPC_REC_ALIGN_TO_4MB(PPC_REC_CODE_AREA_SIZE/4)]; // one virtual-function pointer for each potential ppc instruction PPCREC_JUMP_ENTRY ppcRecompilerDirectJumpTable[PPC_REC_ALIGN_TO_4MB(PPC_REC_CODE_AREA_SIZE/4)]; // lookup table for ppc offset to native code function // x64 data - uint64 __declspec(align(16)) _x64XMM_xorNegateMaskBottom[2]; - uint64 __declspec(align(16)) _x64XMM_xorNegateMaskPair[2]; - uint64 __declspec(align(16)) _x64XMM_xorNOTMask[2]; - uint64 __declspec(align(16)) _x64XMM_andAbsMaskBottom[2]; - uint64 __declspec(align(16)) _x64XMM_andAbsMaskPair[2]; - uint32 __declspec(align(16)) _x64XMM_andFloatAbsMaskBottom[4]; - uint64 __declspec(align(16)) _x64XMM_singleWordMask[2]; - double __declspec(align(16)) _x64XMM_constDouble1_1[2]; - double __declspec(align(16)) _x64XMM_constDouble0_0[2]; - float __declspec(align(16)) _x64XMM_constFloat0_0[2]; - float __declspec(align(16)) _x64XMM_constFloat1_1[2]; - float __declspec(align(16)) _x64XMM_constFloatMin[2]; - uint32 __declspec(align(16)) _x64XMM_flushDenormalMask1[4]; - uint32 __declspec(align(16)) _x64XMM_flushDenormalMaskResetSignBits[4]; + alignas(16) uint64 _x64XMM_xorNegateMaskBottom[2]; + alignas(16) uint64 _x64XMM_xorNegateMaskPair[2]; + alignas(16) uint64 _x64XMM_xorNOTMask[2]; + alignas(16) uint64 _x64XMM_andAbsMaskBottom[2]; + alignas(16) uint64 _x64XMM_andAbsMaskPair[2]; + alignas(16) uint32 _x64XMM_andFloatAbsMaskBottom[4]; + alignas(16) uint64 _x64XMM_singleWordMask[2]; + alignas(16) double _x64XMM_constDouble1_1[2]; + alignas(16) double _x64XMM_constDouble0_0[2]; + alignas(16) float _x64XMM_constFloat0_0[2]; + alignas(16) float _x64XMM_constFloat1_1[2]; + alignas(16) float _x64XMM_constFloatMin[2]; + alignas(16) uint32 _x64XMM_flushDenormalMask1[4]; + alignas(16) uint32 _x64XMM_flushDenormalMaskResetSignBits[4]; // PSQ load/store scale tables double _psq_ld_scale_ps0_ps1[64 * 2]; double _psq_ld_scale_ps0_1[64 * 2]; @@ -396,4 +396,4 @@ extern bool hasAVXSupport; void PPCRecompiler_recompileIfUnvisited(uint32 enterAddress); void PPCRecompiler_attemptEnter(struct PPCInterpreter_t* hCPU, uint32 enterAddress); -void PPCRecompiler_attemptEnterWithoutRecompile(struct PPCInterpreter_t* hCPU, uint32 enterAddress); \ No newline at end of file +void PPCRecompiler_attemptEnterWithoutRecompile(struct PPCInterpreter_t* hCPU, uint32 enterAddress); diff --git a/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp b/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp index cda0e60a..8e8a63d9 100644 --- a/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp +++ b/src/Cafe/HW/Espresso/Recompiler/PPCRecompilerX64.cpp @@ -2221,7 +2221,10 @@ void PPCRecompilerX64Gen_imlInstruction_r_name(PPCRecFunction_t* PPCRecFunction, else if (sprIndex == SPR_XER) x64Emit_mov_reg64_mem32(x64GenContext, tempToRealRegister(imlInstruction->op_r_name.registerIndex), REG_RSP, offsetof(PPCInterpreter_t, spr.XER)); else if (sprIndex >= SPR_UGQR0 && sprIndex <= SPR_UGQR7) - x64Emit_mov_reg64_mem32(x64GenContext, tempToRealRegister(imlInstruction->op_r_name.registerIndex), REG_RSP, offsetof(PPCInterpreter_t, spr.UGQR[sprIndex - SPR_UGQR0])); + { + sint32 memOffset = offsetof(PPCInterpreter_t, spr.UGQR) + sizeof(PPCInterpreter_t::spr.UGQR[0]) * (sprIndex - SPR_UGQR0); + x64Emit_mov_reg64_mem32(x64GenContext, tempToRealRegister(imlInstruction->op_r_name.registerIndex), REG_RSP, memOffset); + } else assert_dbg(); //x64Emit_mov_reg64_mem32(x64GenContext, tempToRealRegister(imlInstruction->op_r_name.registerIndex), REG_RSP, offsetof(PPCInterpreter_t, spr)+sizeof(uint32)*(name-PPCREC_NAME_SPR0)); @@ -2247,7 +2250,10 @@ void PPCRecompilerX64Gen_imlInstruction_name_r(PPCRecFunction_t* PPCRecFunction, else if (sprIndex == SPR_XER) x64Emit_mov_mem32_reg64(x64GenContext, REG_RSP, offsetof(PPCInterpreter_t, spr.XER), tempToRealRegister(imlInstruction->op_r_name.registerIndex)); else if (sprIndex >= SPR_UGQR0 && sprIndex <= SPR_UGQR7) - x64Emit_mov_mem32_reg64(x64GenContext, REG_RSP, offsetof(PPCInterpreter_t, spr.UGQR[sprIndex-SPR_UGQR0]), tempToRealRegister(imlInstruction->op_r_name.registerIndex)); + { + sint32 memOffset = offsetof(PPCInterpreter_t, spr.UGQR) + sizeof(PPCInterpreter_t::spr.UGQR[0]) * (sprIndex - SPR_UGQR0); + x64Emit_mov_mem32_reg64(x64GenContext, REG_RSP, memOffset, tempToRealRegister(imlInstruction->op_r_name.registerIndex)); + } else assert_dbg(); } diff --git a/src/Cafe/HW/Latte/Core/FetchShader.cpp b/src/Cafe/HW/Latte/Core/FetchShader.cpp index a029516c..d6bbc217 100644 --- a/src/Cafe/HW/Latte/Core/FetchShader.cpp +++ b/src/Cafe/HW/Latte/Core/FetchShader.cpp @@ -80,31 +80,31 @@ void LatteShader_calculateFSKey(LatteFetchShader* fetchShader) { LatteParsedFetchShaderAttribute_t* attrib = group.attrib + f; key += (uint64)attrib->endianSwap; - key = _rotl64(key, 3); + key = std::rotl(key, 3); key += (uint64)attrib->nfa; - key = _rotl64(key, 3); + key = std::rotl(key, 3); key += (uint64)(attrib->isSigned?1:0); - key = _rotl64(key, 1); + key = std::rotl(key, 1); key += (uint64)attrib->format; - key = _rotl64(key, 7); + key = std::rotl(key, 7); key += (uint64)attrib->fetchType; - key = _rotl64(key, 8); + key = std::rotl(key, 8); key += (uint64)attrib->ds[0]; - key = _rotl64(key, 2); + key = std::rotl(key, 2); key += (uint64)attrib->ds[1]; - key = _rotl64(key, 2); + key = std::rotl(key, 2); key += (uint64)attrib->ds[2]; - key = _rotl64(key, 2); + key = std::rotl(key, 2); key += (uint64)attrib->ds[3]; - key = _rotl64(key, 2); + key = std::rotl(key, 2); key += (uint64)(attrib->aluDivisor+1); - key = _rotl64(key, 2); + key = std::rotl(key, 2); key += (uint64)attrib->attributeBufferIndex; - key = _rotl64(key, 8); + key = std::rotl(key, 8); key += (uint64)attrib->semanticId; - key = _rotl64(key, 8); + key = std::rotl(key, 8); key += (uint64)(attrib->offset & 3); - key = _rotl64(key, 2); + key = std::rotl(key, 2); } } // todo - also hash invalid buffer groups? diff --git a/src/Cafe/HW/Latte/Core/LatteBufferCache.cpp b/src/Cafe/HW/Latte/Core/LatteBufferCache.cpp index 93efdd62..7b7c28db 100644 --- a/src/Cafe/HW/Latte/Core/LatteBufferCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteBufferCache.cpp @@ -743,7 +743,7 @@ private: //h ^= *memU64; //memU64++; - h = _rotr64(h, 7); + h = std::rotr(h, 7); h += (*memU64 + (uint64)i); memU64++; } diff --git a/src/Cafe/HW/Latte/Core/LatteOverlay.cpp b/src/Cafe/HW/Latte/Core/LatteOverlay.cpp index 998043d4..cb7c9baf 100644 --- a/src/Cafe/HW/Latte/Core/LatteOverlay.cpp +++ b/src/Cafe/HW/Latte/Core/LatteOverlay.cpp @@ -518,7 +518,7 @@ void LatteOverlay_translateScreenPosition(ScreenPosition pos, const Vector2f& wi direction = -1; break; default: - __assume(false); + UNREACHABLE; } } diff --git a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp index 84183cbc..a9ab539b 100644 --- a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp +++ b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp @@ -158,15 +158,15 @@ void LatteMRT::ApplyCurrentState() if (colorView) { key += ((uint64)colorView); - key = _rotl64(key, 5); + key = std::rotl(key, 5); fboLookupView = colorView; } - key = _rotl64(key, 7); + key = std::rotl(key, 7); } if (sLatteCurrentRendertargets.depthBuffer.view) { key += ((uint64)sLatteCurrentRendertargets.depthBuffer.view); - key = _rotl64(key, 5); + key = std::rotl(key, 5); key += (sLatteCurrentRendertargets.depthBuffer.hasStencil); if (fboLookupView == NULL) { diff --git a/src/Cafe/HW/Latte/Core/LatteShader.cpp b/src/Cafe/HW/Latte/Core/LatteShader.cpp index ded1c20f..92234ae0 100644 --- a/src/Cafe/HW/Latte/Core/LatteShader.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShader.cpp @@ -225,8 +225,8 @@ void LatteShader_UpdatePSInputs(uint32* contextRegisters) // parameter gen if (spi0_paramGen != 0) { - key += _rotr64(spi0_paramGen, 7); - key += _rotr64(spi0_paramGenAddr, 3); + key += std::rotr(spi0_paramGen, 7); + key += std::rotr(spi0_paramGenAddr, 3); _activePSImportTable.paramGen = spi0_paramGen; _activePSImportTable.paramGenGPR = spi0_paramGenAddr; } @@ -263,7 +263,7 @@ void LatteShader_UpdatePSInputs(uint32* contextRegisters) cemu_assert_debug(psSemanticId != 0xFF); key += (uint64)psInputControl; - key = _rotl64(key, 7); + key = std::rotl(key, 7); if (spi0_positionEnable && f == spi0_positionAddr) { _activePSImportTable.import[f].semanticId = LATTE_ANALYZER_IMPORT_INDEX_SPIPOSITION; @@ -546,7 +546,7 @@ uint64 LatteSHRC_CalcVSAuxHash(LatteDecompilerShader* vertexShader, uint32* cont if(!vertexShader->streamoutBufferWriteMask2[i]) continue; uint32 bufferStride = contextRegisters[mmVGT_STRMOUT_VTX_STRIDE_0 + i * 4]; - auxHash = _rotl64(auxHash, 7); + auxHash = std::rotl(auxHash, 7); auxHash += (uint64)bufferStride; } } @@ -559,7 +559,7 @@ uint64 LatteSHRC_CalcVSAuxHash(LatteDecompilerShader* vertexShader, uint32* cont if ((word4 & 0x300) == 0x100) { // integer format - auxHashTex = _rotl64(auxHashTex, 7); + auxHashTex = std::rotl(auxHashTex, 7); auxHashTex += 0x333; } } diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerInternal.h b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerInternal.h index 4c2c2efd..3dc3eca6 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerInternal.h +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerInternal.h @@ -124,8 +124,9 @@ struct LatteDecompilerCFInstruction LatteDecompilerCFInstruction(LatteDecompilerCFInstruction&& mE) = default; #else LatteDecompilerCFInstruction(const LatteDecompilerCFInstruction& mE) = default; - LatteDecompilerCFInstruction(const LatteDecompilerCFInstruction&& mE) = default; + LatteDecompilerCFInstruction(LatteDecompilerCFInstruction&& mE) = default; #endif + LatteDecompilerCFInstruction& operator=(LatteDecompilerCFInstruction&& mE) = default; }; diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 509193bb..80c72918 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -1463,7 +1463,7 @@ void OpenGLRenderer::shader_bind(RendererShader* shader) prevGeometryShaderProgram = program; break; default: - __assume(false); + UNREACHABLE; } catchOpenGLError(); @@ -1494,7 +1494,7 @@ void OpenGLRenderer::shader_unbind(RendererShader::ShaderType shaderType) prevGeometryShaderProgram = -1; break; default: - __assume(false); + UNREACHABLE; } } diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererUniformData.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererUniformData.cpp index 6ffcccbb..42fd5eb2 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererUniformData.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRendererUniformData.cpp @@ -44,9 +44,9 @@ void OpenGLRenderer::uniformData_update() for (sint32 f = 0; f < remappedArraySize; f++) { uniformDataHash[0] ^= remappedUniformData64[0]; - uniformDataHash[0] = _rotl64(uniformDataHash[0], 11); + uniformDataHash[0] = std::rotl(uniformDataHash[0], 11); uniformDataHash[1] ^= remappedUniformData64[1]; - uniformDataHash[1] = _rotl64(uniformDataHash[1], 11); + uniformDataHash[1] = std::rotl(uniformDataHash[1], 11); remappedUniformData64 += 2; } if (shader->uniformDataHash64[0] != uniformDataHash[0] || shader->uniformDataHash64[1] != uniformDataHash[1]) diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp index 60dd99ea..e9e86f53 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp @@ -270,7 +270,7 @@ void RendererShaderGL::ShaderCacheLoading_begin(uint64 cacheTitleId) usePrecompiled = false; break; default: - __assume(false); + UNREACHABLE; } forceLog_printf("Using precompiled shaders: %s", usePrecompiled ? "true" : "false"); diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h index 5c929998..1c0753dc 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h @@ -1,7 +1,7 @@ #pragma once #include "Cafe/HW/Latte/Renderer/RendererShader.h" -#include "Common\GLInclude\GLInclude.h" +#include "Common/GLInclude/GLInclude.h" class RendererShaderGL : public RendererShader { diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp index b107e56d..0d41156a 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp @@ -140,8 +140,8 @@ const TBuiltInResource DefaultTBuiltInResource = { /* .generalVaryingIndexing = */ 1, /* .generalSamplerIndexing = */ 1, /* .generalVariableIndexing = */ 1, - /* .generalConstantMatrixVectorIndexing = */ 1, -} + /* .generalConstantMatrixVectorIndexing = */ 1 + } }; class _ShaderVkThreadPool diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index 383c0fd8..5e6119fa 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -3412,7 +3412,7 @@ VkDescriptorSetInfo::~VkDescriptorSetInfo() break; } default: - __assume(false); + UNREACHABLE; } // update global stats performanceMonitor.vk.numDescriptorSamplerTextures.decrement(statsNumSamplerTextures); @@ -4021,13 +4021,13 @@ VKRObjectRenderPass::VKRObjectRenderPass(AttachmentInfo_t& attachmentInfo, sint3 if (attachmentInfo.colorAttachment[i].isPresent || attachmentInfo.colorAttachment[i].viewObj) { stateHash += attachmentInfo.colorAttachment[i].format + i * 31; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); } } if (attachmentInfo.depthAttachment.isPresent || attachmentInfo.depthAttachment.viewObj) { stateHash += attachmentInfo.depthAttachment.format; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); } m_hashForPipeline = stateHash; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRendererCore.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRendererCore.cpp index e47b5bf0..043cf8d6 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRendererCore.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRendererCore.cpp @@ -24,18 +24,18 @@ uint64 VulkanRenderer::draw_calculateMinimalGraphicsPipelineHash(const LatteFetc for (auto& group : fetchShader->bufferGroups) { uint32 bufferStride = group.getCurrentBufferStride(lcr.GetRawView()); - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); stateHash += bufferStride * 3; } stateHash += fetchShader->getVkPipelineHashFragment(); - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); stateHash += lcr.GetRawView()[mmVGT_PRIMITIVE_TYPE]; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); stateHash += lcr.GetRawView()[mmVGT_STRMOUT_EN]; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); if(lcr.PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL()) stateHash += 0x333333; @@ -66,24 +66,24 @@ uint64 VulkanRenderer::draw_calculateGraphicsPipelineHash(const LatteFetchShader if (vertexShader) stateHash += vertexShader->baseHash; - stateHash = _rotl64(stateHash, 13); + stateHash = std::rotl(stateHash, 13); if (geometryShader) stateHash += geometryShader->baseHash; - stateHash = _rotl64(stateHash, 13); + stateHash = std::rotl(stateHash, 13); if (pixelShader) stateHash += pixelShader->baseHash + pixelShader->auxHash; - stateHash = _rotl64(stateHash, 13); + stateHash = std::rotl(stateHash, 13); uint32 polygonCtrl = lcr.PA_SU_SC_MODE_CNTL.getRawValue(); stateHash += polygonCtrl; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); stateHash += ctxRegister[Latte::REGADDR::PA_CL_CLIP_CNTL]; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); const auto colorControlReg = ctxRegister[Latte::REGADDR::CB_COLOR_CONTROL]; stateHash += colorControlReg; @@ -97,7 +97,7 @@ uint64 VulkanRenderer::draw_calculateGraphicsPipelineHash(const LatteFetchShader { if (((blendEnableMask & (1 << i))) == 0) continue; - stateHash = _rotl64(stateHash, 7); + stateHash = std::rotl(stateHash, 7); stateHash += ctxRegister[Latte::REGADDR::CB_BLEND0_CONTROL + i]; } } @@ -109,11 +109,11 @@ uint64 VulkanRenderer::draw_calculateGraphicsPipelineHash(const LatteFetchShader if (stencilTestEnable) { stateHash += ctxRegister[mmDB_STENCILREFMASK]; - stateHash = _rotl64(stateHash, 17); + stateHash = std::rotl(stateHash, 17); if(depthControl & (1<<7)) // back stencil enable { stateHash += ctxRegister[mmDB_STENCILREFMASK_BF]; - stateHash = _rotl64(stateHash, 13); + stateHash = std::rotl(stateHash, 13); } } else @@ -122,7 +122,7 @@ uint64 VulkanRenderer::draw_calculateGraphicsPipelineHash(const LatteFetchShader depthControl &= 0xFF; } - stateHash = _rotl64(stateHash, 17); + stateHash = std::rotl(stateHash, 17); stateHash += depthControl; // polygon offset @@ -528,7 +528,7 @@ uint64 VulkanRenderer::GetDescriptorSetStateHash(LatteDecompilerShader* shader) texUnitRegIndex += Latte::REGADDR::SQ_TEX_RESOURCE_WORD0_N_GS; break; default: - __assume(false); + UNREACHABLE; } auto texture = m_state.boundTexture[hostTextureUnit]; @@ -542,16 +542,16 @@ uint64 VulkanRenderer::GetDescriptorSetStateHash(LatteDecompilerShader* shader) { samplerIndex += LatteDecompiler_getTextureSamplerBaseIndex(shader->shaderType); hash += LatteGPUState.contextRegister[Latte::REGADDR::SQ_TEX_SAMPLER_WORD0_0 + samplerIndex * 3 + 0]; - hash = _rotl64(hash, 7); + hash = std::rotl(hash, 7); hash += LatteGPUState.contextRegister[Latte::REGADDR::SQ_TEX_SAMPLER_WORD0_0 + samplerIndex * 3 + 1]; - hash = _rotl64(hash, 7); + hash = std::rotl(hash, 7); hash += LatteGPUState.contextRegister[Latte::REGADDR::SQ_TEX_SAMPLER_WORD0_0 + samplerIndex * 3 + 2]; - hash = _rotl64(hash, 7); + hash = std::rotl(hash, 7); } - hash = _rotl64(hash, 7); + hash = std::rotl(hash, 7); // hash view id + swizzle mask hash += (uint64)texture->GetUniqueId(); - hash = _rotr64(hash, 21); + hash = std::rotr(hash, 21); hash += (uint64)(word4 & 0x0FFF0000); } @@ -590,7 +590,7 @@ VkDescriptorSetInfo* VulkanRenderer::draw_getOrCreateDescriptorSet(PipelineInfo* break; } default: - __assume(false); + UNREACHABLE; } // create new descriptor set @@ -646,7 +646,7 @@ VkDescriptorSetInfo* VulkanRenderer::draw_getOrCreateDescriptorSet(PipelineInfo* texUnitRegIndex += Latte::REGADDR::SQ_TEX_RESOURCE_WORD0_N_GS; break; default: - __assume(false); + UNREACHABLE; } auto textureView = m_state.boundTexture[hostTextureUnit]; @@ -996,7 +996,7 @@ VkDescriptorSetInfo* VulkanRenderer::draw_getOrCreateDescriptorSet(PipelineInfo* break; } default: - __assume(false); + UNREACHABLE; } return dsInfo; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanSurfaceCopy.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanSurfaceCopy.cpp index c1751dd5..ec751dd7 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanSurfaceCopy.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanSurfaceCopy.cpp @@ -108,12 +108,12 @@ uint64 VulkanRenderer::copySurface_getPipelineStateHash(VkCopySurfaceState_t& st uint64 h = 0; h += (uintptr_t)state.destinationTexture->GetFormat(); - h = _rotr64(h, 7); + h = std::rotr(h, 7); h += state.sourceTexture->isDepth ? 0x1111ull : 0; - h = _rotr64(h, 7); + h = std::rotr(h, 7); h += state.destinationTexture->isDepth ? 0x1112ull : 0; - h = _rotr64(h, 7); + h = std::rotr(h, 7); return h; } diff --git a/src/Cafe/OS/RPL/rpl.cpp b/src/Cafe/OS/RPL/rpl.cpp index 82edbb85..75b1a379 100644 --- a/src/Cafe/OS/RPL/rpl.cpp +++ b/src/Cafe/OS/RPL/rpl.cpp @@ -713,8 +713,8 @@ void _calculateMappedImportNameHash(const char* rplName, const char* funcName, u uint64 v = (uint64)*rplName; h1 += v; h2 ^= v; - h1 = _rotl64(h1, 3); - h2 = _rotl64(h2, 7); + h1 = std::rotl(h1, 3); + h2 = std::rotl(h2, 7); rplName++; } // funcName @@ -723,8 +723,8 @@ void _calculateMappedImportNameHash(const char* rplName, const char* funcName, u uint64 v = (uint64)*funcName; h1 += v; h2 ^= v; - h1 = _rotl64(h1, 3); - h2 = _rotl64(h2, 7); + h1 = std::rotl(h1, 3); + h2 = std::rotl(h2, 7); funcName++; } *h1Out = h1; diff --git a/src/Cafe/OS/common/OSCommon.cpp b/src/Cafe/OS/common/OSCommon.cpp index 9dd05aac..b41ab865 100644 --- a/src/Cafe/OS/common/OSCommon.cpp +++ b/src/Cafe/OS/common/OSCommon.cpp @@ -217,4 +217,4 @@ void osLib_load() swkbd::load(); camera::load(); procui_load(); -} \ No newline at end of file +} diff --git a/src/Cafe/OS/libs/coreinit/coreinit_MEM_BlockHeap.cpp b/src/Cafe/OS/libs/coreinit/coreinit_MEM_BlockHeap.cpp index 1738677e..e4bc6792 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_MEM_BlockHeap.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_MEM_BlockHeap.cpp @@ -398,7 +398,7 @@ namespace coreinit else track = (MEMBlockHeapTrackDEPR*)memory_getPointerFromVirtualOffsetAllowNull(_swapEndianU32(blockHeapHead->headBlock)); - cemu_assert_debug(__popcnt(alignment) == 1); // not a supported alignment value + cemu_assert_debug(std::popcount(alignment) == 1); // not a supported alignment value while (track) { if (track->isFree != _swapEndianU32(0)) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp index 43eae921..a57b4473 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp @@ -45,8 +45,8 @@ namespace coreinit bool g_isMulticoreMode; - __declspec(thread) uint32 t_assignedCoreIndex; - __declspec(thread) Fiber* t_schedulerFiber; + THREAD_LOCAL uint32 t_assignedCoreIndex; + THREAD_LOCAL Fiber* t_schedulerFiber; struct OSHostThread { diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Time.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Time.cpp index c22152f4..e85b6adb 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Time.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Time.cpp @@ -28,7 +28,7 @@ namespace coreinit osLib_returnFromFunction64(hCPU, osTime); } - __declspec(noinline) uint64 coreinit_getTimeBase_dummy() + uint64 coreinit_getTimeBase_dummy() { return __rdtsc(); } diff --git a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp index f4451ce5..4923eae2 100644 --- a/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp +++ b/src/Cafe/OS/libs/nlibcurl/nlibcurl.cpp @@ -201,8 +201,8 @@ static_assert(sizeof(CURLMsg_t) <= 0xC, "sizeof(CURLMsg_t)"); size_t header_callback(char* buffer, size_t size, size_t nitems, void* userdata); -__declspec(thread) PPCConcurrentQueue* g_callerQueue; -__declspec(thread) ConcurrentQueue* g_threadQueue; +THREAD_LOCAL PPCConcurrentQueue* g_callerQueue; +THREAD_LOCAL ConcurrentQueue* g_threadQueue; void CurlWorkerThread(CURL_t* curl, PPCConcurrentQueue* callerQueue, ConcurrentQueue* threadQueue) { g_callerQueue = callerQueue; diff --git a/src/Cafe/TitleList/MetaInfo.cpp b/src/Cafe/TitleList/MetaInfo.cpp index f3e362b0..3ae77a05 100644 --- a/src/Cafe/TitleList/MetaInfo.cpp +++ b/src/Cafe/TitleList/MetaInfo.cpp @@ -174,7 +174,7 @@ std::unique_ptr MetaInfo::GetIcon(uint32& size) const return nullptr; } default: - __assume(false); + UNREACHABLE; } return nullptr; } diff --git a/src/Cemu/CMakeLists.txt b/src/Cemu/CMakeLists.txt index 8c9136ff..0e02699c 100644 --- a/src/Cemu/CMakeLists.txt +++ b/src/Cemu/CMakeLists.txt @@ -13,3 +13,4 @@ target_include_directories(CemuComponents PRIVATE ../) if(ENABLE_DISCORD_RPC) target_link_libraries(CemuComponents PRIVATE discord-rpc) endif() +target_link_libraries(CemuComponents PRIVATE CemuUtil) \ No newline at end of file diff --git a/src/Common/SysAllocator.cpp b/src/Common/SysAllocator.cpp index 6632f6f0..7e296f39 100644 --- a/src/Common/SysAllocator.cpp +++ b/src/Common/SysAllocator.cpp @@ -22,4 +22,4 @@ SysAllocatorContainer& SysAllocatorContainer::GetInstance() SysAllocatorBase::SysAllocatorBase() { SysAllocatorContainer::GetInstance().PushSysAllocator(this); -} +} \ No newline at end of file diff --git a/src/Common/SysAllocator.h b/src/Common/SysAllocator.h index 1807fb24..a9bc0da1 100644 --- a/src/Common/SysAllocator.h +++ b/src/Common/SysAllocator.h @@ -1,6 +1,7 @@ #pragma once #include + uint32 coreinit_allocFromSysArea(uint32 size, uint32 alignment); class SysAllocatorBase; diff --git a/src/Common/precompiled.h b/src/Common/precompiled.h index ad080e6e..dfc02dda 100644 --- a/src/Common/precompiled.h +++ b/src/Common/precompiled.h @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -176,6 +177,12 @@ inline sint16 _swapEndianS16(sint16 v) return (sint16)(((uint16)v >> 8) | ((uint16)v << 8)); } +inline uint64 _umul128(uint64 multiplier, uint64 multiplicand, uint64 *highProduct) { + unsigned __int128 x = (unsigned __int128)multiplier * (unsigned __int128)multiplicand; + *highProduct = (x >> 64); + return x & 0xFFFFFFFFFFFFFFFF; +} + typedef uint8_t BYTE; typedef uint32_t DWORD; typedef int32_t LONG; @@ -203,18 +210,43 @@ typedef union _LARGE_INTEGER { inline T& operator^= (T& a, T b) { return reinterpret_cast( reinterpret_cast::type&>(a) ^= static_cast::type>(b) ); } #endif +#if defined(_MSC_VER) + #define UNREACHABLE __assume(false) +#elif defined(__GNUC__) + #define UNREACHABLE __builtin_unreachable() +#else + #define UNREACHABLE +#endif + +#if defined(_MSC_VER) + #define DEBUG_BREAK __debugbreak() +#else + #include + #define DEBUG_BREAK raise(SIGTRAP) +#endif + +#if defined(_MSC_VER) + #define THREAD_LOCAL __declspec(thread) +#elif defined(__GNUC__) + #define THREAD_LOCAL __thread +#else + #define THREAD_LOCAL thread_local +#endif + +#if defined(_MSC_VER) + #define DLLEXPORT __declspec(dllexport) +#elif defined(__GNUC__) + #define DLLEXPORT __attribute__((dllexport)) +#else + #error No definition for DLLEXPORT +#endif + + // MEMPTR #include "Common/MemPtr.h" #define MPTR_NULL (0) -// macros -#if BOOST_OS_WINDOWS -#define DLLEXPORT __declspec(dllexport) -#else -#define DLLEXPORT __declspec(dllexport) -#endif - template constexpr bool HAS_FLAG(T1 flags, T2 test_flag) { return (flags & (T1)test_flag) == (T1)test_flag; } template @@ -296,7 +328,7 @@ inline void cemu_assert(bool _condition) { if ((_condition) == false) { - __debugbreak(); + DEBUG_BREAK; } } @@ -317,32 +349,32 @@ inline void cemu_assert_suspicious() inline void cemu_assert_error() { - __debugbreak(); + DEBUG_BREAK; } #else inline void cemu_assert_debug(bool _condition) { if ((_condition) == false) - __debugbreak(); + DEBUG_BREAK; } inline void cemu_assert_unimplemented() { - __debugbreak(); + DEBUG_BREAK; } inline void cemu_assert_suspicious() { - __debugbreak(); + DEBUG_BREAK; } inline void cemu_assert_error() { - __debugbreak(); + DEBUG_BREAK; } #endif -#define assert_dbg() __debugbreak() // old style unconditional generic assert +#define assert_dbg() DEBUG_BREAK // old style unconditional generic assert // Some string conversion helpers because C++20 std::u8string is too cumbersome to use in practice // mixing string types generally causes loads of issues and many of the libraries we use dont expose interfaces for u8string @@ -393,7 +425,7 @@ public: template bool future_is_ready(std::future& f) { -#ifdef __clang__ +#if defined(__GNUC__) return f.wait_for(std::chrono::nanoseconds(0)) == std::future_status::ready; #else return f._Is_ready(); @@ -409,7 +441,7 @@ std::atomic* _rawPtrToAtomic(T* ptr) return reinterpret_cast*>(ptr); } -#if __clang__ +#if defined(__GNUC__) #define ATTR_MS_ABI __attribute__((ms_abi)) #else #define ATTR_MS_ABI @@ -430,7 +462,7 @@ inline uint32 GetTitleIdLow(uint64 titleId) return titleId & 0xFFFFFFFF; } -#ifdef __clang__ +#if defined(__GNUC__) #define memcpy_dwords(__dest, __src, __numDwords) memcpy((__dest), (__src), (__numDwords) * sizeof(uint32)) #define memcpy_qwords(__dest, __src, __numQwords) memcpy((__dest), (__src), (__numQwords) * sizeof(uint64)) #else diff --git a/src/Common/unix/platform.cpp b/src/Common/unix/platform.cpp index 592a665f..f0fc52a8 100644 --- a/src/Common/unix/platform.cpp +++ b/src/Common/unix/platform.cpp @@ -16,8 +16,10 @@ void (__cpuid)(int __cpuVal[4], unsigned int __leaf) } #undef __cpuid -void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf) +#ifdef __clang__ +void __cpuidex(int __cpuid_info[4], int __leaf, int __subleaf) { __cpuid_count (__leaf, __subleaf, __cpuid_info[0], __cpuid_info[1], __cpuid_info[2], __cpuid_info[3]); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/config/XMLConfig.h b/src/config/XMLConfig.h index dacfc4d2..04e3cfbf 100644 --- a/src/config/XMLConfig.h +++ b/src/config/XMLConfig.h @@ -148,49 +148,41 @@ public: return default_value; } - template <> bool value(bool default_value) { return m_current_element ? m_current_element->BoolText(default_value) : default_value; } - template <> float value(float default_value) { return m_current_element ? m_current_element->FloatText(default_value) : default_value; } - template <> double value(double default_value) { return m_current_element ? m_current_element->DoubleText(default_value) : default_value; } - template <> uint32 value(uint32 default_value) { return m_current_element ? m_current_element->UnsignedText(default_value) : default_value; } - template <> sint32 value(sint32 default_value) { return m_current_element ? m_current_element->IntText(default_value) : default_value; } - template <> uint64 value(uint64 default_value) { return m_current_element ? (uint64)m_current_element->Int64Text(default_value) : default_value; } - template <> sint64 value(sint64 default_value) { return m_current_element ? m_current_element->Int64Text(default_value) : default_value; } - template <> const char* value(const char* default_value) { if (m_current_element) @@ -243,7 +235,6 @@ public: set(name, value.load()); } - template <> void set(const char* name, uint64 value) { set(name, (sint64)value); @@ -300,7 +291,6 @@ public: return set_attribute(name, value.GetValue()); } - template <> XMLConfigParser& set_attribute(const char* name, const std::string& value) { return set_attribute(name, value.c_str()); diff --git a/src/gui/MemorySearcherTool.h b/src/gui/MemorySearcherTool.h index 2f891062..add9aced 100644 --- a/src/gui/MemorySearcherTool.h +++ b/src/gui/MemorySearcherTool.h @@ -72,9 +72,6 @@ private: return iss && iss.eof(); } - template <> - bool ConvertStringToType(const char* inValue, sint8& outValue) const; - using ListType_t = std::vector>; ListType_t SearchValues(SearchDataType type, void* ptr, uint32 size) { @@ -197,6 +194,8 @@ wxDECLARE_EVENT_TABLE(); bool m_clear_state = false; }; +template <> +bool MemorySearcherTool::ConvertStringToType(const char* inValue, sint8& outValue) const; diff --git a/src/gui/components/wxTitleManagerList.cpp b/src/gui/components/wxTitleManagerList.cpp index d826c118..2a40b25d 100644 --- a/src/gui/components/wxTitleManagerList.cpp +++ b/src/gui/components/wxTitleManagerList.cpp @@ -941,7 +941,7 @@ wxString wxTitleManagerList::GetTitleEntryText(const TitleEntry& entry, ItemColu //return wxStringFormat2("{}", entry.format); } default: - __assume(false); + UNREACHABLE; } return wxEmptyString; diff --git a/src/main.cpp b/src/main.cpp index aa43aee5..e6529391 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,11 +39,13 @@ #define _putenv(__s) putenv((char*)(__s)) #endif +#if BOOST_OS_WINDOWS extern "C" { __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; } +#endif bool _cpuExtension_SSSE3 = false; bool _cpuExtension_SSE4_1 = false; diff --git a/src/util/crypto/aes128.cpp b/src/util/crypto/aes128.cpp index 17f049f3..2c7bfa35 100644 --- a/src/util/crypto/aes128.cpp +++ b/src/util/crypto/aes128.cpp @@ -759,7 +759,7 @@ void AESNI128_CBC_decryptWithExpandedKey(const unsigned char *in, void __aesni__AES128_CBC_decrypt(uint8* output, uint8* input, uint32 length, const uint8* key, const uint8* iv) { - __declspec(align(16)) uint8 expandedKey[11 * 16]; + alignas(16) uint8 expandedKey[11 * 16]; AESNI128_KeyExpansionDecrypt(key, expandedKey); if (iv) { @@ -774,7 +774,7 @@ void __aesni__AES128_CBC_decrypt(uint8* output, uint8* input, uint32 length, con void __aesni__AES128_ECB_encrypt(uint8* input, const uint8* key, uint8* output) { - __declspec(align(16)) uint8 expandedKey[11 * 16]; + alignas(16) uint8 expandedKey[11 * 16]; AESNI128_KeyExpansionEncrypt(key, expandedKey); // encrypt single ECB block __m128i feedback; diff --git a/src/util/helpers/Serializer.cpp b/src/util/helpers/Serializer.cpp new file mode 100644 index 00000000..e9e60b0a --- /dev/null +++ b/src/util/helpers/Serializer.cpp @@ -0,0 +1,162 @@ +#include "Serializer.h" + +template<> +uint8 MemStreamReader::readBE() +{ + if (!reserveReadLength(sizeof(uint8))) + return 0; + uint8 v = m_data[m_cursorPos]; + m_cursorPos += sizeof(uint8); + return v; +} + +template<> +uint16 MemStreamReader::readBE() +{ + if (!reserveReadLength(sizeof(uint16))) + return 0; + const uint8* p = m_data + m_cursorPos; + uint16 v; + std::memcpy(&v, p, sizeof(v)); + v = _BE(v); + m_cursorPos += sizeof(uint16); + return v; +} + +template<> +uint32 MemStreamReader::readBE() +{ + if (!reserveReadLength(sizeof(uint32))) + return 0; + const uint8* p = m_data + m_cursorPos; + uint32 v; + std::memcpy(&v, p, sizeof(v)); + v = _BE(v); + m_cursorPos += sizeof(uint32); + return v; +} + +template<> +uint64 MemStreamReader::readBE() +{ + if (!reserveReadLength(sizeof(uint64))) + return 0; + const uint8* p = m_data + m_cursorPos; + uint64 v; + std::memcpy(&v, p, sizeof(v)); + v = _BE(v); + m_cursorPos += sizeof(uint64); + return v; +} + +template<> +std::string MemStreamReader::readBE() +{ + std::string s; + uint32 stringSize = readBE(); + if (hasError()) + return s; + if (stringSize >= (32 * 1024 * 1024)) + { + // out of bounds read or suspiciously large string + m_hasError = true; + return std::string(); + } + s.resize(stringSize); + readData(s.data(), stringSize); + return s; +} + +template<> +uint8 MemStreamReader::readLE() +{ + return readBE(); +} + +template<> +uint32 MemStreamReader::readLE() +{ + if (!reserveReadLength(sizeof(uint32))) + return 0; + const uint8* p = m_data + m_cursorPos; + uint32 v; + std::memcpy(&v, p, sizeof(v)); + v = _LE(v); + m_cursorPos += sizeof(uint32); + return v; +} + +template<> +uint64 MemStreamReader::readLE() +{ + if (!reserveReadLength(sizeof(uint64))) + return 0; + const uint8* p = m_data + m_cursorPos; + uint64 v; + std::memcpy(&v, p, sizeof(v)); + v = _LE(v); + m_cursorPos += sizeof(uint64); + return v; +} + +template<> +void MemStreamWriter::writeBE(const uint64& v) +{ + m_buffer.resize(m_buffer.size() + 8); + uint8* p = m_buffer.data() + m_buffer.size() - 8; + uint64 tmp = _BE(v); + std::memcpy(p, &tmp, sizeof(tmp)); +} + +template<> +void MemStreamWriter::writeBE(const uint32& v) +{ + m_buffer.resize(m_buffer.size() + 4); + uint8* p = m_buffer.data() + m_buffer.size() - 4; + uint32 tmp = _BE(v); + std::memcpy(p, &tmp, sizeof(tmp)); +} + + +template<> +void MemStreamWriter::writeBE(const uint16& v) +{ + m_buffer.resize(m_buffer.size() + 2); + uint8* p = m_buffer.data() + m_buffer.size() - 2; + uint16 tmp = _BE(v); + std::memcpy(p, &tmp, sizeof(tmp)); +} + + +template<> +void MemStreamWriter::writeBE(const uint8& v) +{ + m_buffer.emplace_back(v); +} + + +template<> +void MemStreamWriter::writeBE(const std::string& v) +{ + writeBE((uint32)v.size()); + writeData(v.data(), v.size()); +} + +template<> +void MemStreamWriter::writeLE(const uint64& v) +{ + m_buffer.resize(m_buffer.size() + 8); + uint8* p = m_buffer.data() + m_buffer.size() - 8; + uint64 tmp = _LE(v); + std::memcpy(p, &tmp, sizeof(tmp)); +} + + +template<> +void MemStreamWriter::writeLE(const uint32& v) +{ + m_buffer.resize(m_buffer.size() + 4); + uint8* p = m_buffer.data() + m_buffer.size() - 4; + uint32 tmp = _LE(v); + std::memcpy(p, &tmp, sizeof(tmp)); +} \ No newline at end of file diff --git a/src/util/helpers/Serializer.h b/src/util/helpers/Serializer.h index a15adfad..a4941c29 100644 --- a/src/util/helpers/Serializer.h +++ b/src/util/helpers/Serializer.h @@ -11,97 +11,6 @@ public: template T readBE(); template T readLE(); - template<> uint8 readBE() - { - if (!reserveReadLength(sizeof(uint8))) - return 0; - uint8 v = m_data[m_cursorPos]; - m_cursorPos += sizeof(uint8); - return v; - } - - template<> uint16 readBE() - { - if (!reserveReadLength(sizeof(uint16))) - return 0; - const uint8* p = m_data + m_cursorPos; - uint16 v; - std::memcpy(&v, p, sizeof(v)); - v = _BE(v); - m_cursorPos += sizeof(uint16); - return v; - } - - template<> uint32 readBE() - { - if (!reserveReadLength(sizeof(uint32))) - return 0; - const uint8* p = m_data + m_cursorPos; - uint32 v; - std::memcpy(&v, p, sizeof(v)); - v = _BE(v); - m_cursorPos += sizeof(uint32); - return v; - } - - template<> uint64 readBE() - { - if (!reserveReadLength(sizeof(uint64))) - return 0; - const uint8* p = m_data + m_cursorPos; - uint64 v; - std::memcpy(&v, p, sizeof(v)); - v = _BE(v); - m_cursorPos += sizeof(uint64); - return v; - } - - template<> std::string readBE() - { - std::string s; - uint32 stringSize = readBE(); - if (hasError()) - return s; - if (stringSize >= (32 * 1024 * 1024)) - { - // out of bounds read or suspiciously large string - m_hasError = true; - return std::string(); - } - s.resize(stringSize); - readData(s.data(), stringSize); - return s; - } - - template<> uint8 readLE() - { - return readBE(); - } - - template<> uint32 readLE() - { - if (!reserveReadLength(sizeof(uint32))) - return 0; - const uint8* p = m_data + m_cursorPos; - uint32 v; - std::memcpy(&v, p, sizeof(v)); - v = _LE(v); - m_cursorPos += sizeof(uint32); - return v; - } - - template<> uint64 readLE() - { - if (!reserveReadLength(sizeof(uint64))) - return 0; - const uint8* p = m_data + m_cursorPos; - uint64 v; - std::memcpy(&v, p, sizeof(v)); - v = _LE(v); - m_cursorPos += sizeof(uint64); - return v; - } - template std::vector readPODVector() { @@ -243,67 +152,8 @@ public: } template void writeBE(const T& v); - - template<> - void writeBE(const uint64& v) - { - m_buffer.resize(m_buffer.size() + 8); - uint8* p = m_buffer.data() + m_buffer.size() - 8; - uint64 tmp = _BE(v); - std::memcpy(p, &tmp, sizeof(tmp)); - } - - template<> - void writeBE(const uint32& v) - { - m_buffer.resize(m_buffer.size() + 4); - uint8* p = m_buffer.data() + m_buffer.size() - 4; - uint32 tmp = _BE(v); - std::memcpy(p, &tmp, sizeof(tmp)); - } - - template<> - void writeBE(const uint16& v) - { - m_buffer.resize(m_buffer.size() + 2); - uint8* p = m_buffer.data() + m_buffer.size() - 2; - uint16 tmp = _BE(v); - std::memcpy(p, &tmp, sizeof(tmp)); - } - - template<> - void writeBE(const uint8& v) - { - m_buffer.emplace_back(v); - } - - template<> - void writeBE(const std::string& v) - { - writeBE((uint32)v.size()); - writeData(v.data(), v.size()); - } - template void writeLE(const T& v); - template<> - void writeLE(const uint64& v) - { - m_buffer.resize(m_buffer.size() + 8); - uint8* p = m_buffer.data() + m_buffer.size() - 8; - uint64 tmp = _LE(v); - std::memcpy(p, &tmp, sizeof(tmp)); - } - - template<> - void writeLE(const uint32& v) - { - m_buffer.resize(m_buffer.size() + 4); - uint8* p = m_buffer.data() + m_buffer.size() - 4; - uint32 tmp = _LE(v); - std::memcpy(p, &tmp, sizeof(tmp)); - } - template void writePODVector(const std::vector& v) { diff --git a/src/util/helpers/ringbuffer.h b/src/util/helpers/ringbuffer.h index ae036efd..aab77fc3 100644 --- a/src/util/helpers/ringbuffer.h +++ b/src/util/helpers/ringbuffer.h @@ -6,7 +6,7 @@ template class RingBuffer { public: - RingBuffer(); + RingBuffer(); bool Push(const T& v);