From ae12dd907c4553de0d72f7da66135a39b70767ba Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 5 Jul 2014 13:55:36 -0700 Subject: [PATCH] Reduce the code size of division by zero a bit --- src/gba/gba-bios.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/gba/gba-bios.c b/src/gba/gba-bios.c index afb3ed953..cf071bc58 100644 --- a/src/gba/gba-bios.c +++ b/src/gba/gba-bios.c @@ -108,28 +108,11 @@ static void _Div(struct ARMCore* cpu, int32_t num, int32_t denom) { 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; } }