Skip to content

Commit

Permalink
Merge branch 'master' into jit-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillonb committed Sep 4, 2024
2 parents 220b811 + e3bf287 commit 9f01ef8
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 20 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ jobs:
path: upload

build-nix:
runs-on: ubuntu-22.04
strategy:
matrix:
os:
- ubuntu-22.04
- macos-14
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ else()
endif()
endif()

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set (X86 TRUE)
else ()
set (X86 FALSE)
endif ()

check_c_compiler_flag("-mssse3" HAS_SSSE3)
check_c_compiler_flag("-msse4.1" HAS_SSE4_1)

if (HAS_SSSE3 AND HAS_SSE4_1)
if (HAS_SSSE3 AND HAS_SSE4_1 AND X86)
set(DEFAULT_C_COMP_OPTIONS ${DEFAULT_C_COMP_OPTIONS} -mssse3 -msse4.1)
ADD_COMPILE_DEFINITIONS(N64_HAVE_SSE)
endif()
Expand Down
25 changes: 19 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@
pkgs.capstone
pkgs.dbus
pkgs.bzip2
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Cocoa
];
stdenv = if pkgs.stdenv.isLinux then pkgs.stdenv
else if pkgs.stdenv.isDarwin then pkgs.clang18Stdenv
else throw "Unsupported platform";
in
{
packages.default = pkgs.stdenv.mkDerivation
packages.default = stdenv.mkDerivation
{
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./src/jit/Cargo.lock;
Expand All @@ -66,20 +71,28 @@
(pkgs.lib.cmakeFeature "CMAKE_BUILD_TYPE" "Release")
];
passthru.exePath = "/bin/n64";
postInstall = ''
wrapProgram $out/bin/n64 --set LD_LIBRARY_PATH ${pkgs.vulkan-loader}/lib
'';
postInstall =
if pkgs.stdenv.isLinux then ''
wrapProgram $out/bin/n64 --set LD_LIBRARY_PATH ${pkgs.vulkan-loader}/lib
'' else if pkgs.stdenv.isDarwin then ''
wrapProgram $out/bin/n64 --set DYLD_FALLBACK_LIBRARY_PATH ${pkgs.darwin.moltenvk}/lib
'' else throw "Unsupported platform";

};

apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/n64";
};

devShells.default = pkgs.mkShell
devShells.default = pkgs.mkShell.override { stdenv = stdenv; }
{
buildInputs = devShellTools ++ tools ++ libs;
LD_LIBRARY_PATH = "${pkgs.vulkan-loader}/lib";
shellHook = if stdenv.isLinux then ''
export LD_LIBRARY_PATH="${pkgs.vulkan-loader}/lib";
'' else if stdenv.isDarwin then ''
export DYLD_FALLBACK_LIBRARY_PATH="${pkgs.darwin.moltenvk}/lib";
'' else throw "Unsupported platform";
};
}
);
Expand Down
8 changes: 4 additions & 4 deletions src/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ typedef __m128i s128;
#define ASSERTDWORD(type) _Static_assert(sizeof(type) == 8, #type " must be 64 bits")
#endif

#ifndef N64_WIN
#if defined(N64_WIN) || defined(N64_MACOS)
#define PATH_MAX 0x1000
#else
#include <unistd.h>
#include <linux/limits.h>
#else
#define PATH_MAX 0x1000
#endif


Expand All @@ -69,7 +69,7 @@ INLINE u32 npow2(u32 x) {
}

