Allow building without dynarec v1

This commit is contained in:
Dillon Beliveau 2023-08-27 23:21:01 -07:00
parent 72252bcff0
commit 9f1e3f0df7
7 changed files with 103 additions and 38 deletions

View file

@ -75,5 +75,28 @@ add_link_options("$<$<COMPILE_LANGUAGE:CXX>:${DEFAULT_C_LINK_OPTIONS}>")
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/version.h.in ${CMAKE_CURRENT_LIST_DIR}/src/generated/version.h)
set(N64_DYNAREC_ENABLED true)
set(N64_DYNAREC_V1_ENABLED false) # For the RSP, for now. Only works on x64.
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
set(N64_DYNAREC_ARCH "x86_64")
set(N64_DYNAREC_V1_ENABLED true)
else()
set(N64_DYNAREC_ENABLED false)
endif()
if (N64_DYNAREC_ENABLED)
message("Dynarec enabled!")
add_compile_definitions(N64_DYNAREC_ENABLED)
else()
message("Dynarec not enabled.")
endif()
if (N64_DYNAREC_V1_ENABLED)
message("Dynarec V1 enabled!")
add_compile_definitions(N64_DYNAREC_V1_ENABLED)
else()
message("Dynarec V1 not enabled.")
endif()
add_subdirectory(src)
add_subdirectory(tests)

View file

