Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ list of the libraries used by PCSX-Redux. Some of them have been
vendored with modifications. If this is the case, you will also
find a link to the vendored version itself.

- [arith64](https://github.com/glitchub/arith64) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/arith64))
- [Capstone](https://github.com/capstone-engine/capstone)
- [Clip](https://github.com/dacap/clip) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/clip))
- [CompletionQueue](https://github.com/bhhbazinga/ConcurrentQueue) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/cq))
Expand Down Expand Up @@ -55,6 +56,7 @@ find a link to the vendored version itself.
- [noto](https://fonts.google.com/noto) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/noto))
- [PEGTL](https://github.com/taocpp/PEGTL)
- [pprint.lua](https://github.com/jagt/pprint.lua) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/pprint.lua))
- [snitch](https://github.com/snitch-org/snitch) ([vendored](https://github.com/grumpycoders/pcsx-redux/tree/main/third_party/snitch))
- [stb](https://github.com/nothings/stb)
- [tracy](https://github.com/wolfpld/tracy)
- [typestring](https://github.com/irrequietus/typestring) ([vendored](https://github.com/grumpycoders/pcsx-redux/blob/main/third_party/typestring.hh))
Expand Down
4 changes: 4 additions & 0 deletions src/mips/common/crt0/cxxglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,7 @@ __attribute__((weak)) void __cxa_guard_release(uint32_t* guardObject) {
guardObject[1] = 0;
atomic_signal_fence(memory_order_release);
}

__attribute__((weak)) void _ZSt24__throw_out_of_range_fmtPKcz(const char* format, ...) {
abort();
}
16 changes: 16 additions & 0 deletions src/mips/psyqo/snitch.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ifndef SNITCHDIR
SNITCHDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))snitch/

LIBRARIES += $(SNITCHDIR)libsnitch.a
CPPFLAGS += -I$(SNITCHDIR)../../../../third_party/snitch

include $(SNITCHDIR)../../psyqo/psyqo.mk

$(SNITCHDIR)libsnitch.a:
$(MAKE) -C $(SNITCHDIR) BUILD=$(BUILD)

clean::
$(MAKE) -C $(SNITCHDIR) clean

.PHONY: clean $(SNITCHDIR)libsnitch.a
endif
11 changes: 11 additions & 0 deletions src/mips/psyqo/snitch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TARGET = snitch
TYPE = library

SRCS = \
../../../../third_party/arith64/arith64.c \
snitch-impl.cpp \

CPPFLAGS = -I../../../../third_party/snitch
CXXFLAGS = -std=c++20

include ../../common.mk
3 changes: 3 additions & 0 deletions src/mips/psyqo/snitch/snitch-impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Single translation unit for snitch header-only library.
#define SNITCH_IMPLEMENTATION
#include "snitch_all.hpp"
2 changes: 2 additions & 0 deletions src/mips/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ all:
$(MAKE) -C memcpy all
$(MAKE) -C memset all
$(MAKE) -C pcdrv all
$(MAKE) -C psyqo all
$(MAKE) -C timers all

clean:
Expand All @@ -20,4 +21,5 @@ clean:
$(MAKE) -C memcpy clean
$(MAKE) -C memset clean
$(MAKE) -C pcdrv clean
$(MAKE) -C psyqo clean
$(MAKE) -C timers clean
17 changes: 17 additions & 0 deletions src/mips/tests/psyqo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
TARGET = psyqo-tests
TYPE = ps-exe

SRCS = \
psyqo-tests.cpp \
test-fixed-point.cpp \
test-vector.cpp \
test-trigonometry.cpp \
test-soft-math.cpp \
test-msf.cpp \
test-adler32.cpp \
test-bezier.cpp \
test-primitives.cpp \

CXXFLAGS = -std=c++20

include ../../psyqo/snitch.mk
53 changes: 53 additions & 0 deletions src/mips/tests/psyqo/psyqo-tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*

MIT License

Copyright (c) 2026 PCSX-Redux authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "common/hardware/pcsxhw.h"
#include "common/syscalls/syscalls.h"

#include "snitch_all.hpp"

static void psyqo_console_print(std::string_view message) noexcept {
for (char c : message) {
syscall_putchar(c);
}
}

int main() {
snitch::cli::console_print = &psyqo_console_print;
snitch::tests.print_callback = &psyqo_console_print;

bool success = snitch::tests.run_tests("psyqo");

if (success) {
ramsyscall_printf("All tests passed!\n");
} else {
ramsyscall_printf("Some tests FAILED!\n");
}

// Signal to the emulator via exit code.
pcsx_exit(success ? 0 : 1);
return success ? 0 : 1;
}
108 changes: 108 additions & 0 deletions src/mips/tests/psyqo/test-adler32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*

MIT License

Copyright (c) 2026 PCSX-Redux authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "psyqo/adler32.hh"

#include "snitch_all.hpp"

using namespace psyqo;

// --- Basic checksums ---

TEST_CASE("Adler32 empty buffer") {
uint32_t sum = adler32(nullptr, 0);
REQUIRE(sum == 1);
}

TEST_CASE("Adler32 single byte") {
uint8_t data[] = {0x01};
uint32_t sum = adler32(data, 1);
// Initial: a=1, b=0. After byte 1: a = 1+1 = 2, b = 0+2 = 2.
REQUIRE(sum == ((2 << 16) | 2));
}

TEST_CASE("Adler32 known vector: 123456789") {
// RFC 1950 test vector
uint8_t data[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
uint32_t sum = adler32(data, 9);
REQUIRE(sum == 0x091e01de);
}

TEST_CASE("Adler32 all zeros") {
uint8_t data[10] = {};
uint32_t sum = adler32(data, 10);
// Initial: a=1, b=0. Each zero byte: a stays 1, b += a = b+1.
// After 10 zeros: a=1, b=10.
REQUIRE(sum == ((10 << 16) | 1));
}

// --- Chaining ---

TEST_CASE("Adler32 chaining produces same result") {
uint8_t data[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
uint32_t whole = adler32(data, 9);

// Compute in two chunks
uint32_t partial = adler32(data, 4);
uint32_t chained = adler32(data + 4, 5, partial);
REQUIRE(chained == whole);
}

TEST_CASE("Adler32 chaining three chunks") {
uint8_t data[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
uint32_t whole = adler32(data, 9);

uint32_t s1 = adler32(data, 3);
uint32_t s2 = adler32(data + 3, 3, s1);
uint32_t s3 = adler32(data + 6, 3, s2);
REQUIRE(s3 == whole);
}

// --- Byte vs word consistency ---

TEST_CASE("Adler32 byte and word variants match") {
// Word-aligned data
uint32_t words[] = {0x04030201, 0x08070605};
uint8_t *bytes = reinterpret_cast<uint8_t *>(words);

uint32_t byte_sum = adler32_bytes(bytes, 8);
uint32_t word_sum = adler32_words(words, 2);
REQUIRE(byte_sum == word_sum);
}

// --- Larger buffer ---

TEST_CASE("Adler32 sequential byte pattern") {
uint8_t data[256];
for (int i = 0; i < 256; i++) data[i] = i;
uint32_t sum = adler32(data, 256);
// Just verify it's non-trivial and deterministic
REQUIRE(sum != 0);
REQUIRE(sum != 1);
// Re-compute to verify determinism
uint32_t sum2 = adler32(data, 256);
REQUIRE(sum == sum2);
}
128 changes: 128 additions & 0 deletions src/mips/tests/psyqo/test-bezier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*

MIT License

Copyright (c) 2026 PCSX-Redux authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "psyqo/bezier.hh"

#include "snitch_all.hpp"

using namespace psyqo;
using namespace psyqo::fixed_point_literals;

// --- Endpoint interpolation ---

TEST_CASE("Bezier cubic at t=0 returns start point") {
Vec2 a, b, c, d;
a.x = 0.0; a.y = 0.0;
b.x = 1.0; b.y = 2.0;
c.x = 3.0; c.y = 4.0;
d.x = 5.0; d.y = 6.0;
auto p = Bezier::cubic(a, b, c, d, 0.0_fp);
REQUIRE(p.x.raw() == a.x.raw());
REQUIRE(p.y.raw() == a.y.raw());
}

TEST_CASE("Bezier cubic at t=1 returns end point") {
Vec2 a, b, c, d;
a.x = 0.0; a.y = 0.0;
b.x = 1.0; b.y = 2.0;
c.x = 3.0; c.y = 4.0;
d.x = 5.0; d.y = 6.0;
auto p = Bezier::cubic(a, b, c, d, 1.0_fp);
auto dx = p.x.raw() - d.x.raw();
auto dy = p.y.raw() - d.y.raw();
REQUIRE(dx >= -5);
REQUIRE(dx <= 5);
REQUIRE(dy >= -5);
REQUIRE(dy <= 5);
}

// --- Linear case ---

TEST_CASE("Bezier cubic with collinear control points is linear") {
Vec2 a, b, c, d;
a.x = 0.0; a.y = 0.0;
b.x = 1.0; b.y = 1.0;
c.x = 2.0; c.y = 2.0;
d.x = 3.0; d.y = 3.0;
auto mid = Bezier::cubic(a, b, c, d, 0.5_fp);
auto diff_x = mid.x.raw() - FixedPoint<>(1.5).raw();
auto diff_y = mid.y.raw() - FixedPoint<>(1.5).raw();
REQUIRE(diff_x >= -5);
REQUIRE(diff_x <= 5);
REQUIRE(diff_y >= -5);
REQUIRE(diff_y <= 5);
}

// --- 3D variant ---

TEST_CASE("Bezier 3D cubic at t=0 returns start") {
Vec3 a, b, c, d;
a.x = 1.0; a.y = 2.0; a.z = 3.0;
b.x = 4.0; b.y = 5.0; b.z = 6.0;
c.x = 7.0; c.y = 8.0; c.z = 9.0;
d.x = 10.0; d.y = 11.0; d.z = 12.0;
auto p = Bezier::cubic(a, b, c, d, 0.0_fp);
REQUIRE(p.x.raw() == a.x.raw());
REQUIRE(p.y.raw() == a.y.raw());
REQUIRE(p.z.raw() == a.z.raw());
}

TEST_CASE("Bezier 3D cubic at t=1 returns end") {
Vec3 a, b, c, d;
a.x = 1.0; a.y = 2.0; a.z = 3.0;
b.x = 4.0; b.y = 5.0; b.z = 6.0;
c.x = 7.0; c.y = 8.0; c.z = 9.0;
d.x = 10.0; d.y = 11.0; d.z = 12.0;
auto p = Bezier::cubic(a, b, c, d, 1.0_fp);
auto dx = p.x.raw() - d.x.raw();
auto dy = p.y.raw() - d.y.raw();
auto dz = p.z.raw() - d.z.raw();
REQUIRE(dx >= -5);
REQUIRE(dx <= 5);
REQUIRE(dy >= -5);
REQUIRE(dy <= 5);
REQUIRE(dz >= -5);
REQUIRE(dz <= 5);
}

// --- Midpoint with symmetric curve ---

TEST_CASE("Bezier symmetric curve midpoint") {
// Symmetric curve: a=(0,0), b=(0,1), c=(1,1), d=(1,0)
// At t=0.5, the midpoint should be approximately (0.5, 0.75)
Vec2 a, b, c, d;
a.x = 0.0; a.y = 0.0;
b.x = 0.0; b.y = 1.0;
c.x = 1.0; c.y = 1.0;
d.x = 1.0; d.y = 0.0;
auto mid = Bezier::cubic(a, b, c, d, 0.5_fp);
auto dx = mid.x.raw() - FixedPoint<>(0.5).raw();
auto dy = mid.y.raw() - FixedPoint<>(0.75).raw();
REQUIRE(dx >= -10);
REQUIRE(dx <= 10);
REQUIRE(dy >= -10);
REQUIRE(dy <= 10);
}
Loading
Loading