SHA-1: 8852bc7278d033bbed66c51bf23aee841ee977a9

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

This reverts commit 6ff973a06b.

This modification did not work and broke the comparisons. Actually this had three problems:

* the asserts checked the wrong instruction
* the mask was not applied to regular comparisons.
* incrementing PC before testing does not work because 'test' references the PC.
This commit is contained in:
Christoph Oelckers 2016-11-02 10:52:14 +01:00
parent 5e76d3af18
commit 703aaa373e
2 changed files with 27 additions and 33 deletions

View file

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

View file

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