Skip to content

Commit cd91e31

Browse files
committed
fixes for mac port, update parallel-rdp to a version supported by parallel-rdp
fix macros fix SRC file var
1 parent e267984 commit cd91e31

13 files changed

+90
-21
lines changed

CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
55
set(MACOSX TRUE)
66
endif()
77

8-
ADD_COMPILE_OPTIONS(-mssse3 -msse4.1)
8+
if (NOT MACOSX)
9+
ADD_COMPILE_OPTIONS(-mssse3 -msse4.1)
10+
ADD_COMPILE_DEFINITIONS(N64_USE_SIMD)
11+
ADD_COMPILE_DEFINITIONS(ENABLE_DYNAREC)
12+
set(ENABLE_DYNAREC TRUE)
13+
endif()
914
#ADD_COMPILE_OPTIONS(-DVULKAN_DEBUG)
1015

1116
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DN64_DEBUG_MODE -g")
@@ -35,7 +40,6 @@ endif()
3540
#add_compile_options(-fsanitize=thread)
3641
#add_link_options(-fsanitize=thread)
3742

38-
ADD_COMPILE_DEFINITIONS(N64_USE_SIMD)
3943

4044
project (N64)
4145
set(CMAKE_CXX_STANDARD 17)

src/common/metrics.h

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef enum metric {
2020

2121
extern uint64_t n64_metric_data[NUM_METRICS];
2222

23+
#ifndef N64_MACOS
2324
INLINE void mark_metric(metric_t metric) {
2425
n64_metric_data[metric]++;
2526
}
@@ -41,6 +42,17 @@ INLINE void reset_all_metrics() {
4142
n64_metric_data[i] = 0;
4243
}
4344
}
45+
#else
46+
INLINE void mark_metric(metric_t metric) { }
47+
48+
INLINE void mark_metric_multiple(metric_t metric, int times) { }
49+
50+
INLINE uint64_t get_metric(metric_t metric) { }
51+
52+
INLINE void set_metric(metric_t metric, uint64_t value) { }
53+
54+
INLINE void reset_all_metrics() { }
55+
#endif
4456

4557
#ifdef __cplusplus
4658
}

src/common/util.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ typedef int64_t s64;
3939
#define ASSERTDWORD(type) _Static_assert(sizeof(type) == 8, #type " must be 64 bits")
4040
#endif
4141

42-
#ifndef N64_WIN
42+
#ifdef N64_WIN
43+
#define PATH_MAX 0x1000
44+
#else
4345
#include <unistd.h>
44-
#include <linux/limits.h>
46+
#ifdef N64_MACOS
4547
#else
46-
#define PATH_MAX 0x1000
48+
#include <unistd.h>
49+
#include <linux/limits.h>
50+
#endif
4751
#endif
4852

4953

src/contrib/parallel-rdp/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ add_library(parallel-rdp
2626
parallel-rdp-standalone/vulkan/texture_format.cpp
2727
parallel-rdp-standalone/vulkan/wsi.cpp
2828
parallel-rdp-standalone/vulkan/wsi.hpp
29-
parallel-rdp-standalone/vulkan/wsi_timing.cpp
29+
#parallel-rdp-standalone/vulkan/wsi_timing.cpp
3030
parallel-rdp-standalone/vulkan/wsi_timing.hpp
3131
parallel-rdp-standalone/util/aligned_alloc.cpp
32+
parallel-rdp-standalone/util/arena_allocator.cpp
3233
parallel-rdp-standalone/util/timer.cpp
3334
parallel-rdp-standalone/util/timeline_trace_file.cpp
3435
parallel-rdp-standalone/util/timeline_trace_file.hpp

src/cpu/CMakeLists.txt

+18-9
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ if (WIN32)
1818
set(DYNASM_EXTRA_FLAGS -D WIN)
1919
endif()
2020

21-
add_custom_command(OUTPUT asm_emitter.c
22-
COMMAND $<TARGET_FILE:minilua> ARGS dynasm/dynasm.lua -D X64 ${DYNASM_EXTRA_FLAGS} -o asm_emitter.c ${CMAKE_CURRENT_SOURCE_DIR}/dynarec/asm_emitter.dasc
23-
MAIN_DEPENDENCY dynarec/asm_emitter.dasc
24-
DEPENDS minilua)
21+
if (ENABLE_DYNAREC)
22+
add_custom_command(OUTPUT asm_emitter.c
23+
COMMAND $<TARGET_FILE:minilua> ARGS dynasm/dynasm.lua -D X64 ${DYNASM_EXTRA_FLAGS} -o asm_emitter.c ${CMAKE_CURRENT_SOURCE_DIR}/dynarec/asm_emitter.dasc
24+
MAIN_DEPENDENCY dynarec/asm_emitter.dasc
25+
DEPENDS minilua)
26+
set(DYNAREC_SRC_FILES
27+
dynarec/dynarec.c dynarec/dynarec.h
28+
asm_emitter.c dynarec/asm_emitter.h
29+
dynarec/dynarec_memory_management.c dynarec/dynarec_memory_management.h
30+
)
31+
set(RSP_DYNAREC_SRC_FILES
32+
dynarec/rsp_dynarec.c dynarec/rsp_dynarec.h
33+
)
34+
else()
35+
endif()
2536

2637
add_library(r4300i
2738
r4300i.c r4300i.h r4300i_register_access.h
@@ -30,18 +41,16 @@ add_library(r4300i
3041
tlb_instructions.c tlb_instructions.h
3142
rsp_interface.c rsp_interface.h
3243
mips_instruction_decode.h
33-
dynarec/dynarec.c dynarec/dynarec.h
34-
asm_emitter.c dynarec/asm_emitter.h
35-
dynarec/dynarec_memory_management.c dynarec/dynarec_memory_management.h)
44+
${DYNAREC_SRC_FILES})
3645

3746
add_library(rsp
3847
n64_rsp_bus.h
3948
rsp_types.h rsp_rom.h
4049
rsp.c rsp.h
4150
rsp_instructions.c rsp_instructions.h
4251
rsp_vector_instructions.c rsp_vector_instructions.h
43-
dynarec/rsp_dynarec.c dynarec/rsp_dynarec.h
44-
mips_instruction_decode.h)
52+
mips_instruction_decode.h
53+
${RSP_DYNAREC_SRC_FILES})
4554

