Skip to content

Commit

Permalink
little endian version of mul53 + fixes + coverage for mul53
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Sep 2, 2014
1 parent 3dfde67 commit f3f8d4f
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 21 deletions.
63 changes: 54 additions & 9 deletions js/dist/alu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* COMPUTE THE ABSOLUTE VALUE OF NUMBER n
*/

exports.abs = function abs() {};
// exports.abs = function abs() {};


/* js/src/add */
Expand Down Expand Up @@ -672,7 +672,7 @@ var bmul53_t = function(r){

/**
* Multiply two blocks, result is put in a 1 or 2 blocks big endian array.
* i <= 1, j <= 1, k <= 2
* aj - ai <= 1, bj - bi <= 1, cj - ci <= 2
*
*
* @param {array} a first operand
Expand All @@ -688,19 +688,15 @@ var bmul53_t = function(r){

var mul = function(a, ai, aj, b, bi, bj, c, ci, cj){

var v, i, j, k;

i = aj - ai;
j = bj - bi;
k = cj - ci;
var v;

// EMPTY CASE
if (i <= 0 || j <= 0 || k <= 0) return;
if (aj <= ai || bj <= bi || cj <= ci) return;

v = a[ai] * b[bi];
c[cj-1] = v % r;

if (k > 1) {
if (cj > ci + 1) {
c[cj-2] = (v - c[cj-1]) / r;
}

Expand All @@ -712,6 +708,55 @@ var bmul53_t = function(r){


exports.bmul53_t = bmul53_t;


/**
* /!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e. 53 bits)
*
* little endian 1 block multiplication
*
*/

var lmul53_t = function(r){

/**
* Multiply two blocks, result is put in a 1 or 2 blocks little endian array.
* aj - ai <= 1, bj - bi <= 1, cj - ci <= 2
*
*
* @param {array} a first operand
* @param {int} ai a left
* @param {int} aj a right
* @param {array} b second operand
* @param {int} bi b left
* @param {int} bj b right
* @param {array} c result, must be 0 initialized
* @param {int} ci c left
* @param {int} cj c right
*/

var mul = function(a, ai, aj, b, bi, bj, c, ci, cj){

var v;

// EMPTY CASE
if (aj <= ai || bj <= bi || cj <= ci) return;

v = a[ai] * b[bi];
c[ci] = v % r;

if (cj > ci + 1) {
c[ci+1] = (v - c[ci]) / r;
}

};

return mul;

};


exports.lmul53_t = lmul53_t;
/* js/src/neg */
/* js/src/neg/neg.js */
/**
Expand Down
Loading

0 comments on commit f3f8d4f

Please sign in to comment.