XenonRecomp icon indicating copy to clipboard operation
XenonRecomp copied to clipboard

Add simde

Open IsaacMarovitz opened this issue 9 months ago • 16 comments

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.

IsaacMarovitz avatar Mar 03 '25 10:03 IsaacMarovitz

ah shoot i should have looked here before doing it myself

i'll give building a shot for you though

grantmulholland avatar Mar 03 '25 19:03 grantmulholland

submodules giving me trouble

grantmulholland avatar Mar 03 '25 20:03 grantmulholland

i literally cant check this out

grantmulholland avatar Mar 03 '25 21:03 grantmulholland

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.

squidbus avatar Mar 03 '25 21:03 squidbus

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.

IsaacMarovitz avatar Mar 03 '25 22:03 IsaacMarovitz

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 avatar Mar 03 '25 22:03 squidbus

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

squidbus avatar Mar 03 '25 22:03 squidbus

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

IsaacMarovitz avatar Mar 03 '25 22:03 IsaacMarovitz

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?

grantmulholland avatar Mar 03 '25 22:03 grantmulholland

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

IsaacMarovitz avatar Mar 03 '25 22:03 IsaacMarovitz

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

grantmulholland avatar Mar 03 '25 23:03 grantmulholland

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;
}

squidbus avatar Mar 04 '25 00:03 squidbus

image

Yep that does the job

SproedKartoffelChip avatar Mar 04 '25 01:03 SproedKartoffelChip

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.

squidbus avatar Mar 04 '25 01:03 squidbus

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

SproedKartoffelChip avatar Mar 04 '25 01:03 SproedKartoffelChip

Submitted https://github.com/IsaacMarovitz/XenonRecomp/pull/1 to this branch to handle __rdtsc and denormal flushing.

squidbus avatar Mar 04 '25 01:03 squidbus