Kagamiin / ESFMu

Emulation core for the "ESFM" enhanced OPL3 clone, based on Nuke.YKT's Nuked OPL3 and reverse-engineering efforts from the community
GNU Lesser General Public License v2.1
23 stars 1 forks source link

build failure on clang-14, 15, 16 #16

Closed jg1uaa closed 7 months ago

jg1uaa commented 7 months ago

DOSBox-X 2024.03.01 uses ESFMu v1.2.3 and I received a report about build failure on OpenBSD-current/i386.

I tested building ESFMu with clang-13 to 16, only clang-13 can build ESFMu (Slackware-15.0/i686 have clang-13).

Here is 32bit code build test result on Debian-12/amd64.

uaa@emeraude:~/ESFMu$ clang-13 -m32 esfm.c -c -o /dev/null
uaa@emeraude:~/ESFMu$ clang-14 -m32 esfm.c -c -o /dev/null
esfm.c:1849:5: error: inline assembly requires more registers than available
                                "movzbl  %b[wave], %%eax             \n\t"
                                ^
esfm.c:1849:5: error: inline assembly requires more registers than available
2 errors generated.
uaa@emeraude:~/ESFMu$ clang-15 -m32 esfm.c -c -o /dev/null
esfm.c:1849:5: error: inline assembly requires more registers than available
                                "movzbl  %b[wave], %%eax             \n\t"
                                ^
esfm.c:1849:5: error: inline assembly requires more registers than available
2 errors generated.
uaa@emeraude:~/ESFMu$ clang-16 -m32 esfm.c -c -o /dev/null
esfm.c:1849:5: error: inline assembly requires more registers than available
                                "movzbl  %b[wave], %%eax             \n\t"
                                ^
esfm.c:1849:5: error: inline assembly requires more registers than available
2 errors generated.
uaa@emeraude:~/ESFMu$

I have no idea to fix this, so simply report this as issue.

Kagamiin commented 7 months ago

Reproduced in Clang 17.0.6. Weird. It works just fine in current versions of GCC.

@akumanatt can you help investigate? Do you think it might be a Clang bug?

In the meantime, I'll add a flag to force-disable the inline ASM optimizations so that you can at least compile the code on current Clang.

Kagamiin commented 7 months ago

@jg1uaa Flag added in version v1.2.4: https://github.com/Kagamiin/ESFMu/releases/tag/v1.2.4

To use, compile with -D_ESFMU_DISABLE_ASM_OPTIMIZATIONS.

Nonetheless, we'll investigate and try to get the issue fixed, as the ASM optimizations reduce the CPU usage of ESFMu by almost 25%, which can help a lot in an emulator like DOSBox-X, especially when running in native mode where it uses the most amount of CPU.

akumanatt commented 7 months ago

Apparently Clang 15 changed how pointers are resolved into offsets and made both logsinrom and exprom require a unique register even though I gave constraints to them as a memory operand that usually resolves to a stack offset. I fixed this by manually storing them as memory address integers before being used by the asm part.

Not sure how it failed in Clang 14 though.

Kagamiin commented 7 months ago

Fixed in https://github.com/Kagamiin/ESFMu/releases/tag/v1.2.5.

jg1uaa commented 7 months ago

Thanks for quickly support! There is no problem with clang-14.

uaa@emeraude:~/ESFMu$ clang-13 -m32 -c esfm.c -o /dev/null
uaa@emeraude:~/ESFMu$ clang-14 -m32 -c esfm.c -o /dev/null
uaa@emeraude:~/ESFMu$ clang-15 -m32 -c esfm.c -o /dev/null
uaa@emeraude:~/ESFMu$ clang-16 -m32 -c esfm.c -o /dev/null
uaa@emeraude:~/ESFMu$