all repos — mgba @ ae12dd907c4553de0d72f7da66135a39b70767ba

mGBA Game Boy Advance Emulator

Reduce the code size of division by zero a bit
Jeffrey Pfau jeffrey@endrift.com
Sat, 05 Jul 2014 13:55:36 -0700
commit

ae12dd907c4553de0d72f7da66135a39b70767ba

parent

2fd9ab1197de96450c633ee56360b0606c4d478b

1 files changed, 5 insertions(+), 22 deletions(-)

jump to
M src/gba/gba-bios.csrc/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; } }