From cd2b0810982a8be8f8c4a508e9d2e017b5d7dbc1 Mon Sep 17 00:00:00 2001 From: Tom Lally Date: Sun, 28 Aug 2022 10:34:57 +0100 Subject: [PATCH] Replaced _rotl64 with std::rotl --- src/Cafe/HW/Latte/Core/FetchShader.cpp | 26 +++++++------- src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp | 6 ++-- src/Cafe/HW/Latte/Core/LatteShader.cpp | 6 ++-- .../OpenGL/OpenGLRendererUniformData.cpp | 4 +-- .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 4 +-- .../Renderer/Vulkan/VulkanRendererCore.cpp | 34 +++++++++---------- src/Cafe/OS/RPL/rpl.cpp | 8 ++--- src/Common/precompiled.h | 4 --- 8 files changed, 44 insertions(+), 48 deletions(-) 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/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 5450ba03..92234ae0 100644 --- a/src/Cafe/HW/Latte/Core/LatteShader.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShader.cpp @@ -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/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/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index e7f7fbf7..5e6119fa 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -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 d59b390c..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 @@ -542,13 +542,13 @@ 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 = std::rotr(hash, 21); 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/Common/precompiled.h b/src/Common/precompiled.h index 6a7dcd15..30f46d76 100644 --- a/src/Common/precompiled.h +++ b/src/Common/precompiled.h @@ -177,10 +177,6 @@ inline sint16 _swapEndianS16(sint16 v) return (sint16)(((uint16)v >> 8) | ((uint16)v << 8)); } -inline uint64 _rotl64(uint64 x, sint8 r) -{ - return (x << r) | (x >> (64 - r)); -} inline uint64 _umul128(uint64 multiplier, uint64 multiplicand, uint64 *highProduct) {