Skip to content

Commit c1ae04a

Browse files
kscophorcys
authored andcommitted
CPU/LoongArch64: Add recompiler
This is mostly a direct translation from the RISC-V backend. Co-Authored-By: phorcys <phorcys@126.com>
1 parent f6d5267 commit c1ae04a

File tree

4 files changed

+2869
-0
lines changed

4 files changed

+2869
-0
lines changed

src/core/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ if(CPU_ARCH_RISCV64)
196196
target_link_libraries(core PRIVATE biscuit::biscuit riscv-disas)
197197
message(STATUS "Building RISC-V-64 recompiler.")
198198
endif()
199+
if(CPU_ARCH_LOONGARCH64)
200+
target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_MMAP_FASTMEM=1")
201+
target_sources(core PRIVATE
202+
${RECOMPILER_SRCS}
203+
cpu_recompiler_loongarch64.cpp
204+
cpu_recompiler_loongarch64.h
205+
)
206+
target_link_libraries(core PRIVATE lagoon)
207+
message(STATUS "Building LoongArch64 recompiler.")
208+
endif()
199209

200210
function(add_core_resources target)
201211
add_util_resources(${target})

src/core/cpu_recompiler.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ class Recompiler
8080
// Align functions to 16 bytes.
8181
static constexpr u32 FUNCTION_ALIGNMENT = 16;
8282

83+
#elif defined(CPU_ARCH_LOONGARCH64)
84+
85+
// Number of host registers.
86+
static constexpr u32 NUM_HOST_REGS = 32;
87+
static constexpr bool HAS_MEMORY_OPERANDS = false;
88+
89+
// A reasonable "maximum" number of bytes per instruction.
90+
static constexpr u32 MAX_NEAR_HOST_BYTES_PER_INSTRUCTION = 64;
91+
static constexpr u32 MIN_CODE_RESERVE_FOR_BLOCK = 512;
92+
93+
// Align functions to 16 bytes.
94+
static constexpr u32 FUNCTION_ALIGNMENT = 16;
95+
8396
#endif
8497

8598
public:

0 commit comments

Comments
 (0)