Skip to content

Commit

Permalink
Merge pull request #4056 from Sonicadvance1/context_remove_unused_fea…
Browse files Browse the repository at this point in the history
…tures

FEXCore/Context: Removes unused features
  • Loading branch information
Sonicadvance1 authored Sep 11, 2024
2 parents 4cb4c0e + ae9db33 commit 05be944
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 132 deletions.
16 changes: 0 additions & 16 deletions FEXCore/Source/Interface/Config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,8 @@ fextl::string FindContainerPrefix() {
void ReloadMetaLayer() {
Meta->Load();

// Do configuration option fix ups after everything is reloaded
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_CORE)) {
// Sanitize Core option
FEX_CONFIG_OPT(Core, CORE);
#if (_M_X86_64)
constexpr uint32_t MaxCoreNumber = 1;
#else
constexpr uint32_t MaxCoreNumber = 0;
#endif
if (Core > MaxCoreNumber) {
// Sanitize the core option by setting the core to the JIT if invalid
FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_CORE, fextl::fmt::format("{}", static_cast<uint32_t>(FEXCore::Config::CONFIG_IRJIT)));
}
}

if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_CACHEOBJECTCODECOMPILATION)) {
FEX_CONFIG_OPT(CacheObjectCodeCompilation, CACHEOBJECTCODECOMPILATION);
FEX_CONFIG_OPT(Core, CORE);
}

