From 0e7ab6a61450fddb6744d48d1aaf329a11aa14a7 Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Wed, 20 Apr 2011 22:34:33 -0700 Subject: [PATCH] add back sjcl.bitArray.extract - needed for bn --- core/bitArray.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/bitArray.js b/core/bitArray.js index 40e4acd..803b9c5 100644 --- a/core/bitArray.js +++ b/core/bitArray.js @@ -42,6 +42,27 @@ sjcl.bitArray = { return (bend === undefined) ? a : sjcl.bitArray.clamp(a, bend-bstart); }, + /** + * Extract a number packed into a bit array. + * @param {bitArray} a The array to slice. + * @param {Number} bstart The offset to the start of the slice, in bits. + * @param {Number} length The length of the number to extract. + * @return {Number} The requested slice. + */ + extract: function(a, bstart, blength) { + // FIXME: this Math.floor is not necessary at all, but for some reason + // seems to suppress a bug in the Chromium JIT. + var x, sh = Math.floor((-bstart-blength) & 31); + if ((bstart + blength - 1 ^ bstart) & -32) { + // it crosses a boundary + x = (a[bstart/32|0] << (32 - sh)) ^ (a[bstart/32+1|0] >>> sh); + } else { + // within a single word + x = a[bstart/32|0] >>> sh; + } + return x & ((1<