First post, by superfury
Thinking about it, it sounds fine. But when it reaches -1 and shifts that(counter is still left to shift), it gets stuck at -1 instead of becoming 0? -1 SAR 1 = -1 instead of SAR -1,1=0? It's shifted, clearing the MSb(becoming +127 when used on a 8-bit value). Then the MSb is set because the value before shifting had it set, thus becoming -1 again?
So, an example on gcc 4.4 on stackoverflow:
00000000 <arithmetic0>:0: 55 push %ebp1: 89 e5 mov %esp,%ebp3: 8b 45 08 mov 0x8(%ebp),%eax6: 5d pop %ebp7: 89 c2 mov %eax,%edx9: c1 ea 1f shr $0x1f,%edxc: 8d 04 02 lea (%edx,%eax,1),%eaxf: d1 f8 sar %eax11: c3
Thus, executing it yields:
00000000 <arithmetic0>:0: 55 push %ebp1: 89 e5 mov %esp,%ebp3: 8b 45 08 mov 0x8(%ebp),%eax ;eax=ffffffff6: 5d pop %ebp7: 89 c2 mov %eax,%edx ;eax=edx=ffffffff9: c1 ea 1f shr $0x1f,%edx ;edx=7fffffff, cf setc: 8d 04 02 lea (%edx,%eax,1),%eax ;eax=7ffffffef: d1 f8 sar %eax ;eax=3fffffff? should be 0?11: c3
Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io