diff options
27 files changed, 75 insertions, 25 deletions
diff --git a/src/library.js b/src/library.js index 201a63e0..0e4ac0b2 100644 --- a/src/library.js +++ b/src/library.js @@ -8590,7 +8590,7 @@ LibraryManager.library = { inet_pton__deps: ['__setErrNo', '$ERRNO_CODES', 'inet_addr'], inet_pton: function(af, src, dst) { // int af, const char *src, void *dst - if ((af ^ {{{ cDefine("AF_INET") }}}) !== 0) { ___setErrNo(ERRNO_CODES.EAFNOSUPPORT); return -1; } + if ((af ^ {{{ cDefine('AF_INET') }}}) !== 0) { ___setErrNo(ERRNO_CODES.EAFNOSUPPORT); return -1; } var ret = _inet_addr(src); if (ret == -1 || isNaN(ret)) return 0; setValue(dst, ret, 'i32'); @@ -8678,7 +8678,7 @@ LibraryManager.library = { var aliasesBuf = _malloc(4); setValue(aliasesBuf, 0, 'i8*'); setValue(ret+___hostent_struct_layout.h_aliases, aliasesBuf, 'i8**'); - setValue(ret+___hostent_struct_layout.h_addrtype, {{{ cDefine("AF_INET") }}}, 'i32'); + setValue(ret+___hostent_struct_layout.h_addrtype, {{{ cDefine('AF_INET') }}}, 'i32'); setValue(ret+___hostent_struct_layout.h_length, 4, 'i32'); var addrListBuf = _malloc(12); setValue(addrListBuf, addrListBuf+8, 'i32*'); diff --git a/src/library_gl.js b/src/library_gl.js index d0f1a692..8c724245 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -636,6 +636,11 @@ var LibraryGL = { for (var i = 0; i < n; i++) { var id = {{{ makeGetValue('buffers', 'i*4', 'i32') }}}; var buffer = GL.buffers[id]; + + // From spec: "glDeleteBuffers silently ignores 0's and names that do not + // correspond to existing buffer objects." + if (!buffer) continue; + Module.ctx.deleteBuffer(buffer); buffer.name = 0; GL.buffers[id] = null; @@ -1318,7 +1323,7 @@ var LibraryGL = { GLEmulation.fogColor = new Float32Array(4); // Add some emulation workarounds - Module.printErr('WARNING: using emscripten GL emulation. This is a collection of limited workarounds, do not expect it to work'); + Module.printErr('WARNING: using emscripten GL emulation. This is a collection of limited workarounds, do not expect it to work. (If you do not want this, build with -s DISABLE_GL_EMULATION=1)'); #if GL_UNSAFE_OPTS == 0 Module.printErr('WARNING: using emscripten GL emulation unsafe opts. If weirdness happens, try -s GL_UNSAFE_OPTS=0'); #endif diff --git a/src/utility.js b/src/utility.js index 9cc8d3a3..7d122cef 100644 --- a/src/utility.js +++ b/src/utility.js @@ -312,6 +312,12 @@ function setUnion(x, y) { return ret; } +function setSize(x) { + var ret = 0; + for (var xx in x) ret++; + return ret; +} + function invertArray(x) { var ret = {}; for (var i = 0; i < x.length; i++) { diff --git a/system/include/sys/sendfile.h b/system/include/sys/sendfile.h new file mode 100644 index 00000000..1f58f0dd --- /dev/null +++ b/system/include/sys/sendfile.h @@ -0,0 +1,16 @@ +#ifndef _SYS_SENDFILE_H +#define _SYS_SENDFILE_H + +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tests/dirent/test_readdir.c b/tests/dirent/test_readdir.c index 9f7b12e8..12f97b73 100644 --- a/tests/dirent/test_readdir.c +++ b/tests/dirent/test_readdir.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -129,4 +130,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/fcntl-open/src.c b/tests/fcntl-open/src.c index bd52dd3f..fc5d5c76 100644 --- a/tests/fcntl-open/src.c +++ b/tests/fcntl-open/src.c @@ -1,6 +1,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -91,4 +92,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/glbook/CH02_HelloTriangle.png b/tests/glbook/CH02_HelloTriangle.png Binary files differindex d6351e2a..7b8c176e 100644 --- a/tests/glbook/CH02_HelloTriangle.png +++ b/tests/glbook/CH02_HelloTriangle.png diff --git a/tests/glbook/CH08_SimpleVertexShader.png b/tests/glbook/CH08_SimpleVertexShader.png Binary files differindex 84b276fd..6711784d 100644 --- a/tests/glbook/CH08_SimpleVertexShader.png +++ b/tests/glbook/CH08_SimpleVertexShader.png diff --git a/tests/glbook/CH09_SimpleTexture2D.png b/tests/glbook/CH09_SimpleTexture2D.png Binary files differindex e33539e9..7cb01698 100644 --- a/tests/glbook/CH09_SimpleTexture2D.png +++ b/tests/glbook/CH09_SimpleTexture2D.png diff --git a/tests/glbook/CH09_TextureCubemap.png b/tests/glbook/CH09_TextureCubemap.png Binary files differindex b592b047..2ca61b63 100644 --- a/tests/glbook/CH09_TextureCubemap.png +++ b/tests/glbook/CH09_TextureCubemap.png diff --git a/tests/glbook/CH09_TextureWrap.png b/tests/glbook/CH09_TextureWrap.png Binary files differindex 3367e254..1fb5a319 100644 --- a/tests/glbook/CH09_TextureWrap.png +++ b/tests/glbook/CH09_TextureWrap.png diff --git a/tests/glbook/CH10_MultiTexture.png b/tests/glbook/CH10_MultiTexture.png Binary files differindex 8e006eb3..dc7a0ed6 100644 --- a/tests/glbook/CH10_MultiTexture.png +++ b/tests/glbook/CH10_MultiTexture.png diff --git a/tests/glbook/CH13_ParticleSystem.png b/tests/glbook/CH13_ParticleSystem.png Binary files differindex 4b69414f..e0e4b31b 100644 --- a/tests/glbook/CH13_ParticleSystem.png +++ b/tests/glbook/CH13_ParticleSystem.png diff --git a/tests/htmltest.png b/tests/htmltest.png Binary files differindex 980245ee..36e87dd8 100644 --- a/tests/htmltest.png +++ b/tests/htmltest.png diff --git a/tests/runner.py b/tests/runner.py index 76841026..fa81f899 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -12062,7 +12062,7 @@ int main(int argc, char const *argv[]) open(os.path.join(self.get_dir(), 'test.file'), 'w').write('''ay file..............,,,,,,,,,,,,,,''') open(os.path.join(self.get_dir(), 'stdin'), 'w').write('''inter-active''') Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'files.cpp'), '-c']).communicate() - Popen([PYTHON, path_from_root('tools', 'nativize_llvm.py'), os.path.join(self.get_dir(), 'files.o')]).communicate(input)[0] + Popen([PYTHON, path_from_root('tools', 'nativize_llvm.py'), os.path.join(self.get_dir(), 'files.o')], stdout=PIPE, stderr=PIPE).communicate(input) output = Popen([os.path.join(self.get_dir(), 'files.o.run')], stdin=open(os.path.join(self.get_dir(), 'stdin')), stdout=PIPE, stderr=PIPE).communicate() self.assertContained('''size: 37 data: 119,97,107,97,32,119,97,107,97,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35 @@ -12367,6 +12367,8 @@ elif 'browser' in str(sys.argv): ''' + code def reftest(self, expected): + # make sure the pngs used here have no color correction, using e.g. + # pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile basename = os.path.basename(expected) shutil.copyfile(expected, os.path.join(self.get_dir(), basename)) open(os.path.join(self.get_dir(), 'reftest.js'), 'w').write(''' @@ -13657,7 +13659,7 @@ Press any key to continue.''' def test_sdl_rotozoom(self): shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) - self.btest('sdl_rotozoom.c', reference='sdl_rotozoom.png', args=['--preload-file', 'screenshot.png'], reference_slack=3) + self.btest('sdl_rotozoom.c', reference='sdl_rotozoom.png', args=['--preload-file', 'screenshot.png'], reference_slack=5) def test_sdl_gfx_primitives(self): self.btest('sdl_gfx_primitives.c', reference='sdl_gfx_primitives.png', reference_slack=1) @@ -14075,6 +14077,8 @@ elif 'benchmark' in str(sys.argv): total_native_times = map(lambda x: 0., range(TOTAL_TESTS)) class benchmark(RunnerCore): + save_dir = True + def print_stats(self, times, native_times, last=False, reps=TEST_REPS): if reps == 0: print '(no reps)' diff --git a/tests/sdl_gfx_primitives.png b/tests/sdl_gfx_primitives.png Binary files differindex 525b4f8f..706af9ae 100644 --- a/tests/sdl_gfx_primitives.png +++ b/tests/sdl_gfx_primitives.png diff --git a/tests/sdl_maprgba.png b/tests/sdl_maprgba.png Binary files differindex 4f64c7cd..caca4a8b 100644 --- a/tests/sdl_maprgba.png +++ b/tests/sdl_maprgba.png diff --git a/tests/sdl_rotozoom.png b/tests/sdl_rotozoom.png Binary files differindex 288dd303..5933754f 100644 --- a/tests/sdl_rotozoom.png +++ b/tests/sdl_rotozoom.png diff --git a/tests/stat/test_chmod.c b/tests/stat/test_chmod.c index cb84e028..3574760b 100644 --- a/tests/stat/test_chmod.c +++ b/tests/stat/test_chmod.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -126,4 +127,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/stat/test_mknod.c b/tests/stat/test_mknod.c index be1d0c39..361b2315 100644 --- a/tests/stat/test_mknod.c +++ b/tests/stat/test_mknod.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -88,4 +89,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/stat/test_stat.c b/tests/stat/test_stat.c index 6e220eb9..f59fb3c3 100644 --- a/tests/stat/test_stat.c +++ b/tests/stat/test_stat.c @@ -2,6 +2,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -161,4 +162,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/stdio/test_fgetc_ungetc.c b/tests/stdio/test_fgetc_ungetc.c index c69a3d1a..0eea4007 100644 --- a/tests/stdio/test_fgetc_ungetc.c +++ b/tests/stdio/test_fgetc_ungetc.c @@ -1,5 +1,6 @@ #include <assert.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -47,7 +48,9 @@ void test() { ungetc('a', file); err = fgetc(file); assert(err == (int)'a'); - fread(buffer, sizeof(char), sizeof(buffer), file); + int r = fread(buffer, sizeof(char), sizeof(buffer), file); + assert(r == 3); + buffer[3] = 0; assert(!strcmp(buffer, "bcd")); // rewind and fseek should reset anything that's been @@ -84,4 +87,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/unistd/unlink.c b/tests/unistd/unlink.c index 87252da2..f0a8f4dd 100644 --- a/tests/unistd/unlink.c +++ b/tests/unistd/unlink.c @@ -1,6 +1,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -135,4 +136,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tests/utime/test_utime.c b/tests/utime/test_utime.c index 1793f4a5..59e3e98a 100644 --- a/tests/utime/test_utime.c +++ b/tests/utime/test_utime.c @@ -1,5 +1,6 @@ #include <assert.h> #include <errno.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -50,4 +51,4 @@ int main() { setup(); test(); return EXIT_SUCCESS; -}
\ No newline at end of file +} diff --git a/tools/file_packager.py b/tools/file_packager.py index 136da609..1a9d925b 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -206,7 +206,7 @@ for file_ in data_files: abspath = os.path.abspath(path) if DEBUG: print >> sys.stderr, path, abspath, curr_abspath if not abspath.startswith(curr_abspath): - print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory. This is invalid since the current directory becomes the root that the generated code will see' % path + print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory "%s". This is invalid since the current directory becomes the root that the generated code will see' % (path, curr_abspath) sys.exit(1) file_['dstpath'] = abspath[len(curr_abspath)+1:] if os.path.isabs(path): diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 29b36cad..82942ce2 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2817,7 +2817,7 @@ function relocate(ast) { var other = node[3]; if (base === 0) return other; if (other[0] == 'num') { - other[1] += base; + other[1] = (other[1] + base)|0; return other; } else { node[2] = ['num', base]; @@ -3106,7 +3106,7 @@ function outline(ast) { // Reserve an extra two spots per possible outlining: one for control flow var, the other for control flow data // The control variables are zeroed out when calling an outlined function, and after using // the value after they return. - asmData.maxOutlinings = Math.round(3*measureSize(func)/sizeToOutline); + asmData.maxOutlinings = Math.round(3*measureSize(func)/extraInfo.sizeToOutline); asmData.totalStackSize = stackSize + (stack.length + 2*asmData.maxOutlinings)*8; asmData.controlStackPos = function(i) { return stackSize + (stack.length + i)*8 }; asmData.controlDataStackPos = function(i) { return stackSize + (stack.length + i)*8 + 4 }; @@ -3210,9 +3210,17 @@ function outline(ast) { var CONTROL_BREAK = 1, CONTROL_BREAK_LABEL = 2, CONTROL_CONTINUE = 3, CONTROL_CONTINUE_LABEL = 4, CONTROL_RETURN_VOID = 5, CONTROL_RETURN_INT = 6, CONTROL_RETURN_DOUBLE = 7; - var sizeToOutline = extraInfo.sizeToOutline; - var level = 0; + var sizeToOutline = null; // customized per function and as we make progress + function calculateThreshold(func) { + sizeToOutline = extraInfo.sizeToOutline; + var size = measureSize(func); + //var desiredChunks = Math.ceil(size/extraInfo.sizeToOutline); + ////sizeToOutline = Math.round((extraInfo.sizeToOutline + (2*size/desiredChunks))/3); + //sizeToOutline = Math.round(size/desiredChunks); + printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>= ' + extraInfo.sizeToOutline + '), aim for ' + sizeToOutline); + } + var level = 0; var outliningParents = {}; // function name => parent it was outlined from function doOutline(func, asmData, stats, start, end) { @@ -3225,13 +3233,13 @@ function outline(ast) { // analyze variables, and find 'owned' variables - that only appear in the outlined code, and do not need any spill support var codeInfo = analyzeCode(func, asmData, code); var allCodeInfo = analyzeCode(func, asmData, func); - //printErr(' do outline ' + [func[1], level, 'range:', start, end, 'of', stats.length, newIdent, measureSize(code), JSON.stringify(codeInfo.labels), JSON.stringify(codeInfo.breaks), JSON.stringify(codeInfo.continues)]); var owned = { sp: 1 }; // sp is always owned, each has its own keys(setUnion(codeInfo.reads, codeInfo.writes)).forEach(function(v) { if (allCodeInfo.reads[v] === codeInfo.reads[v] && allCodeInfo.writes[v] === codeInfo.writes[v] && !(v in asmData.params)) { owned[v] = 1; } }); + printErr('attempting outline ' + [func[1], newIdent, 'overhead:', setSize(setSub(codeInfo.writes, owned)), setSize(setSub(codeInfo.reads, owned))]); var reps = []; // wipe out control variable reps.push(['stat', makeAssign(makeStackAccess(ASM_INT, asmData.controlStackPos(outlineIndex)), ['num', 0])]); @@ -3426,6 +3434,7 @@ function outline(ast) { } } outliningParents[newIdent] = func[1]; + calculateThreshold(func); return [newFunc]; } @@ -3452,7 +3461,7 @@ function outline(ast) { } while (1) { i--; - calcMinIndex(); + calcMinIndex(); // TODO: optimize if (i < minIndex) { // we might be done. but, if we have just outlined, do a further attempt from the beginning. // (but only if the total costs are not extravagant) @@ -3536,7 +3545,7 @@ function outline(ast) { var newFuncs = doOutline(func, asmData, stats, i, end); // outline [i, .. ,end] inclusive if (newFuncs.length) { ret.push.apply(ret, newFuncs); - printErr('performed outline on ' + func[1] + ' of ' + sizeSeen + ', func is now size ' + measureSize(func) + ' ==> ' + newFuncs[0][1]); + printErr('performed outline on ' + func[1] + ' of ' + sizeSeen + ', => ' + newFuncs[0][1]); } sizeSeen = 0; end = i-1; @@ -3566,10 +3575,10 @@ function outline(ast) { funcs.forEach(function(func) { var asmData = normalizeAsm(func); var size = measureSize(func); - if (size >= sizeToOutline) { - printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>= ' + sizeToOutline + ')'); + if (size >= extraInfo.sizeToOutline) { aggressiveVariableElimination(func, asmData); flatten(func, asmData); + calculateThreshold(func); analyzeFunction(func, asmData); var stats = getStatements(func); var ret = outlineStatements(func, asmData, stats, 0.9*size); diff --git a/tools/shared.py b/tools/shared.py index 250c018d..c0df227d 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -599,7 +599,7 @@ def line_splitter(data): return out -def limit_size(string, MAX=80*20): +def limit_size(string, MAX=120*20): if len(string) < MAX: return string return string[0:MAX/2] + '\n[..]\n' + string[-MAX/2:] |