diff --git a/FEXCore/Source/Interface/Core/CPUID.cpp b/FEXCore/Source/Interface/Core/CPUID.cpp index de7e8241c7..9beac190c8 100644 --- a/FEXCore/Source/Interface/Core/CPUID.cpp +++ b/FEXCore/Source/Interface/Core/CPUID.cpp @@ -96,20 +96,46 @@ static uint32_t GetCPUID() { return CPU; } +struct CPUFamily { + uint32_t Stepping; + uint32_t Model; + uint32_t ExtendedModel; + uint32_t FamilyID; + uint32_t ExtendedFamilyID; + uint32_t ProcessorType; +}; + +constexpr static uint32_t GenerateFamily(const CPUFamily Family) { + ERROR_AND_DIE_THROW_FMT((Family.Stepping & ~0xF) == 0, "Stepping too large"); + ERROR_AND_DIE_THROW_FMT((Family.Model & ~0xF) == 0, "Model too large"); + ERROR_AND_DIE_THROW_FMT((Family.FamilyID & ~0xF) == 0, "FamilyID too large"); + ERROR_AND_DIE_THROW_FMT((Family.ExtendedModel & ~0xF) == 0, "ExtendedModel too large"); + ERROR_AND_DIE_THROW_FMT((Family.ExtendedFamilyID & ~0xFF) == 0, "ExtendedFamilyID too large"); + ERROR_AND_DIE_THROW_FMT((Family.ProcessorType & ~0xF) == 0, "ProcessorType too large"); + + return Family.Stepping | (Family.Model << 4) | (Family.FamilyID << 8) | (Family.ProcessorType << 12) | (Family.ExtendedModel << 16) | + (Family.ExtendedFamilyID << 20); +} + #ifdef CPUID_AMD -constexpr uint32_t FAMILY_IDENTIFIER = 0 | // Stepping - (0xA << 4) | // Model - (0xF << 8) | // Family ID - (0 << 12) | // Processor type - (0 << 16) | // Extended model ID - (1 << 20); // Extended family ID +constexpr uint32_t FAMILY_IDENTIFIER = GenerateFamily(CPUFamily { + .Stepping = 0, + .Model = 0xA, + .ExtendedModel = 0, + .FamilyID = 0xF, + .ExtendedFamilyID = 1, + .ProcessorType = 0, +}); + #else -constexpr uint32_t FAMILY_IDENTIFIER = 0 | // Stepping - (0x7 << 4) | // Model - (0x6 << 8) | // Family ID - (0 << 12) | // Processor type - (1 << 16) | // Extended model ID - (0x0 << 20); // Extended family ID +constexpr uint32_t FAMILY_IDENTIFIER = GenerateFamily(CPUFamily { + .Stepping = 1, + .Model = 6, + .ExtendedModel = 0xA, + .FamilyID = 6, + .ExtendedFamilyID = 0, + .ProcessorType = 0, +}); #endif #ifdef _M_ARM_64 diff --git a/FEXCore/include/FEXCore/Utils/LogManager.h b/FEXCore/include/FEXCore/Utils/LogManager.h index 32d8b708c3..8093676110 100644 --- a/FEXCore/include/FEXCore/Utils/LogManager.h +++ b/FEXCore/include/FEXCore/Utils/LogManager.h @@ -171,5 +171,12 @@ namespace Msg { FEX_TRAP_EXECUTION; \ } while (0) +#define ERROR_AND_DIE_THROW_FMT(pred, ...) \ + do { \ + if ((pred)) break; \ + LogMan::Msg::EFmt(__VA_ARGS__); \ + FEX_TRAP_EXECUTION; \ + } while (0) + } // namespace Msg } // namespace LogMan