Get rid of global state

This commit is contained in:
copy 2016-10-01 23:22:10 +02:00
parent ed6e2edb32
commit 5e9e1ca90d
2 changed files with 9 additions and 10 deletions

View file

@ -275,8 +275,6 @@ CPU.prototype.imul_reg16 = function(operand1, operand2)
return result;
}
var mul32_result = new Int32Array(2);
CPU.prototype.do_mul32 = function(a, b)
{
var a00 = a & 0xFFFF;
@ -287,9 +285,9 @@ CPU.prototype.do_mul32 = function(a, b)
var mid = (low_result >>> 16) + (a16 * b00 | 0) | 0;
var high_result = mid >>> 16;
mid = (mid & 0xFFFF) + (a00 * b16 | 0) | 0;
mul32_result[0] = (mid << 16) | low_result & 0xFFFF;
mul32_result[1] = ((mid >>> 16) + (a16 * b16 | 0) | 0) + high_result | 0;
return mul32_result;
this.mul32_result[0] = (mid << 16) | low_result & 0xFFFF;
this.mul32_result[1] = ((mid >>> 16) + (a16 * b16 | 0) | 0) + high_result | 0;
return this.mul32_result;
};
CPU.prototype.do_imul32 = function(a, b)
@ -493,8 +491,6 @@ CPU.prototype.idiv16 = function(source_operand)
}
}
var div32_result = new Float64Array(2);
// If the dividend is too large, the division cannot be done precisely using
// JavaScript's double floating point numbers. Run simple long divsion until
// the dividend is small enough
@ -541,9 +537,9 @@ CPU.prototype.do_div32 = function(div_low, div_high, quot)
var mod = div % quot;
result += div / quot | 0;
div32_result[0] = result;
div32_result[1] = mod;
return div32_result;
this.div32_result[0] = result;
this.div32_result[1] = mod;
return this.div32_result;
}

View file

@ -175,6 +175,9 @@ function CPU()
/** @type {number} */
this.last_result = 0;
this.mul32_result = new Int32Array(2);
this.div32_result = new Float64Array(2);
this.tsc_offset = 0;
/** @type {number} */