fextl::string ContainerPrefix {FindContainerPrefix()};
Expand Down
13 changes: 0 additions & 13 deletions FEXCore/Source/Interface/Config/Config.json.in
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
{
"Options": {
"CPU": {
"Core": {
"Type": "uint32",
"Default": "FEXCore::Config::ConfigCore::CONFIG_IRJIT",
"TextDefault": "irjit",
"ShortArg": "c",
"Choices": [ "irjit", "host" ],
"ArgumentHandler": "CoreHandler",
"Desc": [
"Which CPU core to use",
"host only exists on x86_64",
"[irjit, host]"
]
},
"Multiblock": {
"Type": "bool",
"Default": "false",
Expand Down
4 changes: 0 additions & 4 deletions FEXCore/Source/Interface/Context/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ void FEXCore::Context::ContextImpl::CompileRIPCount(FEXCore::Core::InternalThrea
CompileBlock(Thread->CurrentFrame, GuestRIP, MaxInst);
}

void FEXCore::Context::ContextImpl::SetCustomCPUBackendFactory(CustomCPUFactoryType Factory) {
CustomCPUFactory = std::move(Factory);
}

void FEXCore::Context::ContextImpl::SetSignalDelegator(FEXCore::SignalDelegator* _SignalDelegation) {
SignalDelegation = _SignalDelegation;
}
Expand Down
16 changes: 0 additions & 16 deletions FEXCore/Source/Interface/Context/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@
#include <stdint.h>

#include <atomic>
#include <condition_variable>
#include <functional>
#include <istream>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <stddef.h>
#include <queue>

namespace FEXCore {
class CodeLoader;
Expand Down Expand Up @@ -65,11 +59,6 @@ namespace Validation {
} // namespace FEXCore::IR

namespace FEXCore::Context {
enum CoreRunningMode {
MODE_RUN = 0,
MODE_SINGLESTEP = 1,
};

struct ExitFunctionLinkData {
uint64_t HostBranch;
uint64_t GuestRIP;
Expand Down Expand Up @@ -110,8 +99,6 @@ class ContextImpl final : public FEXCore::Context::Context {
void CompileRIP(FEXCore::Core::InternalThreadState* Thread, uint64_t GuestRIP) override;
void CompileRIPCount(FEXCore::Core::InternalThreadState* Thread, uint64_t GuestRIP, uint64_t MaxInst) override;

void SetCustomCPUBackendFactory(CustomCPUFactoryType Factory) override;

void HandleCallback(FEXCore::Core::InternalThreadState* Thread, uint64_t RIP) override;

uint64_t RestoreRIPFromHostPC(FEXCore::Core::InternalThreadState* Thread, uint64_t HostPC) override;
Expand Down Expand Up @@ -220,7 +207,6 @@ class ContextImpl final : public FEXCore::Context::Context {
friend class FEXCore::IR::Validation::IRValidation;

struct {
CoreRunningMode RunningMode {CoreRunningMode::MODE_RUN};
uint64_t VirtualMemSize {1ULL << 36};
uint64_t TSCScale = 0;

Expand All @@ -240,7 +226,6 @@ class ContextImpl final : public FEXCore::Context::Context {
FEX_CONFIG_OPT(AOTIRGenerate, AOTIRGENERATE);
FEX_CONFIG_OPT(AOTIRLoad, AOTIRLOAD);
FEX_CONFIG_OPT(SMCChecks, SMCCHECKS);
FEX_CONFIG_OPT(Core, CORE);
FEX_CONFIG_OPT(MaxInstPerBlock, MAXINST);
FEX_CONFIG_OPT(RootFSPath, ROOTFS);
FEX_CONFIG_OPT(ThunkHostLibsPath, THUNKHOSTLIBS);
Expand Down Expand Up @@ -273,7 +258,6 @@ class ContextImpl final : public FEXCore::Context::Context {
fextl::unique_ptr<FEXCore::ThunkHandler> ThunkHandler;
fextl::unique_ptr<FEXCore::CPU::Dispatcher> Dispatcher;

CustomCPUFactoryType CustomCPUFactory;
FEXCore::Context::ExitHandler CustomExitHandler;

#ifdef BLOCKSTATS
Expand Down
10 changes: 2 additions & 8 deletions FEXCore/Source/Interface/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,8 @@ void ContextImpl::InitializeCompiler(FEXCore::Core::InternalThreadState* Thread)
Thread->PassManager->RegisterSyscallHandler(SyscallHandler);

// Create CPU backend
switch (Config.Core) {
case FEXCore::Config::CONFIG_IRJIT:
Thread->PassManager->InsertRegisterAllocationPass();
Thread->CPUBackend = FEXCore::CPU::CreateArm64JITCore(this, Thread);
break;
case FEXCore::Config::CONFIG_CUSTOM: Thread->CPUBackend = CustomCPUFactory(this, Thread); break;
default: ERROR_AND_DIE_FMT("Unknown core configuration"); break;
}
Thread->PassManager->InsertRegisterAllocationPass();
Thread->CPUBackend = FEXCore::CPU::CreateArm64JITCore(this, Thread);

Thread->PassManager->Finalize();
}
Expand Down
17 changes: 0 additions & 17 deletions FEXCore/include/FEXCore/Config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@

namespace FEXCore::Config {
namespace Handler {
static inline std::optional<fextl::string> CoreHandler(std::string_view Value) {
if (Value == "irjit") {
return "0";
}
#ifdef _M_X86_64
else if (Value == "host") {
return "1";
}
#endif
return "0";
}

static inline std::optional<fextl::string> SMCCheckHandler(std::string_view Value) {
if (Value == "none") {
return "0";
Expand Down Expand Up @@ -60,11 +48,6 @@ enum ConfigOption {
#define ENUMDEFINES
#include <FEXCore/Config/ConfigOptions.inl>

enum ConfigCore {
CONFIG_IRJIT,
CONFIG_CUSTOM,
};

enum ConfigSMCChecks {
CONFIG_SMC_NONE,
CONFIG_SMC_MTRACK,
Expand Down
16 changes: 0 additions & 16 deletions FEXCore/include/FEXCore/Core/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,8 @@ class AOTIRWriter {
virtual void Close() = 0;
};

struct VDSOSigReturn {
void* VDSO_kernel_sigreturn;
void* VDSO_kernel_rt_sigreturn;
};

using CodeRangeInvalidationFn = std::function<void(uint64_t start, uint64_t Length)>;

using CustomCPUFactoryType = std::function<fextl::unique_ptr<CPU::CPUBackend>(Context*, Core::InternalThreadState* Thread)>;
using CustomIREntrypointHandler = std::function<void(uintptr_t Entrypoint, IR::IREmitter*)>;

using ExitHandler = std::function<void(Core::InternalThreadState* Thread, ExitReason)>;
Expand Down Expand Up @@ -130,16 +124,6 @@ class Context {
FEX_DEFAULT_VISIBILITY virtual void CompileRIP(FEXCore::Core::InternalThreadState* Thread, uint64_t GuestRIP) = 0;
FEX_DEFAULT_VISIBILITY virtual void CompileRIPCount(FEXCore::Core::InternalThreadState* Thread, uint64_t GuestRIP, uint64_t MaxInst) = 0;

/**
* @brief Allows the frontend to pass in a custom CPUBackend creation factory
*
* This allows the frontend to have its own frontend. Typically for debugging
*
* @param CTX The context that we created
* @param Factory The factory that the context will call if the DefaultCore config ise set to CUSTOM
*/
FEX_DEFAULT_VISIBILITY virtual void SetCustomCPUBackendFactory(CustomCPUFactoryType Factory) = 0;

FEX_DEFAULT_VISIBILITY virtual void HandleCallback(FEXCore::Core::InternalThreadState* Thread, uint64_t RIP) = 0;

///< State reconstruction helpers
Expand Down
2 changes: 0 additions & 2 deletions Source/Tools/CodeSizeValidation/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,6 @@ int main(int argc, char** argv, char** const envp) {
// Setup configurations that this tool needs
// Maximum one instruction.
FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_MAXINST, "1");
// IRJIT. Only works on JITs.
FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_CORE, fextl::fmt::format("{}", static_cast<uint64_t>(FEXCore::Config::CONFIG_IRJIT)));
// Enable block disassembly.
FEXCore::Config::EraseSet(
FEXCore::Config::CONFIG_DISASSEMBLE,
Expand Down
3 changes: 1 addition & 2 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class SignalDelegator final : public FEXCore::SignalDelegator, public FEXCore::A
}

FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE);
FEX_CONFIG_OPT(Core, CORE);
fextl::string const ApplicationName;
FEXCORE_TELEMETRY_INIT(CrashMask, TYPE_CRASH_MASK);
FEXCORE_TELEMETRY_INIT(UnhandledNonCanonical, TYPE_UNHANDLED_NONCANONICAL_ADDRESS);
Expand Down Expand Up @@ -198,7 +197,7 @@ class SignalDelegator final : public FEXCore::SignalDelegator, public FEXCore::A
bool InstallHostThunk(int Signal);
bool UpdateHostThunk(int Signal);

FEXCore::Context::VDSOSigReturn VDSOPointers {};
FEX::VDSO::VDSOSigReturn VDSOPointers {};

bool IsAddressInDispatcher(uint64_t Address) const {
return Address >= Config.DispatcherBegin && Address < Config.DispatcherEnd;
Expand Down
4 changes: 2 additions & 2 deletions Source/Tools/LinuxEmulation/VDSO_Emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <unistd.h>

namespace FEX::VDSO {
FEXCore::Context::VDSOSigReturn VDSOPointers {};
VDSOSigReturn VDSOPointers {};
namespace VDSOHandlers {
using TimeType = decltype(::time)*;
using GetTimeOfDayType = decltype(::gettimeofday)*;
Expand Down Expand Up @@ -678,7 +678,7 @@ const std::span<FEXCore::IR::ThunkDefinition> GetVDSOThunkDefinitions() {
return VDSODefinitions;
}

const FEXCore::Context::VDSOSigReturn& GetVDSOSymbols() {
const VDSOSigReturn& GetVDSOSymbols() {
return VDSOPointers;
}
} // namespace FEX::VDSO
11 changes: 6 additions & 5 deletions Source/Tools/LinuxEmulation/VDSO_Emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

#include "LinuxSyscalls/Syscalls.h"

namespace FEXCore::Context {
struct VDSOSigReturn;
}

namespace FEX::VDSO {
using MapperFn = std::function<void*(void* addr, size_t length, int prot, int flags, int fd, off_t offset)>;
struct VDSOMapping {
Expand All @@ -17,11 +13,16 @@ struct VDSOMapping {
void* OptionalSigReturnMapping {};
size_t OptionalMappingSize {};
};

struct VDSOSigReturn {
void* VDSO_kernel_sigreturn;
void* VDSO_kernel_rt_sigreturn;
};
VDSOMapping LoadVDSOThunks(bool Is64Bit, FEX::HLE::SyscallHandler* const Handler);
void UnloadVDSOMapping(const VDSOMapping& Mapping);

uint64_t GetVSyscallEntry(const void* VDSOBase);

const std::span<FEXCore::IR::ThunkDefinition> GetVDSOThunkDefinitions();
const FEXCore::Context::VDSOSigReturn& GetVDSOSymbols();
const VDSOSigReturn& GetVDSOSymbols();
} // namespace FEX::VDSO
31 changes: 14 additions & 17 deletions Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ int main(int argc, char** argv, char** const envp) {
FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_DISABLE_VIXL_INDIRECT_RUNTIME_CALLS, "0");
#endif

FEX_CONFIG_OPT(Core, CORE);

#ifndef _WIN32
fextl::unique_ptr<FEX::HLE::MemAllocator> Allocator;

Expand Down Expand Up @@ -276,21 +274,20 @@ int main(int argc, char** argv, char** const envp) {
(!HostFeatures.SupportsAES256 && Loader.RequiresAES256()) || (!HostFeatures.SupportsAFP && Loader.RequiresAFP());


bool IsHostRunner = false;
#if !defined(VIXL_SIMULATOR) && defined(_M_X86_64)
const bool IsHostRunner = Core == FEXCore::Config::CONFIG_CUSTOM;
if (IsHostRunner) {
///< Features that are only unsupported when running using the HostRunner and the CI machine doesn't support the feature getting tested.
Xbyak::util::Cpu X86Features {};
const bool Supports3DNow = X86Features.has(Xbyak::util::Cpu::t3DN) && X86Features.has(Xbyak::util::Cpu::tE3DN);
const bool SupportsSSE4A = X86Features.has(Xbyak::util::Cpu::tSSE4a);
const bool SupportsBMI1 = X86Features.has(Xbyak::util::Cpu::tBMI1);
const bool SupportsBMI2 = X86Features.has(Xbyak::util::Cpu::tBMI2);
const bool SupportsCLWB = X86Features.has(Xbyak::util::Cpu::tCLWB);

TestUnsupported |= (!Supports3DNow && Loader.Requires3DNow()) || (!SupportsSSE4A && Loader.RequiresSSE4A()) ||
(!SupportsBMI1 && Loader.RequiresBMI1()) || (!SupportsBMI2 && Loader.RequiresBMI2()) ||
(!SupportsCLWB && Loader.RequiresCLWB());
}
IsHostRunner = true;
///< Features that are only unsupported when running using the HostRunner and the CI machine doesn't support the feature getting tested.
Xbyak::util::Cpu X86Features {};
const bool Supports3DNow = X86Features.has(Xbyak::util::Cpu::t3DN) && X86Features.has(Xbyak::util::Cpu::tE3DN);
const bool SupportsSSE4A = X86Features.has(Xbyak::util::Cpu::tSSE4a);
const bool SupportsBMI1 = X86Features.has(Xbyak::util::Cpu::tBMI1);
const bool SupportsBMI2 = X86Features.has(Xbyak::util::Cpu::tBMI2);
const bool SupportsCLWB = X86Features.has(Xbyak::util::Cpu::tCLWB);

TestUnsupported |= (!Supports3DNow && Loader.Requires3DNow()) || (!SupportsSSE4A && Loader.RequiresSSE4A()) ||
(!SupportsBMI1 && Loader.RequiresBMI1()) || (!SupportsBMI2 && Loader.RequiresBMI2()) ||
(!SupportsCLWB && Loader.RequiresCLWB());
#endif

#ifdef _WIN32
Expand All @@ -301,7 +298,7 @@ int main(int argc, char** argv, char** const envp) {
return 0;
}

if (Core != FEXCore::Config::CONFIG_CUSTOM) {
if (!IsHostRunner) {
#ifndef _WIN32
auto SyscallHandler = Loader.Is64BitMode() ? FEX::HLE::x64::CreateHandler(CTX.get(), SignalDelegation.get()) :
FEX::HLE::x32::CreateHandler(CTX.get(), SignalDelegation.get(), std::move(Allocator));
Expand Down
8 changes: 4 additions & 4 deletions unittests/32Bit_ASM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ foreach(ASM_SRC ${ASM_SOURCES})
set(TEST_ARGS)
if (_M_ARM_64 OR ENABLE_VIXL_SIMULATOR)
list(APPEND TEST_ARGS
"--no-silent -g -c irjit -n 1 --no-multiblock" "jit_1" "jit"
"--no-silent -g -c irjit -n 500 --no-multiblock" "jit_500" "jit"
"--no-silent -g -c irjit -n 500 --multiblock" "jit_500_m" "jit"
"--no-silent -g -n 1 --no-multiblock" "jit_1" "jit"
"--no-silent -g -n 500 --no-multiblock" "jit_500" "jit"
"--no-silent -g -n 500 --multiblock" "jit_500_m" "jit"
)
endif()

if (ENABLE_VIXL_SIMULATOR)
set(CPU_CLASS Simulator)
elseif (_M_X86_64)
list(APPEND TEST_ARGS
"--no-silent -g -c host" "host" "host"
"--no-silent -g" "host" "host"
)
endif()

Expand Down
8 changes: 4 additions & 4 deletions unittests/ASM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ foreach(ASM_SRC ${ASM_SOURCES})
set(TEST_ARGS)
if (_M_ARM_64 OR ENABLE_VIXL_SIMULATOR)
list(APPEND TEST_ARGS
"--no-silent -g -c irjit -n 1 --no-multiblock" "jit_1" "jit"
"--no-silent -g -c irjit -n 500 --no-multiblock" "jit_500" "jit"
"--no-silent -g -c irjit -n 500 --multiblock" "jit_500_m" "jit"
"--no-silent -g -n 1 --no-multiblock" "jit_1" "jit"
"--no-silent -g -n 500 --no-multiblock" "jit_500" "jit"
"--no-silent -g -n 500 --multiblock" "jit_500_m" "jit"
)
endif()

if (ENABLE_VIXL_SIMULATOR)
set(CPU_CLASS Simulator)
elseif (_M_X86_64)
list(APPEND TEST_ARGS
"--no-silent -g -c host" "host" "host"
"--no-silent -g" "host" "host"
)
endif()

Expand Down
2 changes: 1 addition & 1 deletion unittests/FEXLinuxTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function(AddTests Tests BinDirectory Bitness)
"guest"
"$<TARGET_FILE:FEXLoader>"
${THUNK_ARGS}
"-o" "stderr" "--no-silent" "-c" "irjit" "-n" "500" "--"
"-o" "stderr" "--no-silent" "-n" "500" "--"
"${BIN_PATH}")

if (_M_X86_64 AND NOT TEST_NAME STREQUAL "thunk_testlib")
Expand Down
2 changes: 1 addition & 1 deletion unittests/POSIX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ foreach(POSIX_TEST ${POSIX_TESTS})
"${TEST_NAME}"
"guest"
"${CMAKE_BINARY_DIR}/Bin/FEXLoader"
"-o" "stderr" "--no-silent" "-c" "irjit" "-n" "500" "--"
"-o" "stderr" "--no-silent" "-n" "500" "--"
"${POSIX_TEST}")
set_property(TEST "${TEST_NAME}.jit.posix" APPEND PROPERTY SKIP_RETURN_CODE 125)
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion unittests/ThunkFunctionalTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function(AddThunksTest Bin ThunksFile)
set (ARGS
"-t" "${CMAKE_INSTALL_PREFIX}/lib/fex-emu/HostThunks"
"-j" "${CMAKE_INSTALL_PREFIX}/share/fex-emu/GuestThunks"
"-o" "stderr" "--no-silent" "-c" "irjit" "-n" "500"
"-o" "stderr" "--no-silent" "-n" "500"
)
if (NOT ThunksFile)
set (TEST_NAME ThunkFunctionalTest-NoThunks-${Bin})
Expand Down
Loading

0 comments on commit 05be944

Please sign in to comment.