libretro-cap32 icon indicating copy to clipboard operation
libretro-cap32 copied to clipboard

[WIP] Misaligned access fix

Open madcock opened this issue 1 year ago • 5 comments

Fix misaligned access that caused problems on SF2000 platform.

madcock avatar Jan 20 '24 16:01 madcock

Context from the data_frog_sf2000 discord at https://discord.com/channels/741895796315914271/1099465777825972347/1176215621025939457

image

madcock avatar Jan 20 '24 16:01 madcock

Is something related with big/little endianess, isn't it? What is the endianess of your CPU? maybe we could use a gcc flag to detect when you compile with your MIPS devkit.

Check the endianness file and use your exclusive compiler flag: https://github.com/libretro/libretro-cap32/blob/master/cap32/retro_endianness.h

Thanks @madcock for your PR :)

DSkywalk avatar Jan 26 '24 16:01 DSkywalk

It's not endianess. RendPos is uint32_t * but it points to a byte-aligned address, not a word-aligned one https://github.com/libretro/libretro-cap32/blob/e727310c86ef1dc1d1c3ffa2e7fa73b3c8dd0d0d/cap32/crtc.c#L1243 This upsets some platforms; x86 and ARM are immune, while MIPS is not, and needs a (costly) exception processing each time a write is issued. The fix is far from perfect (lowest CRTC horizontal position bits would become trimmed) so I vote not merging. And since it's actually relevant, the rendering should be done in byte or halfword quantities, esp. seeing something like this https://github.com/libretro/libretro-cap32/blob/e727310c86ef1dc1d1c3ffa2e7fa73b3c8dd0d0d/cap32/crtc.c#L1013

bnister avatar Jan 26 '24 21:01 bnister

Also, since it's not obvious here, bnister == osaka in thread above. I asked for an explanation since I knew it would be better than any I could give. ;)

(So sounds like it makes sense to reject this PR, and instead investigate the source of the alignment issues, which is the way rendering is currently done.)

Thanks everyone!

madcock avatar Jan 26 '24 21:01 madcock

Ook, and thank you very much for the great explanation @bnister!

@madcock when you have the patch, just update this PR and I will be happy to merge it.

Thank you both! :+1:

DSkywalk avatar Jan 27 '24 08:01 DSkywalk

Hi @DSkywalk , should we merge this or not?

LibretroAdmin avatar Jun 28 '24 22:06 LibretroAdmin

No, as the developer wrote it is a very early fix that needed tweaks and also affects the correct emulation of the screen (crtc), as there has been no news step to close it and if the author wants to recover it in the future there is no problem to revisit it. Thanks!! :+1:

DSkywalk avatar Jul 03 '24 10:07 DSkywalk