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

Add simde #22

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add simde #22

wants to merge 6 commits into from

Conversation

IsaacMarovitz
Copy link
Contributor

@IsaacMarovitz IsaacMarovitz commented Mar 3, 2025

Add simde and include it in ppc_context.h, this means that recomp will need to link against simde.

According to @squidbus's testing, results in working x86_64 and ARM64 builds.

@grantmulholland

This comment was marked as outdated.

@grantmulholland

This comment was marked as outdated.

@grantmulholland

This comment was marked as outdated.

@squidbus
Copy link
Contributor

squidbus commented Mar 3, 2025

Tried this locally for ARM, few notes:

  • UnleashedRecompLib over in the other repo does not link against XenonUtils, so the includes are missing there for ppc_context.h.
  • In ppc_context.h:
    • Need to add #include <x86/avx.h>.
    • Need to add SIMDE prefix to rounding constants:
      static constexpr size_t GuestToHost[] = { SIMDE_MM_ROUND_NEAREST, SIMDE_MM_ROUND_TOWARD_ZERO, SIMDE_MM_ROUND_UP, SIMDE_MM_ROUND_DOWN };
    • Missing _MM_DENORMALS_ZERO_MASK, couldn't find an equivalent for this in simde code.
  • In generated source:
    • _MM_FROUND_NO_EXC needs to be SIMDE_MM_FROUND_NO_EXC, and same changes also for rounding constants mentioned previously.
    • Missing __rdtsc.

I have a feeling the constants shouldn't need that renaming but for some reason it's not compiling otherwise for me.

@IsaacMarovitz
Copy link
Contributor Author

Hmm i thought SIMDE_ENABLE_NATIVE_ALIASES would've taken care of those constants but no biggie. I might need your help for sorting out the linker issues.

@squidbus
Copy link
Contributor

squidbus commented Mar 3, 2025

Hmm i thought SIMDE_ENABLE_NATIVE_ALIASES would've taken care of those constants but no biggie. I might need your help for sorting out the linker issues.

In my current local code I'm able to compile an ARM64 build that works the same as my x86_64 build, with the above changes I mentioned.

@squidbus
Copy link
Contributor

squidbus commented Mar 3, 2025

For the UnleashedRecompLib thing specifically I am not sure if it's okay to just link it but that's what I did locally.

@IsaacMarovitz
Copy link
Contributor Author

Excellent. Btw I sent you a message on Discord on shadPS4 server.

@grantmulholland
Copy link

On SIMDE_ENABLE_NATIVE_ALIASES, from the readme in its repository:

Unfortunately, this is somewhat error-prone due to portability issues in the APIs, so it's recommended to only do this for testing.

It might be worth dropping that and sticking prefixes where appropriate, to avoid weird issues?

@IsaacMarovitz
Copy link
Contributor Author

IsaacMarovitz commented Mar 3, 2025

It might be worth dropping that and sticking prefixes where appropriate, to avoid weird issues?

It seems to be working for the intrinsics themselves, but yeah long term it shouldn't be a big deal to prefix the functions

@grantmulholland
Copy link

grantmulholland commented Mar 3, 2025

Good news: Plugging this into UnleashedRecomp with a little tweakage seems to be working.

Bad news: Something in shader compilation territory seems to have blown up. I'm getting messages telling me to make an issue under DirectXShaderCompiler, but I don't have a clue how to write a proper report for that, if it's an issue there to begin with.

image

@squidbus
Copy link
Contributor

squidbus commented Mar 4, 2025

For ARM this seems to work for a __rdtsc substitute:

inline uint64_t __rdtsc()
{
    uint64_t ret;
    asm volatile("mrs %0, cntvct_el0\n\t"
                 : "=r"(ret)::"memory");
    return ret;
}

@SproedKartoffelChip
Copy link

image

Yep that does the job

@squidbus
Copy link
Contributor

squidbus commented Mar 4, 2025

Note there is another issue that simde doesn't handle _MM_DENORMALS_ZERO_MASK, and that denormal behavior is needed for the game to work properly in some places. Possibly can be worked around with platform-specific code.

@SproedKartoffelChip
Copy link

Yeah some funky stuff happening with enemies falling out of bounds and audio cutting out might be a symptom of that

@squidbus
Copy link
Contributor

squidbus commented Mar 4, 2025

Submitted IsaacMarovitz#1 to this branch to handle __rdtsc and denormal flushing.

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.

4 participants