4655
TARGET_LINK_LIBRARIES(rsp disassemble)
4756
TARGET_LINK_LIBRARIES(r4300i disassemble common)

src/cpu/dynarec/dynarec.h

+13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ INLINE u32 dynarec_outer_index(u32 physical_address) {
6464
}
6565

6666
INLINE void invalidate_dynarec_page_by_index(u32 outer_index) {
67+
#ifdef ENABLE_DYNAREC
6768
N64DYNAREC->blockcache[outer_index] = NULL;
69+
#endif
6870
}
6971

7072
INLINE bool is_code(u32 physical_address) {
@@ -73,14 +75,25 @@ INLINE bool is_code(u32 physical_address) {
7375
}
7476

7577
INLINE void invalidate_dynarec_page(u32 physical_address) {
78+
#ifdef ENABLE_DYNAREC
7679
if (unlikely(is_code(physical_address))) {
7780
invalidate_dynarec_page_by_index(dynarec_outer_index(physical_address));
7881
}
82+
#endif
7983
}
8084

85+
#ifdef ENABLE_DYNAREC
8186
int n64_dynarec_step();
8287
n64_dynarec_t* n64_dynarec_init(u8* codecache, size_t codecache_size);
8388
void invalidate_dynarec_page(u32 physical_address);
8489
void invalidate_dynarec_all_pages();
90+
#else
91+
INLINE void no_dynarec_err() {
92+
logfatal("Dynarec is disabled at compile time");
93+
}
94+
INLINE int n64_dynarec_step() { no_dynarec_err(); }
95+
INLINE n64_dynarec_t* n64_dynarec_init(u8* codecache, size_t codecache_size) { no_dynarec_err(); }
96+
INLINE void invalidate_dynarec_all_pages() { }
97+
#endif
8598

8699
#endif //N64_DYNAREC_H

src/cpu/fpu_instructions.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void set_cause_cvt_l_d(double d) {
254254
#define check_nans_f(fs, ft) do { assert_is_float(fs); assert_is_float(ft); if (is_nan_f(fs) || is_nan_f(ft)) { set_cause_invalid_operation(); check_fpu_exception(); } } while (0)
255255
#define check_nans_d(fs, ft) do { assert_is_double(fs); assert_is_double(ft); if (is_nan_d(fs) || is_nan_d(ft)) { set_cause_invalid_operation(); check_fpu_exception(); } } while (0)
256256

257-
#ifdef N64_WIN
257+
#if defined(N64_WIN) || defined(N64_MACOS)
258258
#define unordered_s(a, b) (isnan(a) || isnan(b))
259259
#define unordered_d(a, b) (isnan(a) || isnan(b))
260260
#else

src/cpu/rsp.c

+4
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ void rsp_run() {
353353
}
354354

355355
void rsp_dynarec_run() {
356+
#ifdef ENABLE_DYNAREC
356357
int run_for = 0;
357358
// This is set to 0 by the break instruction, and when halted by a write to SP_STATUS_REG
358359
while (N64RSP.steps > 0) {
@@ -361,4 +362,7 @@ void rsp_dynarec_run() {
361362
run_for += taken;
362363
}
363364
mark_metric_multiple(METRIC_RSP_STEPS, run_for);
365+
#else
366+
no_dynarec_err();
367+
#endif
364368
}

src/cpu/rsp.h

+2
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ extern rsp_t n64rsp;
126126
#define N64RSPDYNAREC n64rsp.dynarec
127127

128128
INLINE void quick_invalidate_rsp_icache(u32 address) {
129+
#ifdef ENABLE_DYNAREC
129130
int index = address / 4;
130131

131132
N64RSP.icache[index].handler = cache_rsp_instruction;
132133
N64RSP.icache[index].instruction.raw = word_from_byte_array(N64RSP.sp_imem, address);
133134
N64RSPDYNAREC->blockcache[index].run = rsp_missing_block_handler;
135+
#endif
134136
}
135137

136138
INLINE void invalidate_rsp_icache(u32 address) {

src/cpu/rsp_vector_instructions.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,19 @@ RSP_VECTOR_INSTR(rsp_vec_vcl) {
808808
}
809809
}
810810

811+
#ifdef N64_USE_SIMD
811812
N64RSP.vco.l.single = N64RSP.zero;
812813
N64RSP.vco.h.single = N64RSP.zero;
813814
N64RSP.vce.single = N64RSP.zero;
814815
vd->single = N64RSP.acc.l.single;
816+
#else
817+
for (int i = 0; i < 4; i++) {
818+
N64RSP.vco.l.words[i] = 0;
819+
N64RSP.vco.h.words[i] = 0;
820+
N64RSP.vce.words[i] = 0;
821+
vd->words[i] = N64RSP.acc.l.words[i];
822+
}
823+
#endif
815824
}
816825

817826
RSP_VECTOR_INSTR(rsp_vec_vcr) {
@@ -989,7 +998,7 @@ RSP_VECTOR_INSTR(rsp_vec_vmadh) {
989998
s16 multiplicand1 = vte.elements[e];
990999
s16 multiplicand2 = vs->elements[e];
9911000
s32 prod = multiplicand1 * multiplicand2;
992-
word uprod = prod;
1001+
u32 uprod = prod;
9931002

9941003
u64 acc_delta = (u64)uprod << 16;
9951004
s64 acc = get_rsp_accumulator(e) + acc_delta;
@@ -1684,6 +1693,11 @@ RSP_VECTOR_INSTR(rsp_vec_vzero) {
16841693
defvd;
16851694
for (int i = 0; i < 8; i++) {
16861695
N64RSP.acc.l.elements[i] = vte.elements[i] + vs->elements[i];
1696+
#ifndef N64_USE_SIMD
1697+
vd->elements[i] = 0;
1698+
#endif
16871699
}
1700+
#ifdef N64_USE_SIMD
16881701
vd->single = N64RSP.zero;
1702+
#endif
16891703
}

src/imgui/imgui_ui.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ void render_metrics_window() {
150150
rsp_steps.add_point(get_metric(METRIC_RSP_STEPS));
151151
double frametime = 1000.0f / ImGui::GetIO().Framerate;
152152
frame_times.add_point(frametime);
153+
#ifdef ENABLE_DYNAREC
153154
codecache_bytes_used.add_point(n64sys.dynarec->codecache_used);
155+
#endif
154156
audiostream_bytes_available.add_point(get_metric(METRIC_AUDIOSTREAM_AVAILABLE));
155157

156158
si_interrupts.add_point(get_metric(METRIC_SI_INTERRUPT));
@@ -180,6 +182,7 @@ void render_metrics_window() {
180182
ImPlot::EndPlot();
181183
}
182184

185+
#ifdef ENABLE_DYNAREC
183186
ImGui::Text("Block compilations this frame: %ld", get_metric(METRIC_BLOCK_COMPILATION));
184187
ImPlot::SetNextAxisLimits(ImAxis_Y1, 0, block_complilations.max(), ImGuiCond_Always);
185188
ImPlot::SetNextAxisLimits(ImAxis_X1, 0, METRICS_HISTORY_ITEMS, ImGuiCond_Always);
@@ -194,6 +197,7 @@ void render_metrics_window() {
194197
ImPlot::PlotBars("Codecache bytes used", codecache_bytes_used.data, METRICS_HISTORY_ITEMS, 1, 0, flags, codecache_bytes_used.offset);
195198
ImPlot::EndPlot();
196199
}
200+
#endif
197201

198202
ImGui::Text("Audio stream bytes available: %ld", get_metric(METRIC_AUDIOSTREAM_AVAILABLE));
199203
ImPlot::SetNextAxisLimits(ImAxis_Y1, 0, audiostream_bytes_available.max(), ImGuiCond_Always);

src/system/n64system.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ void init_n64system(const char* rom_path, bool enable_frontend, bool enable_debu
108108

109109
n64sys.video_type = video_type;
110110

111-
mprotect_codecache();
112-
n64sys.dynarec = n64_dynarec_init(codecache, CODECACHE_SIZE);
113-
N64RSP.dynarec = rsp_dynarec_init(rsp_codecache, RSP_CODECACHE_SIZE);
111+
if (!use_interpreter) {
112+
mprotect_codecache();
113+
n64sys.dynarec = n64_dynarec_init(codecache, CODECACHE_SIZE);
114+
N64RSP.dynarec = rsp_dynarec_init(rsp_codecache, RSP_CODECACHE_SIZE);
115+
}
114116

115117
if (enable_frontend) {
116118
render_init(video_type);

0 commit comments

Comments
 (0)