aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js3
-rw-r--r--src/library.js25
-rw-r--r--src/library_browser.js20
-rw-r--r--src/parseTools.js9
-rw-r--r--src/settings.js12
5 files changed, 48 insertions, 21 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 163ff4a8..9bf93c86 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -1391,6 +1391,9 @@ function analyzer(data, sidePass) {
// Allocas
var finishedInitial = false;
+
+ lines = func.lines; // We need to consider all the function lines now, not just the first label
+
for (var i = 0; i < lines.length; i++) {
var item = lines[i];
if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.allocatedNum)) {
diff --git a/src/library.js b/src/library.js
index be2e946f..6a94be40 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3915,26 +3915,13 @@ LibraryManager.library = {
return limit;
},
- // A glibc-like implementation of the C random number generation functions:
- // http://pubs.opengroup.org/onlinepubs/000095399/functions/rand.html
- __rand_state: 42,
- srand__deps: ['__rand_state'],
- srand: function(seed) {
- // void srand(unsigned seed);
- ___rand_state = seed;
- },
- rand__deps: ['__rand_state'],
+ // Use browser's Math.random(). We can't set a seed, though.
+ srand: function(seed) {}, // XXX ignored
rand: function() {
- // int rand(void);
- ___rand_state = (1103515245 * ___rand_state + 12345) % 0x100000000;
- return ___rand_state & 0x7FFFFFFF;
- },
- rand_r: function(seed) {
- // int rand_r(unsigned *seed);
- var state = {{{ makeGetValue('seed', 0, 'i32') }}};
- state = (1103515245 * state + 12345) % 0x100000000;
- {{{ makeSetValue('seed', 0, 'state', 'i32') }}}
- return state & 0x7FFFFFFF;
+ return Math.floor(Math.random()*0x80000000);
+ },
+ rand_r: function(seed) { // XXX ignores the seed
+ return Math.floor(Math.random()*0x80000000);
},
realpath__deps: ['$FS', '__setErrNo'],
diff --git a/src/library_browser.js b/src/library_browser.js
index f285a6d2..11c9bf2c 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -10,6 +10,10 @@ mergeInto(LibraryManager.library, {
$Browser: {
mainLoop: {
scheduler: null,
+#if PROFILE_MAIN_LOOP
+ meanTime: 0,
+ lastReport: 0,
+#endif
shouldPause: false,
paused: false,
queue: [],
@@ -93,7 +97,7 @@ mergeInto(LibraryManager.library, {
}
if (!b) {
var bb = new Browser.BlobBuilder();
- bb.append(byteArray.buffer);
+ bb.append((new Uint8Array(byteArray)).buffer); // we need to pass a buffer, and must copy the array to get the right data range
b = bb.getBlob();
}
var url = Browser.URLObject.createObjectURL(b);
@@ -394,7 +398,21 @@ mergeInto(LibraryManager.library, {
Browser.mainLoop.shouldPause = false;
return;
}
+
+#if PROFILE_MAIN_LOOP
+ var start = performance.now();
+#endif
jsFunc();
+#if PROFILE_MAIN_LOOP
+ var now = performance.now();
+ var time = now - start;
+ Browser.mainLoop.meanTime = (Browser.mainLoop.meanTime*9 + time)/10;
+ if (now - Browser.mainLoop.lastReport > 1000) {
+ console.log('main loop time: ' + Browser.mainLoop.meanTime);
+ Browser.mainLoop.lastReport = now;
+ }
+#endif
+
if (Browser.mainLoop.shouldPause) {
// catch pauses from the main loop itself
Browser.mainLoop.paused = true;
diff --git a/src/parseTools.js b/src/parseTools.js
index 86e3c643..e37f3a99 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1794,7 +1794,14 @@ function processMathop(item) {
case 'add': return handleOverflow(getFastValue(idents[0], '+', idents[1], item.type), bits);
case 'sub': return handleOverflow(getFastValue(idents[0], '-', idents[1], item.type), bits);
case 'sdiv': case 'udiv': return makeRounding(getFastValue(idents[0], '/', idents[1], item.type), bits, op[0] === 's');
- case 'mul': return handleOverflow(getFastValue(idents[0], '*', idents[1], item.type), bits);
+ case 'mul': {
+ if (bits == 32 && PRECISE_I32_MUL) {
+ preciseI64MathUsed = true;
+ return '(i64Math.multiply(' + idents[0] + ',0,' + idents[1] + ',0),i64Math.result[0])';
+ } else {
+ return handleOverflow(getFastValue(idents[0], '*', idents[1], item.type), bits);
+ }
+ }
case 'urem': case 'srem': return getFastValue(idents[0], '%', idents[1], item.type);
case 'or': {
if (bits > 32) {
diff --git a/src/settings.js b/src/settings.js
index 09b17c83..cf329568 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -76,6 +76,16 @@ var DOUBLE_MODE = 1; // How to load and store 64-bit doubles. Without typed arra
// NaN or an infinite number.
var PRECISE_I64_MATH = 1; // If enabled, i64 addition etc. is emulated - which is slow but precise. If disabled,
// we use the 'double trick' which is fast but incurs rounding at high values.
+ // Note that we do not catch 32-bit multiplication by default (which must be done in
+ // 64 bits for high values for full precision) - you must manually set PRECISE_I32_MUL
+ // for that.
+var PRECISE_I32_MUL = 0; // If enabled, i64 math is done in i32 multiplication. This is necessary if the values
+ // exceed the JS double-integer limit of ~52 bits. This option can normally be disabled
+ // because generally i32 multiplication works ok without it, and enabling it has a big
+ // impact on performance.
+ // Note that you can hand-optimize your code to avoid the need for this: If you do
+ // multiplications that actually need 64-bit precision inside 64-bit values, things
+ // will work properly. (Unless the LLVM optimizer turns them into 32-bit values?)
var CLOSURE_ANNOTATIONS = 0; // If set, the generated code will be annotated for the closure
// compiler. This potentially lets closure optimize the code better.
@@ -115,6 +125,8 @@ var LIBRARY_DEBUG = 0; // Print out when we enter a library call (library*.js).
var GL_DEBUG = 0; // Print out all calls into WebGL. As with LIBRARY_DEBUG, you can set a runtime
// option, in this case GL.debug.
+var PROFILE_MAIN_LOOP = 0; // Profile the function called in set_main_loop
+
var DISABLE_EXCEPTION_CATCHING = 0; // Disables generating code to actually catch exceptions. If the code you
// are compiling does not actually rely on catching exceptions (but the
// compiler generates code for it, maybe because of stdlibc++ stuff),