From 703aaa373e0127657cd88960c48bb330a99324fc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 2 Nov 2016 10:52:14 +0100 Subject: [PATCH] SHA-1: 8852bc7278d033bbed66c51bf23aee841ee977a9 * Revert "Modify CMPJMP to produce more compact code (as far as VC++ is concerned, anyway)" This reverts commit 6ff973a06bd97dfd1c2c5191b508fdbd98f62063. 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. --- src/scripting/vm/vmexec.cpp | 14 ++++------- src/scripting/vm/vmexec.h | 46 ++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/scripting/vm/vmexec.cpp b/src/scripting/vm/vmexec.cpp index af25030a9c..57ce48a95a 100644 --- a/src/scripting/vm/vmexec.cpp +++ b/src/scripting/vm/vmexec.cpp @@ -82,17 +82,11 @@ #define THROW(x) throw(EVMAbortException(x)) #define CMPJMP(test) \ - pc++; \ - if (VM_UBYTE(test) == VM_UBYTE(a)) { \ + if ((test) == (a & CMP_CHECK)) { \ assert(pc[1].op == OP_JMP); \ - 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); \ + pc += 1 + JMPOFS(pc+1); \ + } else { \ + pc += 1; \ } #define GETADDR(a,o,x) \ diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index 500c30c667..69f406dd81 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -1199,88 +1199,88 @@ begin: ASSERTF(B); ASSERTF(C); 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 { - CMPJMP_MASK(reg.f[C] == reg.f[B]); + CMPJMP(reg.f[C] == reg.f[B]); } NEXTOP; OP(EQF_K): ASSERTF(B); ASSERTKF(C); if (a & CMP_APPROX) { - CMPJMP_MASK(fabs(konstf[C] - reg.f[B]) < VM_EPSILON); + CMPJMP(fabs(konstf[C] - reg.f[B]) < VM_EPSILON); } else { - CMPJMP_MASK(konstf[C] == reg.f[B]); + CMPJMP(konstf[C] == reg.f[B]); } NEXTOP; OP(LTF_RR): ASSERTF(B); ASSERTF(C); if (a & CMP_APPROX) { - CMPJMP_MASK((reg.f[B] - reg.f[C]) < -VM_EPSILON); + CMPJMP((reg.f[B] - reg.f[C]) < -VM_EPSILON); } else { - CMPJMP_MASK(reg.f[B] < reg.f[C]); + CMPJMP(reg.f[B] < reg.f[C]); } NEXTOP; OP(LTF_RK): ASSERTF(B); ASSERTKF(C); if (a & CMP_APPROX) { - CMPJMP_MASK((reg.f[B] - konstf[C]) < -VM_EPSILON); + CMPJMP((reg.f[B] - konstf[C]) < -VM_EPSILON); } else { - CMPJMP_MASK(reg.f[B] < konstf[C]); + CMPJMP(reg.f[B] < konstf[C]); } NEXTOP; OP(LTF_KR): ASSERTKF(B); ASSERTF(C); if (a & CMP_APPROX) { - CMPJMP_MASK((konstf[B] - reg.f[C]) < -VM_EPSILON); + CMPJMP((konstf[B] - reg.f[C]) < -VM_EPSILON); } else { - CMPJMP_MASK(konstf[B] < reg.f[C]); + CMPJMP(konstf[B] < reg.f[C]); } NEXTOP; OP(LEF_RR): ASSERTF(B); ASSERTF(C); if (a & CMP_APPROX) { - CMPJMP_MASK((reg.f[B] - reg.f[C]) <= -VM_EPSILON); + CMPJMP((reg.f[B] - reg.f[C]) <= -VM_EPSILON); } else { - CMPJMP_MASK(reg.f[B] <= reg.f[C]); + CMPJMP(reg.f[B] <= reg.f[C]); } NEXTOP; OP(LEF_RK): ASSERTF(B); ASSERTKF(C); if (a & CMP_APPROX) { - CMPJMP_MASK((reg.f[B] - konstf[C]) <= -VM_EPSILON); + CMPJMP((reg.f[B] - konstf[C]) <= -VM_EPSILON); } else { - CMPJMP_MASK(reg.f[B] <= konstf[C]); + CMPJMP(reg.f[B] <= konstf[C]); } NEXTOP; OP(LEF_KR): ASSERTKF(B); ASSERTF(C); if (a & CMP_APPROX) { - CMPJMP_MASK((konstf[B] - reg.f[C]) <= -VM_EPSILON); + CMPJMP((konstf[B] - reg.f[C]) <= -VM_EPSILON); } else { - CMPJMP_MASK(konstf[B] <= reg.f[C]); + CMPJMP(konstf[B] <= reg.f[C]); } NEXTOP; @@ -1369,12 +1369,12 @@ begin: Do_EQV2: if (a & CMP_APPROX) { - CMPJMP_MASK(fabs(reg.f[B ] - fcp[0]) < VM_EPSILON && - fabs(reg.f[B+1] - fcp[1]) < VM_EPSILON); + CMPJMP(fabs(reg.f[B ] - fcp[0]) < VM_EPSILON && + fabs(reg.f[B+1] - fcp[1]) < VM_EPSILON); } 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; OP(EQV2_K): @@ -1496,13 +1496,13 @@ begin: Do_EQV3: if (a & CMP_APPROX) { - 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); + 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); } 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; OP(EQV3_K):