Reduce the code size of division by zero a bit
Jeffrey Pfau jeffrey@endrift.com
Sat, 05 Jul 2014 13:55:36 -0700
1 files changed,
5 insertions(+),
22 deletions(-)
jump to
M
src/gba/gba-bios.c
→
src/gba/gba-bios.c
@@ -108,28 +108,11 @@ cpu->gprs[0] = result.quot;
cpu->gprs[1] = result.rem; cpu->gprs[3] = abs(result.quot); } else { - switch (num) { - case 0: - cpu->gprs[0] = 1; - cpu->gprs[1] = 0; - cpu->gprs[3] = 1; - break; - case 1: - cpu->gprs[0] = 1; - cpu->gprs[1] = 1; - cpu->gprs[3] = 1; - break; - case -1: - cpu->gprs[0] = -1; - cpu->gprs[1] = -1; - cpu->gprs[3] = 1; - break; - default: - // Technically this should hang, but that would be painful to emulate in HLE - cpu->gprs[0] = 0; - cpu->gprs[1] = 0; - cpu->gprs[3] = 0; - } + // If abs(num) > 1, this should hang, but that would be painful to + // emulate in HLE, and no game will get into a state where it hangs... + cpu->gprs[0] = (num < 0) ? -1 : 1; + cpu->gprs[1] = num; + cpu->gprs[3] = 1; } }