Browse Source

jit bugfix in mod/div, sometimes eax was overwritten leading to incorrect result

ncannasse 7 years ago
parent
commit
97539b3c2f
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/jit.c

+ 4 - 1
src/jit.c

@@ -1665,14 +1665,17 @@ static preg *op_binop( jit_ctx *ctx, vreg *dst, vreg *a, vreg *b, hl_opcode *op
 		case OUMod:
 		case OUMod:
 			{
 			{
 				preg *out = op->op == OSMod || op->op == OUMod ? REG_AT(Edx) : PEAX;
 				preg *out = op->op == OSMod || op->op == OUMod ? REG_AT(Edx) : PEAX;
-				preg *r = alloc_cpu(ctx,b,true);
+				preg *r;
 				int jz, jend;
 				int jz, jend;
+				if( pa->kind == RCPU && pa->id == Eax ) RLOCK(pa);
+				r = alloc_cpu(ctx,b,true);
 				// integer div 0 => 0
 				// integer div 0 => 0
 				op32(ctx,TEST,r,r);
 				op32(ctx,TEST,r,r);
 				XJump_small(JNotZero,jz);
 				XJump_small(JNotZero,jz);
 				op32(ctx,XOR,out,out);
 				op32(ctx,XOR,out,out);
 				XJump_small(JAlways,jend);
 				XJump_small(JAlways,jend);
 				patch_jump(ctx,jz);
 				patch_jump(ctx,jz);
+				pa = fetch(a);
 				if( pa->kind != RCPU || pa->id != Eax ) {
 				if( pa->kind != RCPU || pa->id != Eax ) {
 					scratch(PEAX);
 					scratch(PEAX);
 					scratch(pa);
 					scratch(pa);