Modify CMPJMP to produce more compact code (as far as VC++ is concerned, anyway)

This commit is contained in:
Marisa Heit 2016-10-30 22:15:40 -05:00
parent 2857fac338
commit 6ff973a06b
2 changed files with 33 additions and 27 deletions

View file

@ -82,11 +82,17 @@
#define THROW(x) throw(EVMAbortException(x))
#define CMPJMP(test) \
if ((test) == (a & CMP_CHECK)) { \
pc++; \
if (VM_UBYTE(test) == VM_UBYTE(a)) { \
assert(pc[1].op == OP_JMP); \
pc += 1 + JMPOFS(pc+1); \
} else { \
pc += 1; \
pc += JMPOFS(pc); \
}
#define CMPJMP_MASK(test) \
pc++; \
if (VM_UBYTE(test) == (VM_UBYTE(a) & CMP_CHECK)) { \
assert(pc[1].op == OP_JMP); \
pc += JMPOFS(pc); \
}
#define GETADDR(a,o,x) \

View file

@ -1199,88 +1199,88 @@ begin:
ASSERTF(B); ASSERTF(C);
if (a & CMP_APPROX)
{
CMPJMP(fabs(reg.f[C] - reg.f[B]) < VM_EPSILON);
CMPJMP_MASK(fabs(reg.f[C] - reg.f[B]) < VM_EPSILON);
}
else
{
CMPJMP(reg.f[C] == reg.f[B]);
CMPJMP_MASK(reg.f[C] == reg.f[B]);
}
NEXTOP;
OP(EQF_K):
ASSERTF(B); ASSERTKF(C);
if (a & CMP_APPROX)
{
CMPJMP(fabs(konstf[C] - reg.f[B]) < VM_EPSILON);
CMPJMP_MASK(fabs(konstf[C] - reg.f[B]) < VM_EPSILON);
}
else
{
CMPJMP(konstf[C] == reg.f[B]);
CMPJMP_MASK(konstf[C] == reg.f[B]);
}
NEXTOP;
OP(LTF_RR):
ASSERTF(B); ASSERTF(C);
if (a & CMP_APPROX)
{
CMPJMP((reg.f[B] - reg.f[C]) < -VM_EPSILON);
CMPJMP_MASK((reg.f[B] - reg.f[C]) < -VM_EPSILON);
}
else
{
CMPJMP(reg.f[B] < reg.f[C]);
CMPJMP_MASK(reg.f[B] < reg.f[C]);
}
NEXTOP;
OP(LTF_RK):
ASSERTF(B); ASSERTKF(C);
if (a & CMP_APPROX)
{
CMPJMP((reg.f[B] - konstf[C]) < -VM_EPSILON);
CMPJMP_MASK((reg.f[B] - konstf[C]) < -VM_EPSILON);
}
else
{
CMPJMP(reg.f[B] < konstf[C]);
CMPJMP_MASK(reg.f[B] < konstf[C]);
}
NEXTOP;
OP(LTF_KR):
ASSERTKF(B); ASSERTF(C);
if (a & CMP_APPROX)
{
CMPJMP((konstf[B] - reg.f[C]) < -VM_EPSILON);
CMPJMP_MASK((konstf[B] - reg.f[C]) < -VM_EPSILON);
}
else
{
CMPJMP(konstf[B] < reg.f[C]);
CMPJMP_MASK(konstf[B] < reg.f[C]);
}
NEXTOP;
OP(LEF_RR):
ASSERTF(B); ASSERTF(C);
if (a & CMP_APPROX)
{
CMPJMP((reg.f[B] - reg.f[C]) <= -VM_EPSILON);
CMPJMP_MASK((reg.f[B] - reg.f[C]) <= -VM_EPSILON);
}
else
{
CMPJMP(reg.f[B] <= reg.f[C]);
CMPJMP_MASK(reg.f[B] <= reg.f[C]);
}
NEXTOP;
OP(LEF_RK):
ASSERTF(B); ASSERTKF(C);
if (a & CMP_APPROX)
{
CMPJMP((reg.f[B] - konstf[C]) <= -VM_EPSILON);
CMPJMP_MASK((reg.f[B] - konstf[C]) <= -VM_EPSILON);
}
else
{
CMPJMP(reg.f[B] <= konstf[C]);
CMPJMP_MASK(reg.f[B] <= konstf[C]);
}
NEXTOP;
OP(LEF_KR):
ASSERTKF(B); ASSERTF(C);
if (a & CMP_APPROX)
{
CMPJMP((konstf[B] - reg.f[C]) <= -VM_EPSILON);
CMPJMP_MASK((konstf[B] - reg.f[C]) <= -VM_EPSILON);
}
else
{
CMPJMP(konstf[B] <= reg.f[C]);
CMPJMP_MASK(konstf[B] <= reg.f[C]);
}
NEXTOP;
@ -1369,12 +1369,12 @@ begin:
Do_EQV2:
if (a & CMP_APPROX)
{
CMPJMP(fabs(reg.f[B ] - fcp[0]) < VM_EPSILON &&
fabs(reg.f[B+1] - fcp[1]) < VM_EPSILON);
CMPJMP_MASK(fabs(reg.f[B ] - fcp[0]) < VM_EPSILON &&
fabs(reg.f[B+1] - fcp[1]) < VM_EPSILON);
}
else
{
CMPJMP(reg.f[B] == fcp[0] && reg.f[B+1] == fcp[1]);
CMPJMP_MASK(reg.f[B] == fcp[0] && reg.f[B+1] == fcp[1]);
}
NEXTOP;
OP(EQV2_K):
@ -1496,13 +1496,13 @@ begin:
Do_EQV3:
if (a & CMP_APPROX)
{
CMPJMP(fabs(reg.f[B ] - fcp[0]) < VM_EPSILON &&
fabs(reg.f[B+1] - fcp[1]) < VM_EPSILON &&
fabs(reg.f[B+2] - fcp[2]) < VM_EPSILON);
CMPJMP_MASK(fabs(reg.f[B ] - fcp[0]) < VM_EPSILON &&
fabs(reg.f[B+1] - fcp[1]) < VM_EPSILON &&
fabs(reg.f[B+2] - fcp[2]) < VM_EPSILON);
}
else
{
CMPJMP(reg.f[B] == fcp[0] && reg.f[B+1] == fcp[1] && reg.f[B+2] == fcp[2]);
CMPJMP_MASK(reg.f[B] == fcp[0] && reg.f[B+1] == fcp[1] && reg.f[B+2] == fcp[2]);
}
NEXTOP;
OP(EQV3_K):