Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Allow non-strict aliasing and overflow optimizations #1752

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

jcm93
Copy link
Contributor

@jcm93 jcm93 commented Jan 6, 2025

Non-strict aliasing is found to resolve #1737.

We also use signed integer overflow around ares, so we want to allow the compiler to optimize for that if it wants to; essentially everywhere ares runs is two's complement.

Couple quirks: Xcode has its own declaration for strict aliasing, so use that. Clang-CL doesn't transparently accept -fwrapv, so it's passed with /clang:-fwrapv.

_ares_gcc_common_options will eventually see more development to make warnings consistent across platforms where possible.

(Fixes #1737)

@DiscoStarslayer
Copy link

Can confirm this branch builds fine and fixes the graphical issues on n64 for me on windows + msys2 mingw64 gcc
image

@TesseracT33
Copy link

I have no say in this matter but my opinion is this: instead of using -fno-strict-aliasing, which will probably lead to reduced runtime performance and is more like a workaround rather than a proper fix, one should find where the strict aliasing is violated using a sanitizer and fix the problem from that end instead.

@jcm93
Copy link
Contributor Author

jcm93 commented Jan 6, 2025

I could keep strict aliasing under clang since there do not seem to be any environments yet where it causes issues. That might indeed be prudent.

In my first attempts at debugging this problem last month I did try to use ubsan to investigate, but it crashes nearly instantly on my arm64 Fedora system and I was unable to make it cooperate.

clang's sanitizers on macOS meanwhile did not detect any issues that seemed relevant. The only instances of UB it found were negative left shifts in some interpreters:

ares/n64/cpu/interpreter-ipu.cpp:65:44: runtime error: left shift of negative value -31
ares/n64/rsp/interpreter-ipu.cpp:51:50: runtime error: left shift of negative value -2
ares/n64/rsp/interpreter-vpu.cpp:1334:34: runtime error: left shift of negative value -1
ares/n64/rsp/interpreter-ipu.cpp:38:45: runtime error: left shift of negative value -883
ares/n64/cpu/interpreter-fpu.cpp:420:54: runtime error: left shift of negative value -7

etc.

These occurred relatively seldom; far from every frame, and didn't seem directly pertinent to the display output in a way that might cause this issue.

So I'd welcome the approach and do favor it, I just have limited ability to investigate myself.

For whatever it's worth, I went looking and Near's comments contemporary to its introduction can be found here.

@LukeUsher
Copy link
Member

One thing at a time; baby steps, we'll take it for now

@LukeUsher LukeUsher merged commit 445acba into ares-emulator:master Jan 6, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[New build system] Corrupt N64 graphical output when built with gcc with optimizations
4 participants