aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/runtime.js7
-rw-r--r--src/utility.js4
2 files changed, 9 insertions, 2 deletions
diff --git a/src/runtime.js b/src/runtime.js
index 39aed12c..190260e6 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -101,11 +101,14 @@ var Runtime = {
forceAlign: function(target, quantum) {
quantum = quantum || {{{ QUANTUM_SIZE }}};
+ if (quantum == 1) return target;
if (isNumber(target) && isNumber(quantum)) {
return Math.ceil(target/quantum)*quantum;
- } else {
- return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
+ } else if (isNumber(quantum) && isPowerOfTwo(quantum)) {
+ var logg = log2(quantum);
+ return '((((' +target + ')+' + (quantum-1) + ')>>' + logg + ')<<' + logg + ')';
}
+ return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
},
isNumberType: function(type) {
diff --git a/src/utility.js b/src/utility.js
index 4ffe46a0..5ddccfd4 100644
--- a/src/utility.js
+++ b/src/utility.js
@@ -297,6 +297,10 @@ function log2(x) {
return Math.log(x)/Math.LN2;
}
+function isPowerOfTwo(x) {
+ return x > 0 && ((x & (x-1)) == 0);
+}
+
function Benchmarker() {
var starts = {}, times = {}, counts = {};
this.start = function(id) {