You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/games-emulation/bsnes-jg/files/bsnes-jg-1.1.2-strict-alias...

68 lines
2.2 KiB

https://bugs.gentoo.org/926077
https://github.com/LIJI32/SameBoy/pull/593
https://gitlab.com/jgemu/bsnes/-/merge_requests/419
https://gitlab.com/jgemu/bsnes/-/commit/966545bb79cc9810fbcedbe34fd52f7b9b5ef04e
From 966545bb79cc9810fbcedbe34fd52f7b9b5ef04e Mon Sep 17 00:00:00 2001
From: Lior Halphon <LIJI32@gmail.com>
Date: Sat, 9 Mar 2024 11:08:01 -0800
Subject: [PATCH 1/2] Avoid strict aliasing violations. Closes #593
Backported from:
https://github.com/LIJI32/SameBoy/commit/8739da61c013e20e1cc94f0619c622a65c713408
---
deps/gb/apu.c | 4 ++--
deps/gb/apu.h | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/deps/gb/apu.c b/deps/gb/apu.c
index e621e82a..0f0ed16b 100644
--- a/deps/gb/apu.c
+++ b/deps/gb/apu.c
@@ -100,7 +100,7 @@ static void update_sample(GB_gameboy_t *gb, GB_channel_t index, int8_t value, un
output.left = output.right = 0;
}
- if (*(uint32_t *)&(gb->apu_output.current_sample[index]) != *(uint32_t *)&output) {
+ if (gb->apu_output.current_sample[index].packed != output.packed) {
refresh_channel(gb, index, cycles_offset);
gb->apu_output.current_sample[index] = output;
}
@@ -131,7 +131,7 @@ static void update_sample(GB_gameboy_t *gb, GB_channel_t index, int8_t value, un
if (likely(!gb->apu_output.channel_muted[index])) {
output = (GB_sample_t){(0xF - value * 2) * left_volume, (0xF - value * 2) * right_volume};
}
- if (*(uint32_t *)&(gb->apu_output.current_sample[index]) != *(uint32_t *)&output) {
+ if (gb->apu_output.current_sample[index].packed != output.packed) {
refresh_channel(gb, index, cycles_offset);
gb->apu_output.current_sample[index] = output;
}
diff --git a/deps/gb/apu.h b/deps/gb/apu.h
index c8700c80..15b54a87 100644
--- a/deps/gb/apu.h
+++ b/deps/gb/apu.h
@@ -25,11 +25,22 @@
/* APU ticks are 2MHz, triggered by an internal APU clock. */
+#ifdef GB_INTERNAL
+typedef union
+{
+ struct {
+ int16_t left;
+ int16_t right;
+ };
+ uint32_t packed;
+} GB_sample_t;
+#else
typedef struct
{
int16_t left;
int16_t right;
} GB_sample_t;
+#endif
typedef struct
{