INLINE bool file_exists(const char* path) {
#ifndef N64_WIN
#if !defined(N64_WIN) && !defined(N64_MACOS)
return access(path, F_OK) == 0;
#else
FILE* f = fopen(path, "r");
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/fpu_instructions.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void set_cause_cvt_l_d(double d) {
#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)
#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)

#ifdef N64_WIN
#if defined(N64_WIN) || defined(N64_MACOS)
#define unordered_s(a, b) (isnan(a) || isnan(b))
#define unordered_d(a, b) (isnan(a) || isnan(b))
#else
Expand Down
2 changes: 2 additions & 0 deletions src/system/mprotect_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void mprotect_rwx(u8* cache, size_t size, const char* cache_name) {
if (!VirtualProtect(cache, size, PAGE_EXECUTE_READWRITE, &oldProtect)) {
mprotect_error(cache_name);
}
#elif defined(N64_MACOS)
// no-op
#else
if (mprotect(cache, size, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) {
mprotect_error(cache_name);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dynarec_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void test_branch_likely(bool jit) {
n64_system_step(false, 1);

assert_reg_value((u64)0, MIPS_REG_T0);
assert_eq_u64("pc", 0xFFFFFFFF80000008, N64CPU.pc);
assert_eq_u64("pc", 0xFFFFFFFF80000008ULL, N64CPU.pc);

if (jit) {
n64_system_step(true, -1);
Expand All @@ -48,7 +48,7 @@ void test_branch_likely(bool jit) {
}

// Branch was NOT taken.
assert_eq_u64("pc", 0xFFFFFFFF80000014, N64CPU.pc);
assert_eq_u64("pc", 0xFFFFFFFF80000014ULL, N64CPU.pc);

// Delay slot was skipped.
// 0: register is not getting written back at all
Expand Down
3 changes: 2 additions & 1 deletion tests/test_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#define LOG_ENABLED
#include <log.h>
#include <inttypes.h>
#include <system/n64system.h>
#include <cpu/mips_instructions.h>
#include <cpu/r4300i_register_access.h>
Expand All @@ -15,7 +16,7 @@ bool test_complete() {
s64 test_failed = get_register(TEST_FAILED_REGISTER);
if (test_failed != 0) {
if (test_failed != -1) {
logfatal("Test #%ld failed.", test_failed);
logfatal("Test #%" PRId64 " failed.", test_failed);
}

return true;
Expand Down
9 changes: 5 additions & 4 deletions tests/unit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef N64_UNIT_H
#define N64_UNIT_H
#include <cpu/r4300i_register_access.h>
#include <inttypes.h>

static int tests_failed = 0;

Expand Down Expand Up @@ -62,9 +63,9 @@ void test_instr_1_1_imm(case_instr_1_1_imm test_case, mipsinstr_handler_t instr,
u64 actual = get_register(routput);

if (actual != test_case.output) {
failed("%s: r%d, (r%d)%ld, %d | Expected: %ld but got %ld", instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
failed("%s: r%d, (r%d)%" PRId64 ", %d | Expected: %" PRId64 " but got %" PRId64, instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
} else if (SHOULD_LOG_PASSED_TESTS) {
passed("%s: r%d, (r%d)%ld, %d | Expected: %ld and got %ld", instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
passed("%s: r%d, (r%d)%" PRId64 ", %d | Expected: %" PRId64 " and got %" PRId64, instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
}
}

Expand All @@ -88,9 +89,9 @@ void test_instr_2_1(case_instr_2_1 test_case, mipsinstr_handler_t instr, const c
u64 actual = get_register(routput);

if (actual != test_case.output) {
failed("%s: r%d, (r%d)%ld, (r%d)%ld | Expected: %ld but got %ld", instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
failed("%s: r%d, (r%d)%" PRId64 ", (r%d)%" PRId64 " | Expected: %" PRId64 " but got %" PRId64, instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
} else if (SHOULD_LOG_PASSED_TESTS) {
passed("%s: r%d, (r%d)%ld, (r%d)%ld | Expected: %ld and got %ld", instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
passed("%s: r%d, (r%d)%" PRId64 ", (r%d)%" PRId64 " | Expected: %" PRId64 " and got %" PRId64, instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
}
}

Expand Down

0 comments on commit 9f01ef8

Please sign in to comment.