Add unsigned division opcodes to the VM

This commit is contained in:
Marisa Heit 2016-10-17 22:37:49 -05:00
parent 646f9b21c7
commit 1652c02a08
2 changed files with 58 additions and 2 deletions

View file

@ -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];

View file

@ -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