@ -8,26 +8,6 @@ configure_file(../contrib/tools/dynasm/dasm_ppc.lua dynasm/dasm_ppc.lua COPYONLY
configure_file(../contrib/tools/dynasm/dasm_x64.lua dynasm/dasm_x64.lua COPYONLY)
configure_file(../contrib/tools/dynasm/dasm_x86.lua dynasm/dasm_x86.lua COPYONLY)
add_executable(minilua ../contrib/tools/minilua.c)
if (NOT WIN32)
target_link_libraries(minilua m)
endif()
if (WIN32)
set(DYNASM_EXTRA_FLAGS -D WIN)
endif()
add_custom_command(OUTPUT v1_emitter.c
COMMAND $<TARGET_FILE:minilua> ARGS dynasm/dynasm.lua -D X64 ${DYNASM_EXTRA_FLAGS} -o v1_emitter.c ${CMAKE_CURRENT_SOURCE_DIR}/dynarec/v1/v1_emitter.dasc
MAIN_DEPENDENCY dynarec/v1/v1_emitter.dasc
DEPENDS minilua)
add_custom_command(OUTPUT v2_emitter.c
COMMAND $<TARGET_FILE:minilua> ARGS dynasm/dynasm.lua -D X64 ${DYNASM_EXTRA_FLAGS} -o v2_emitter.c ${CMAKE_CURRENT_SOURCE_DIR}/dynarec/v2/v2_emitter.dasc
MAIN_DEPENDENCY dynarec/v2/v2_emitter.dasc
DEPENDS minilua)
add_library(r4300i
r4300i.c r4300i.h r4300i_register_access.h
mips_instructions.c mips_instructions.h
@ -35,16 +15,14 @@ add_library(r4300i
tlb_instructions.c tlb_instructions.h
rsp_interface.c rsp_interface.h
mips_instruction_decode.h
)
dynarec/dynasm_impl.c
set(DYNAREC_COMMON_SOURCES
dynarec/dynarec.c dynarec/dynarec.h
dynarec/dynarec_memory_management.c dynarec/dynarec_memory_management.h
dynarec/v1/v1_compiler.c dynarec/v1/v1_compiler.h
v1_emitter.c dynarec/v1/v1_emitter.h
v2_emitter.c dynarec/v2/v2_emitter.h
dynarec/dynasm_impl.c
)
set (DYNAREC_V2_SOURCES
dynarec/v2/v2_compiler.c dynarec/v2/v2_compiler.h dynarec/v2/v2_compiler_platformspecific.h
dynarec/v2/ir_context.c dynarec/v2/ir_context.h
dynarec/v2/ir_emitter.c dynarec/v2/ir_emitter.h
@ -53,15 +31,6 @@ add_library(r4300i
dynarec/v2/target_platform.h
dynarec/v2/register_allocator.c dynarec/v2/register_allocator.h)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
target_sources(r4300i PRIVATE
dynarec/v2/x86_64_target_platform.c
dynarec/v2/v2_compiler_x64.c
)
else()
message(FATAL_ERROR "Unsupported target CPU architecture ${CMAKE_SYSTEM_PROCESSOR}")
endif()
message("System processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
add_library(rsp
@ -70,7 +39,6 @@ add_library(rsp
rsp.c rsp.h
rsp_instructions.c rsp_instructions.h
rsp_vector_instructions.c rsp_vector_instructions.h
dynarec/rsp_dynarec.c dynarec/rsp_dynarec.h
mips_instruction_decode.h)
TARGET_LINK_LIBRARIES(rsp disassemble)
@ -79,6 +47,59 @@ if (NOT WIN32)
TARGET_LINK_LIBRARIES(r4300i m)
endif()
if (N64_DYNAREC_V1_ENABLED OR N64_DYNAREC_ENABLED)
target_sources(r4300i PRIVATE
${DYNAREC_COMMON_SOURCES}
)
endif()
if (N64_DYNAREC_V1_ENABLED OR (N64_DYNAREC_ENABLED AND N64_DYNAREC_ARCH STREQUAL "x86_64"))
add_executable(minilua ../contrib/tools/minilua.c)
if (NOT WIN32)
target_link_libraries(minilua m)
endif()
if (WIN32)
set(DYNASM_EXTRA_FLAGS -D WIN)
endif()
if (N64_DYNAREC_V1_ENABLED)
add_custom_command(OUTPUT v1_emitter.c
COMMAND $<TARGET_FILE:minilua> ARGS dynasm/dynasm.lua -D X64 ${DYNASM_EXTRA_FLAGS} -o v1_emitter.c ${CMAKE_CURRENT_SOURCE_DIR}/dynarec/v1/v1_emitter.dasc
MAIN_DEPENDENCY dynarec/v1/v1_emitter.dasc
DEPENDS minilua)
target_sources(r4300i PRIVATE
dynarec/v1/v1_compiler.c dynarec/v1/v1_compiler.h
v1_emitter.c dynarec/v1/v1_emitter.h
)
target_sources(rsp PRIVATE
dynarec/rsp_dynarec.c dynarec/rsp_dynarec.h
)
endif()
endif()
if (N64_DYNAREC_ENABLED)
target_sources(r4300i PRIVATE
${DYNAREC_V2_SOURCES}
)
if (N64_DYNAREC_ARCH STREQUAL "x86_64")
add_custom_command(OUTPUT v2_emitter.c
COMMAND $<TARGET_FILE:minilua> ARGS dynasm/dynasm.lua -D X64 ${DYNASM_EXTRA_FLAGS} -o v2_emitter.c ${CMAKE_CURRENT_SOURCE_DIR}/dynarec/v2/v2_emitter.dasc
MAIN_DEPENDENCY dynarec/v2/v2_emitter.dasc
DEPENDS minilua)
target_sources(r4300i PRIVATE
v2_emitter.c dynarec/v2/v2_emitter.h
dynarec/v2/x86_64_target_platform.c
dynarec/v2/v2_compiler_x64.c
)
endif()
endif()
find_package(Capstone)
IF(Capstone_FOUND)

View file

@ -174,7 +174,9 @@ void n64_dynarec_init(u8* codecache, size_t codecache_size) {
n64dynarec.codecache = codecache;
#ifdef N64_DYNAREC_V1_ENABLED
v1_compiler_init();
#endif
v2_compiler_init();
}

View file

@ -12,6 +12,7 @@ void flush_code_cache() {
}
}
#ifdef N64_DYNAREC_V1_ENABLED
void flush_rsp_code_cache() {
// Just set the pointer back to the beginning, no need to clear the actual data.
N64RSPDYNAREC->codecache_used = 0;
@ -21,6 +22,7 @@ void flush_rsp_code_cache() {
N64RSPDYNAREC->blockcache[i].run = rsp_missing_block_handler;
}
}
#endif
void* dynarec_bumpalloc(size_t size) {
if (n64dynarec.codecache_used + size >= n64dynarec.codecache_size) {
@ -48,6 +50,7 @@ void* dynarec_bumpalloc_zero(size_t size) {
return ptr;
}
#ifdef N64_DYNAREC_V1_ENABLED
void* rsp_dynarec_bumpalloc(size_t size) {
if (N64RSPDYNAREC->codecache_used + size >= N64RSPDYNAREC->codecache_size) {
flush_rsp_code_cache();
@ -63,3 +66,4 @@ void* rsp_dynarec_bumpalloc(size_t size) {
return ptr;
}
#endif

View file

@ -352,6 +352,7 @@ void rsp_run() {
mark_metric_multiple(METRIC_RSP_STEPS, run_for);
}
#ifdef N64_DYNAREC_V1_ENABLED
void rsp_dynarec_run() {
int run_for = 0;
// This is set to 0 by the break instruction, and when halted by a write to SP_STATUS_REG
@ -362,3 +363,4 @@ void rsp_dynarec_run() {
}
mark_metric_multiple(METRIC_RSP_STEPS, run_for);
}
#endif

View file

@ -130,7 +130,9 @@ INLINE void quick_invalidate_rsp_icache(u32 address) {
N64RSP.icache[index].handler = cache_rsp_instruction;
N64RSP.icache[index].instruction.raw = word_from_byte_array(N64RSP.sp_imem, address);
#ifdef N64_DYNAREC_V1_ENABLED
N64RSPDYNAREC->blockcache[index].run = rsp_missing_block_handler;
#endif
}
INLINE void invalidate_rsp_icache(u32 address) {
@ -410,7 +412,9 @@ INLINE void rsp_set_vce(u16 vce) {
void rsp_step();
void rsp_run();
#ifdef N64_DYNAREC_V1_ENABLED
void rsp_dynarec_run();
#endif
vu_reg_t ext_get_vte(vu_reg_t* vt, u8 e);
#endif //N64_RSP_H

View file

@ -84,7 +84,9 @@ void init_n64system(const char* rom_path, bool enable_frontend, bool enable_debu
mprotect_codecache();
n64_dynarec_init(codecache, CODECACHE_SIZE);
#ifdef N64_DYNAREC_V1_ENABLED
N64RSP.dynarec = rsp_dynarec_init(rsp_codecache, RSP_CODECACHE_SIZE);
#endif
if (enable_frontend) {
render_init(video_type);
@ -323,8 +325,11 @@ int n64_system_step(bool dynarec, int steps) {
// 2 RSP steps per 3 CPU steps
N64RSP.steps += (cpu_steps / 3) * 2;
cpu_steps %= 3;
#ifdef N64_DYNAREC_V1_ENABLED
rsp_dynarec_run();
#else
rsp_run();
#endif
} else {
N64RSP.steps = 0;
cpu_steps = 0;
@ -364,7 +369,11 @@ void jit_system_loop() {
N64RSP.steps += (cpu_steps / 3) * 2;
cpu_steps %= 3;
#ifdef N64_DYNAREC_V1_ENABLED
rsp_dynarec_run();
#else
rsp_run();
#endif
} else {
N64RSP.steps = 0;
cpu_steps = 0;