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 %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 08 mov 0x8(%ebp),%eax
6: 5d pop %ebp
7: 89 c2 mov %eax,%edx
9: c1 ea 1f shr $0x1f,%edx
c: 8d 04 02 lea (%edx,%eax,1),%eax
f: d1 f8 sar %eax
11: c3
Thus, executing it yields:
00000000 <arithmetic0>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 08 mov 0x8(%ebp),%eax ;eax=ffffffff
6: 5d pop %ebp
7: 89 c2 mov %eax,%edx ;eax=edx=ffffffff
9: c1 ea 1f shr $0x1f,%edx ;edx=7fffffff, cf set
c: 8d 04 02 lea (%edx,%eax,1),%eax ;eax=7ffffffe
f: 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