From 1652c02a08337fec5281ddbbbce6b1bf1ae5fd8b Mon Sep 17 00:00:00 2001 From: Marisa Heit Date: Mon, 17 Oct 2016 22:37:49 -0500 Subject: [PATCH] Add unsigned division opcodes to the VM --- src/scripting/vm/vmexec.h | 50 +++++++++++++++++++++++++++++++++++++++ src/scripting/vm/vmops.h | 10 ++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index 8f8a212955..9dbea7c51b 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -813,6 +813,31 @@ begin: reg.d[a] = konstd[B] / reg.d[C]; NEXTOP; + OP(DIVU_RR): + ASSERTD(a); ASSERTD(B); ASSERTD(C); + if (reg.d[C] == 0) + { + THROW(X_DIVISION_BY_ZERO); + } + reg.d[a] = int((unsigned)reg.d[B] / (unsigned)reg.d[C]); + NEXTOP; + OP(DIVU_RK): + ASSERTD(a); ASSERTD(B); ASSERTKD(C); + if (konstd[C] == 0) + { + THROW(X_DIVISION_BY_ZERO); + } + reg.d[a] = int((unsigned)reg.d[B] / (unsigned)konstd[C]); + NEXTOP; + OP(DIVU_KR): + ASSERTD(a); ASSERTKD(B); ASSERTD(C); + if (reg.d[C] == 0) + { + THROW(X_DIVISION_BY_ZERO); + } + reg.d[a] = int((unsigned)konstd[B] / (unsigned)reg.d[C]); + NEXTOP; + OP(MOD_RR): ASSERTD(a); ASSERTD(B); ASSERTD(C); if (reg.d[C] == 0) @@ -838,6 +863,31 @@ begin: reg.d[a] = konstd[B] % reg.d[C]; NEXTOP; + OP(MODU_RR): + ASSERTD(a); ASSERTD(B); ASSERTD(C); + if (reg.d[C] == 0) + { + THROW(X_DIVISION_BY_ZERO); + } + reg.d[a] = int((unsigned)reg.d[B] % (unsigned)reg.d[C]); + NEXTOP; + OP(MODU_RK): + ASSERTD(a); ASSERTD(B); ASSERTKD(C); + if (konstd[C] == 0) + { + THROW(X_DIVISION_BY_ZERO); + } + reg.d[a] = int((unsigned)reg.d[B] % (unsigned)konstd[C]); + NEXTOP; + OP(MODU_KR): + ASSERTD(a); ASSERTKD(B); ASSERTD(C); + if (reg.d[C] == 0) + { + THROW(X_DIVISION_BY_ZERO); + } + reg.d[a] = int((unsigned)konstd[B] % (unsigned)reg.d[C]); + NEXTOP; + OP(AND_RR): ASSERTD(a); ASSERTD(B); ASSERTD(C); reg.d[a] = reg.d[B] & reg.d[C]; diff --git a/src/scripting/vm/vmops.h b/src/scripting/vm/vmops.h index 39d224f5c9..1b34dcc0fc 100644 --- a/src/scripting/vm/vmops.h +++ b/src/scripting/vm/vmops.h @@ -115,12 +115,18 @@ xx(SUB_RK, sub, RIRIKI), xx(SUB_KR, sub, RIKIRI), xx(MUL_RR, mul, RIRIRI), // dA = dB * dkC xx(MUL_RK, mul, RIRIKI), -xx(DIV_RR, div, RIRIRI), // dA = dkB / dkC +xx(DIV_RR, div, RIRIRI), // dA = dkB / dkC (signed) xx(DIV_RK, div, RIRIKI), xx(DIV_KR, div, RIKIRI), -xx(MOD_RR, mod, RIRIRI), // dA = dkB % dkC +xx(DIVU_RR, divu, RIRIRI), // dA = dkB / dkC (unsigned) +xx(DIVU_RK, divu, RIRIKI), +xx(DIVU_KR, divu, RIKIRI), +xx(MOD_RR, mod, RIRIRI), // dA = dkB % dkC (signed) xx(MOD_RK, mod, RIRIKI), xx(MOD_KR, mod, RIKIRI), +xx(MODU_RR, modu, RIRIRI), // dA = dkB % dkC (unsigned) +xx(MODU_RK, modu, RIRIKI), +xx(MODU_KR, modu, RIKIRI), xx(AND_RR, and, RIRIRI), // dA = dB & dkC xx(AND_RK, and, RIRIKI), xx(OR_RR, or, RIRIRI), // dA = dB | dkC