8000 resource: Implement `decodeSZSNxAsm64_` by MonsterDruide1 · Pull Request #196 · open-ead/sead · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

resource: Implement decodeSZSNxAsm64_ #196

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

Merged
merged 2 commits into from
Jun 4, 2025

Conversation

MonsterDruide1
Copy link
Contributor
@MonsterDruide1 MonsterDruide1 commented May 20, 2025

Based on the name, this function just contains a bunch of assembly - so I didn't even bother trying to re-implement it in C++, but just copied the output of the disassembler here straight-away.

The labels are defined using just [number]: to avoid creating actual labels in the executable for them. This also means that references to them must be suffixed with either b for backwards-search or f for forwards-search, which is why some of those jump targets look weird.

Additionally, I tried properly defining inputs/outputs of the assembly block. The auto-allocation for src and dst works fine here, but error doesn't want to pick the actual target w2 - either it picks w0 and generates conflicts with dst in x0 (=> mismatch), or when marking it as clobbering variable (=&r), it decides to pick w8 instead, which is also not our target - so I manually assigned it to w2 to match the code here.

At label 6, two more instructions are auto-generated (mov w0, w2 ; ret), thanks to the setup of the assembly block.


This change is Reviewable

@MonsterDruide1 MonsterDruide1 self-assigned this May 20, 2025
@Pistonight
Copy link
Contributor
Pistonight commented May 20, 2025

Do we allow assembly in the project?

I am referring to this to be exact https://botw.link/about#how-can-i-help

Contributions that copy the assembly — or the pseudocode given by tools such as Hex-Rays or Ghidra — are rejected. We only accept contributions that are transformative in nature.

@leoetlino
Copy link
Contributor

That's for BotW, not sead. We don't have a clear policy on this for sead

Personally I think that it's a bit iffy but we're already doing the same thing for Wii U...

@leoetlino
Copy link
Contributor

Also I'm not sure if this should be inline assembly or a separate .s file. If we can't get regalloc to work the same I think that suggests it's not inline asm

@aboood40091
Copy link
Contributor

For Wii U, it's definitely inline assembly for several reasons, like the double blr at the end; one is an explicit instruction, and the other is generated by doing return error;.

@MonsterDruide1
Copy link
Contributor Author

I'm a bit suspicious of that "mov #1000", followed by "sub #1" - even IDA displayed that as "mov #FFF" straight-away, so I don't see how the compiler would miss this optimization opportunity if not explicitly listed in the assembly, but I'll do some testing later.

@MonsterDruide1
Copy link
Contributor Author

Next to the argument already listed above, here's another one:
2: tst w6, w5 is reachable without initializing w6, by taking the cbnz w5, 2f three lines above it. This mistake should never happen with a compiler.

@leoetlino
Copy link
Contributor

This mistake should never happen with a compiler.

While I agree that this definitely smells like handwritten assembly, that argument is not quite true! Compilers can make mistakes too and/or UB can cause compilers to generate dumb code.

https://github.com/open-ead/EventFlow/blob/556793186c3065e7b25a51247d0560d7ff401b81/src/evfl/Flowchart.cpp#L330-L338

8000

@fruityloops1
Copy link
Contributor

It's assembly

@aboood40091
Copy link
Contributor

I mean, yeah, it's literally in the function name. The debate is whether it's a separate text file or inline assembly (I'm certain of the latter).

@MonsterDruide1
Copy link
Contributor Author

I tried writing it as nice as possible, using templates for the usages of src and dst. Also, the last two instructions can be auto-generated when using inline assembly here - I'm not sure if that's possible when separating it off to a .s file.

@MonsterDruide1
Copy link
Contributor Author

Any more comments on this, or should this be merged?

@MonsterDruide1 MonsterDruide1 merged commit e00d2be into open-ead:master Jun 4, 2025
3 checks passed
@MonsterDruide1 MonsterDruide1 deleted the decodeSZSasm branch June 4, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0