You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Licensed under the Apache License, Version 2.0 (the "License");
260
+
* you may not use this file except in compliance with the License.
261
+
* You may obtain a copy of the License at
262
+
*
263
+
* http://www.apache.org/licenses/LICENSE-2.0
264
+
*
265
+
* Unless required by applicable law or agreed to in writing, software
266
+
* distributed under the License is distributed on an "AS IS" BASIS,
267
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
268
+
* See the License for the specific language governing permissions and
269
+
* limitations under the License.
270
+
*/
271
+
272
+
'use strict';
273
+
274
+
// MODULES //
275
+
276
+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
277
+
278
+
279
+
// VARIABLES //
280
+
281
+
// Define a mask for the least significant 16 bits (low word): 65535 => 0x0000ffff => 00000000000000001111111111111111
282
+
var LOW_WORD_MASK = 0x0000ffff>>>0; // asm type annotation
283
+
284
+
285
+
// MAIN //
286
+
287
+
/**
288
+
* Performs multiplication of two unsigned 32-bit integers and returns an array of two unsigned 32-bit integers which represents the unsigned 64-bit integer product.
289
+
*
290
+
* @param {uinteger32} a - integer
291
+
* @param {uinteger32} b - integer
292
+
* @param {Collection} out - output array
293
+
* @param {integer} stride - output array stride
294
+
* @param {NonNegativeInteger} offset - output array index offset
295
+
* @returns {Collection} output array
296
+
*
297
+
* @example
298
+
* var out = [ 0, 0 ];
299
+
* var v = umuldw( 0xAAAAAAAA, 0x55555555, out, 1, 0 );
300
+
* // returns [ 954437176, 1908874354 ]
301
+
*/
302
+
function umuldw(a, b, out, stride, offset ) {
303
+
var w1;
304
+
var w2;
305
+
var w3;
306
+
var ha;
307
+
var hb;
308
+
var la;
309
+
var lb;
310
+
var t;
311
+
var k;
312
+
313
+
if ( isnan( a ) || isnan( b ) ) {
314
+
out[ offset ] = NaN;
315
+
out[ offset + stride ] = NaN;
316
+
return out;
317
+
}
318
+
a >>>= 0; // asm type annotation
319
+
b >>>= 0; // asm type annotation
320
+
321
+
ha = ( a >>> 16 ) >>> 0;
322
+
la = ( a & LOW_WORD_MASK ) >>> 0;
323
+
324
+
hb = ( b >>> 16 ) >>> 0;
325
+
lb = ( b & LOW_WORD_MASK ) >>> 0;
326
+
327
+
t = ( la*lb ) >>> 0;
328
+
w3 = ( t & LOW_WORD_MASK ) >>> 0;
329
+
k = ( t >>> 16 ) >>> 0;
330
+
331
+
t = ( ( ha*lb ) + k ) >>> 0;
332
+
w2 = ( t & LOW_WORD_MASK ) >>> 0;
333
+
w1 = ( t >>> 16 ) >>> 0;
334
+
335
+
t = ( ( la*hb ) + w2 ) >>> 0;
336
+
k = ( t >>> 16 ) >>> 0;
337
+
338
+
out[ offset ] = ( ( ha*hb ) + w1 + k ) >>> 0; // compute the higher 32 bits and cast to an unsigned 32-bit integer
339
+
out[ offset + stride ] = ( ( t << 16 ) + w3) >>> 0; // compute the lower 32 bits and cast to an unsigned 32-bit integer
340
+
341
+
return out;
342
+
}
343
+
344
+
345
+
// EXPORTS //
346
+
347
+
module.exports = umuldw;
348
+
</pre></td></tr></table></pre>
349
+
350
+
<divclass='push'></div><!-- for sticky footer -->
351
+
</div><!-- /wrapper -->
352
+
<divclass='footer quiet pad2 space-top1 center small'>
0 commit comments