mirror of
https://github.com/Michaelangel007/apple2_russian_peasant_multiplication.git
synced 2024-09-07 10:54:23 +00:00
Procedural Javascript - optimize Shr1()
This commit is contained in:
parent
2dbc120e02
commit
4f2d4af511
19
rpm_proc.js
19
rpm_proc.js
@ -156,17 +156,20 @@ function Shr1( array )
|
|||||||
var i;
|
var i;
|
||||||
var n = array.length;
|
var n = array.length;
|
||||||
var carry = 0;
|
var carry = 0;
|
||||||
var q = 0;
|
var sum = 0;
|
||||||
var div = 0;
|
|
||||||
var rem = 0;
|
|
||||||
|
|
||||||
for( i = n-1; i >= 0; --i )
|
for( i = n-1; i >= 0; --i )
|
||||||
{
|
{
|
||||||
div = array[ i ] + carry; // dividend
|
// Optimized
|
||||||
q = (div / 2) | 0; // 2 is divisor
|
sum = array[i] + carry;
|
||||||
array[i] = q;
|
array[i] = (sum / 2) | 0;
|
||||||
rem = div - q*2; // 2 is divisor
|
carry = (sum & 1) ? BASE : 0;
|
||||||
carry = rem * BASE;
|
// Original
|
||||||
|
// div = array[ i ] + carry; // dividend
|
||||||
|
// q = (div / 2) | 0; // 2 is divisor
|
||||||
|
// array[i] = q;
|
||||||
|
// rem = div - q*2; // 2 is divisor
|
||||||
|
// carry = rem * BASE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user