Fix compilation on GCC and other Linux fixes (#80)

This commit is contained in:
Tom Lally 2022-08-28 14:29:15 +01:00 committed by GitHub
parent 96dcc7c82e
commit 454b587e36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 339 additions and 292 deletions

1
.gitignore vendored
View File

@ -17,6 +17,7 @@
build/
out/
.cache/
bin/Cemu
# Cemu bin files
bin/otp.bin

View File

@ -77,7 +77,7 @@ void ih264d_init_function_ptr(dec_struct_t *ps_codec)
}
}
#ifdef __clang__
#ifdef __GNUC__
#include <cpuid.h>
void __cpuid2(signed int* cpuInfo, unsigned int level)

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -34,7 +34,7 @@ PPCInterpreter_t* PPCInterpreter_getCurrentInstance()
return ppcInterpreterCurrentInstance;
}
__declspec(noinline) uint64 PPCInterpreter_getMainCoreCycleCounter()
uint64 PPCInterpreter_getMainCoreCycleCounter()
{
return PPCTimer_getFromRDTSC();
}

View File

@ -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;

View File

@ -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];

View File

@ -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();
}

View File

@ -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?

View File

@ -743,7 +743,7 @@ private:
//h ^= *memU64;
//memU64++;
h = _rotr64(h, 7);
h = std::rotr(h, 7);
h += (*memU64 + (uint64)i);
memU64++;
}

View File

@ -518,7 +518,7 @@ void LatteOverlay_translateScreenPosition(ScreenPosition pos, const Vector2f& wi
direction = -1;
break;
default:
__assume(false);
UNREACHABLE;
}
}

View File

@ -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)
{

View File

@ -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<uint64>(spi0_paramGen, 7);
key += std::rotr<uint64>(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;
}
}

View File

@ -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;
};

View File

@ -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;
}
}

View File

@ -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])

View File

@ -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");

View File

@ -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
{

View File

@ -140,7 +140,7 @@ const TBuiltInResource DefaultTBuiltInResource = {
/* .generalVaryingIndexing = */ 1,
/* .generalSamplerIndexing = */ 1,
/* .generalVariableIndexing = */ 1,
/* .generalConstantMatrixVectorIndexing = */ 1,
/* .generalConstantMatrixVectorIndexing = */ 1
}
};

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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<unsigned int>(alignment) == 1); // not a supported alignment value
while (track)
{
if (track->isFree != _swapEndianU32(0))

View File

@ -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
{

View File

@ -28,7 +28,7 @@ namespace coreinit
osLib_returnFromFunction64(hCPU, osTime);
}
__declspec(noinline) uint64 coreinit_getTimeBase_dummy()
uint64 coreinit_getTimeBase_dummy()
{
return __rdtsc();
}

View File

@ -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<QueueMsg_t>* g_callerQueue;
__declspec(thread) ConcurrentQueue<QueueMsg_t>* g_threadQueue;
THREAD_LOCAL PPCConcurrentQueue<QueueMsg_t>* g_callerQueue;
THREAD_LOCAL ConcurrentQueue<QueueMsg_t>* g_threadQueue;
void CurlWorkerThread(CURL_t* curl, PPCConcurrentQueue<QueueMsg_t>* callerQueue, ConcurrentQueue<QueueMsg_t>* threadQueue)
{
g_callerQueue = callerQueue;

View File

@ -174,7 +174,7 @@ std::unique_ptr<uint8[]> MetaInfo::GetIcon(uint32& size) const
return nullptr;
}
default:
__assume(false);
UNREACHABLE;
}
return nullptr;
}

View File

@ -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)

View File

@ -1,6 +1,7 @@
#pragma once
#include <vector>
uint32 coreinit_allocFromSysArea(uint32 size, uint32 alignment);
class SysAllocatorBase;

View File

@ -55,6 +55,7 @@
#include <stack>
#include <array>
#include <bitset>
#include <bit>
#include <filesystem>
#include <memory>
@ -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<T&>( reinterpret_cast<std::underlying_type<T>::type&>(a) ^= static_cast<std::underlying_type<T>::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 <csignal>
#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 <typename T1, typename T2>
constexpr bool HAS_FLAG(T1 flags, T2 test_flag) { return (flags & (T1)test_flag) == (T1)test_flag; }
template <typename T1, typename T2>
@ -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<typename T>
bool future_is_ready(std::future<T>& 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<T>* _rawPtrToAtomic(T* ptr)
return reinterpret_cast<std::atomic<T>*>(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

View File

@ -16,8 +16,10 @@ void (__cpuid)(int __cpuVal[4], unsigned int __leaf)
}
#undef __cpuid
#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]);
}
#endif

View File

@ -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());

View File

@ -72,9 +72,6 @@ private:
return iss && iss.eof();
}
template <>
bool ConvertStringToType(const char* inValue, sint8& outValue) const;
using ListType_t = std::vector<MEMPTR<void>>;
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;

View File

@ -941,7 +941,7 @@ wxString wxTitleManagerList::GetTitleEntryText(const TitleEntry& entry, ItemColu
//return wxStringFormat2("{}", entry.format);
}
default:
__assume(false);
UNREACHABLE;
}
return wxEmptyString;

View File

@ -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;

View File

@ -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;

View File

@ -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<uint32>();
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<uint8>();
}
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<uint64>(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<uint32>(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<uint16>(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<uint8>(const uint8& v)
{
m_buffer.emplace_back(v);
}
template<>
void MemStreamWriter::writeBE<std::string>(const std::string& v)
{
writeBE<uint32>((uint32)v.size());
writeData(v.data(), v.size());
}
template<>
void MemStreamWriter::writeLE<uint64>(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<uint32>(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));
}

View File

@ -11,97 +11,6 @@ public:
template<typename T> T readBE();
template<typename T> 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<uint32>();
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<uint8>();
}
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<typename T>
std::vector<T> readPODVector()
{
@ -243,67 +152,8 @@ public:
}
template<typename T> void writeBE(const T& v);
template<>
void writeBE<uint64>(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<uint32>(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<uint16>(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<uint8>(const uint8& v)
{
m_buffer.emplace_back(v);
}
template<>
void writeBE<std::string>(const std::string& v)
{
writeBE<uint32>((uint32)v.size());
writeData(v.data(), v.size());
}
template<typename T> void writeLE(const T& v);
template<>
void writeLE<uint64>(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<uint32>(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<typename T>
void writePODVector(const std::vector<T>& v)
{

View File

@ -6,7 +6,7 @@ template<typename T, uint32 elements, typename P = uint32>
class RingBuffer
{
public:
RingBuffer<T, elements, P>();
RingBuffer();
bool Push(const T& v);