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

implement "recomp" wrappers for string.h functions #55

Open
blackgamma7 opened this issue Jul 7, 2024 · 4 comments
Open

implement "recomp" wrappers for string.h functions #55

blackgamma7 opened this issue Jul 7, 2024 · 4 comments

Comments

@blackgamma7
Copy link

Would it be possible/reasonable to wrap any functions labeled as those found in the string.h library by loading the registers directly into the native counterpart? example:

void strlen_recomp(uint8_t* rdram, recomp_context* ctx) {
    ctx->r2=(uint32_t)std::strlen((char*)MEM_W(0x0, ctx->r4));
}
@AngheloAlf
Copy link
Collaborator

What are you aiming to do exactly?
There shouldn't be a need to provide functions for string functions. If the game already uses one of those functions then said function should be already present on the ROM and should get recompiled by the recompiler like all the rest of the functions.

@blackgamma7
Copy link
Author

blackgamma7 commented Jul 8, 2024

I ask because I can understand if it is a matter of can vs should. Using the platform-native counterpart of these functions may be more efficient if the expected output is the same. However, I can understand if this goes against the purpose of using the static recompilation of the original code.

@AngheloAlf
Copy link
Collaborator

It is possible to do so, but it can be tricky to implement correctly, mainly because of the endianness differences.
The N64 is a big endian machine, while most modern PCs are little endian, so you need to account for that when reading or writing data from recompiled functions. Sometimes it can be as simple as moving around some struct members but other times you may need some intermediary buffers just to re-endian the data around which may kill any performance improvement of using some native functions.

So, is it possible? Yeah.
Should we do it? Not really unless we thought there was a good enough reason to do so. We shouldn't try to optimize prematurely.

@blackgamma7
Copy link
Author

blackgamma7 commented Jul 8, 2024

Okay, I appreciate the response. I was wondering about the viability.

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

No branches or pull requests

2 participants