diff options
-rw-r--r-- | src/library.js | 17 | ||||
-rw-r--r-- | src/library_openal.js | 71 | ||||
-rw-r--r-- | src/parseTools.js | 4 | ||||
-rw-r--r-- | system/include/libc/ctype.h | 44 | ||||
-rwxr-xr-x | tests/runner.py | 72 | ||||
-rw-r--r-- | tools/js-optimizer.js | 11 |
6 files changed, 151 insertions, 68 deletions
diff --git a/src/library.js b/src/library.js index d5f11cf3..382c21ad 100644 --- a/src/library.js +++ b/src/library.js @@ -2642,7 +2642,7 @@ LibraryManager.library = { // format: A pointer to the format string. // varargs: A pointer to the start of the arguments list. // Returns the resulting string string as a character array. - _formatString__deps: ['strlen'], + _formatString__deps: ['strlen', '_reallyNegative'], _formatString: function(format, varargs) { var textIndex = format; var argIndex = 0; @@ -2897,7 +2897,6 @@ LibraryManager.library = { // Float. var currArg = getNextArg('double'); var argText; - if (isNaN(currArg)) { argText = 'nan'; flagZeroPad = false; @@ -2932,6 +2931,9 @@ LibraryManager.library = { } } else if (next == {{{ charCode('f') }}} || next == {{{ charCode('F') }}}) { argText = currArg.toFixed(effectivePrecision); + if (currArg === 0 && __reallyNegative(currArg)) { + argText = '-' + argText; + } } var parts = argText.split('e'); @@ -4950,7 +4952,7 @@ LibraryManager.library = { var ret = 0; while (x) { if (x&1) ret++; - x >>= 1; + x >>>= 1; } return ret; }, @@ -5478,9 +5480,14 @@ LibraryManager.library = { return isNaN(x); }, __isnan: 'isnan', + + _reallyNegative: function(x) { + return x < 0 || (x === 0 && (1/x) === -Infinity); + }, + + copysign__deps: ['_reallyNegative'], copysign: function(a, b) { - if (a < 0 === b < 0) return a; - return -a; + return __reallyNegative(a) === __reallyNegative(b) ? a : -a; }, copysignf: 'copysign', __signbit__deps: ['copysign'], diff --git a/src/library_openal.js b/src/library_openal.js index 6bd0f6b0..3d3c11f2 100644 --- a/src/library_openal.js +++ b/src/library_openal.js @@ -57,6 +57,7 @@ var LibraryOpenAL = { } if (ctx) { + ctx.listener.panningModel = "equalpower"; AL.contexts.push({ctx: ctx, err: 0, src: [], buf: []}); return AL.contexts.length; } else { @@ -81,7 +82,7 @@ var LibraryOpenAL = { return; } for (var i = 0; i < count; ++i) { - var sourceIdx = {{{ makeGetValue('sources', 'i', 'i32') }}} - 1; + var sourceIdx = {{{ makeGetValue('sources', 'i*4', 'i32') }}} - 1; delete AL.currentContext.src[sourceIdx]; } }, @@ -196,15 +197,15 @@ var LibraryOpenAL = { case 0x1004 /* AL_POSITION */: AL.currentContext.src[source - 1].panner.setPosition( {{{ makeGetValue('value', '0', 'float') }}}, - {{{ makeGetValue('value', '1', 'float') }}}, - {{{ makeGetValue('value', '2', 'float') }}} + {{{ makeGetValue('value', '4', 'float') }}}, + {{{ makeGetValue('value', '8', 'float') }}} ); break; case 0x1006 /* AL_VELOCITY */: AL.currentContext.src[source - 1].panner.setVelocity( {{{ makeGetValue('value', '0', 'float') }}}, - {{{ makeGetValue('value', '1', 'float') }}}, - {{{ makeGetValue('value', '2', 'float') }}} + {{{ makeGetValue('value', '4', 'float') }}}, + {{{ makeGetValue('value', '8', 'float') }}} ); break; default: @@ -235,7 +236,7 @@ var LibraryOpenAL = { return; } for (var i = 0; i < count; ++i) { - var buffer = {{{ makeGetValue('buffers', 'i', 'i32') }}}; + var buffer = {{{ makeGetValue('buffers', 'i*4', 'i32') }}}; if (buffer > AL.currentContext.buf.length) { #if OPENAL_DEBUG console.error("alSourceQueueBuffers called with an invalid buffer"); @@ -287,7 +288,7 @@ var LibraryOpenAL = { return; } for (var i = 0; i < count; ++i) { - var bufferIdx = {{{ makeGetValue('buffers', 'i', 'i32') }}} - 1; + var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}} - 1; var buffer = AL.currentContext.buf[bufferIdx].buf; for (var j = 0; j < AL.currentContext.src.length; ++j) { if (buffer == AL.currentContext.src[j].buffer) { @@ -385,14 +386,18 @@ var LibraryOpenAL = { return; } var offset = 0; - if ("src" in AL.currentContext.src[source - 1]) { - // If the source is already playing, we need to resume from beginning. - // We do that by stopping the current source and replaying it. - _alSourceStop(source); - } else if (AL.currentContext.src[source - 1].paused) { - // So now we have to resume playback, remember the offset here. - offset = AL.currentContext.src[source - 1].pausedTime - - AL.currentContext.src[source - 1].playTime; + if ("src" in AL.currentContext.src[source - 1] && + AL.currentContext.src[source - 1]["src"].buffer == + AL.currentContext.src[source - 1].buffer) { + if (AL.currentContext.src[source - 1].paused) { + // So now we have to resume playback, remember the offset here. + offset = AL.currentContext.src[source - 1].pausedTime - + AL.currentContext.src[source - 1].playTime; + } else { + // If the source is already playing, we need to resume from beginning. + // We do that by stopping the current source and replaying it. + _alSourceStop(source); + } } var src = AL.currentContext.ctx.createBufferSource(); src.loop = AL.currentContext.src[source - 1].loop; @@ -513,9 +518,43 @@ var LibraryOpenAL = { }, alListenerfv: function(param, values) { + if (!AL.currentContext) { #if OPENAL_DEBUG - console.log("alListenerfv is not supported yet"); + console.error("alListenerfv called without a valid context"); #endif + return; + } + switch (param) { + case 0x1004 /* AL_POSITION */: + AL.currentContext.ctx.listener.setPosition( + {{{ makeGetValue('values', '0', 'float') }}}, + {{{ makeGetValue('values', '4', 'float') }}}, + {{{ makeGetValue('values', '8', 'float') }}} + ); + break; + case 0x1006 /* AL_VELOCITY */: + AL.currentContext.ctx.listener.setVelocity( + {{{ makeGetValue('values', '0', 'float') }}}, + {{{ makeGetValue('values', '4', 'float') }}}, + {{{ makeGetValue('values', '8', 'float') }}} + ); + break; + case 0x100F /* AL_ORIENTATION */: + AL.currentContext.ctx.listener.setOrientation( + {{{ makeGetValue('values', '0', 'float') }}}, + {{{ makeGetValue('values', '4', 'float') }}}, + {{{ makeGetValue('values', '8', 'float') }}}, + {{{ makeGetValue('values', '12', 'float') }}}, + {{{ makeGetValue('values', '16', 'float') }}}, + {{{ makeGetValue('values', '20', 'float') }}} + ); + break; + default: +#if OPENAL_DEBUG + console.log("alListenerfv with param " + param + " not implemented yet"); +#endif + break; + } }, alIsExtensionPresent: function(extName) { diff --git a/src/parseTools.js b/src/parseTools.js index 2664baed..9fddacbb 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -818,7 +818,9 @@ function parseNumerical(value, type) { return '0'; } if (isNumber(value)) { - return parseFloat(value).toString(); // will change e.g. 5.000000e+01 to 50 + var ret = parseFloat(value); // will change e.g. 5.000000e+01 to 50 + if (type in Runtime.FLOAT_TYPES && value[0] == '-' && ret === 0) return '-0'; // fix negative 0, toString makes it 0 + return ret.toString(); } else { return value; } diff --git a/system/include/libc/ctype.h b/system/include/libc/ctype.h index 383a8db1..666c4d7c 100644 --- a/system/include/libc/ctype.h +++ b/system/include/libc/ctype.h @@ -117,20 +117,6 @@ extern __IMPORT _CONST char _ctype_[]; _END_STD_C - - - - - - - - - - - - - - /* * Copyright (c) 2000, 2005, 2008 Apple Inc. All rights reserved. * @@ -196,25 +182,15 @@ _END_STD_C * @(#)ctype.h 8.4 (Berkeley) 1/21/94 */ -#define _CTYPE_A 0x00000100L /* Alpha */ -#define _CTYPE_C 0x00000200L /* Control */ -#define _CTYPE_D 0x00000400L /* Digit */ -#define _CTYPE_G 0x00000800L /* Graph */ -#define _CTYPE_L 0x00001000L /* Lower */ -#define _CTYPE_P 0x00002000L /* Punct */ -#define _CTYPE_S 0x00004000L /* Space */ -#define _CTYPE_U 0x00008000L /* Upper */ -#define _CTYPE_X 0x00010000L /* X digit */ -#define _CTYPE_B 0x00020000L /* Blank */ -#define _CTYPE_R 0x00040000L /* Print */ -#define _CTYPE_I 0x00080000L /* Ideogram */ -#define _CTYPE_T 0x00100000L /* Special */ -#define _CTYPE_Q 0x00200000L /* Phonogram */ -#define _CTYPE_SW0 0x20000000L /* 0 width character */ -#define _CTYPE_SW1 0x40000000L /* 1 width character */ -#define _CTYPE_SW2 0x80000000L /* 2 width character */ -#define _CTYPE_SW3 0xc0000000L /* 3 width character */ -#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */ -#define _CTYPE_SWS 30 /* Bits to shift to get width */ +#define _CTYPE_A 0x00000400 /* Alpha */ +#define _CTYPE_C 0x00000002 /* Control */ +#define _CTYPE_D 0x00000800 /* Digit */ +#define _CTYPE_L 0x00000200 /* Lower */ +#define _CTYPE_P 0x00000004 /* Punct */ +#define _CTYPE_S 0x00002000 /* Space */ +#define _CTYPE_U 0x00000100 /* Upper */ +#define _CTYPE_X 0x00001000 /* X digit */ +#define _CTYPE_B 0x00000001 /* Blank */ +#define _CTYPE_R 0x00004000 /* Print */ #endif /* _CTYPE_H_ */ diff --git a/tests/runner.py b/tests/runner.py index 529dcc48..168567d2 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1234,6 +1234,59 @@ m_divisor is 1091269979 ''' self.do_run(src, ',0,,2,C!,0,C!,0,,65535,C!,0,') + def test_negative_zero(self): + src = r''' + #include <stdio.h> + #include <math.h> + + int main() { + #define TEST(x, y) \ + printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y)); + TEST( 5.0f, 5.0f); + TEST( 5.0f, -5.0f); + TEST(-5.0f, 5.0f); + TEST(-5.0f, -5.0f); + TEST( 5.0f, 4.0f); + TEST( 5.0f, -4.0f); + TEST(-5.0f, 4.0f); + TEST(-5.0f, -4.0f); + TEST( 0.0f, 5.0f); + TEST( 0.0f, -5.0f); + TEST(-0.0f, 5.0f); + TEST(-0.0f, -5.0f); + TEST( 5.0f, 0.0f); + TEST( 5.0f, -0.0f); + TEST(-5.0f, 0.0f); + TEST(-5.0f, -0.0f); + TEST( 0.0f, 0.0f); + TEST( 0.0f, -0.0f); + TEST(-0.0f, 0.0f); + TEST(-0.0f, -0.0f); + return 0; + } + ''' + self.do_run(src, '''5.00, 5.00 ==> 5.00 +5.00, -5.00 ==> -5.00 +-5.00, 5.00 ==> 5.00 +-5.00, -5.00 ==> -5.00 +5.00, 4.00 ==> 5.00 +5.00, -4.00 ==> -5.00 +-5.00, 4.00 ==> 5.00 +-5.00, -4.00 ==> -5.00 +0.00, 5.00 ==> 0.00 +0.00, -5.00 ==> -0.00 +-0.00, 5.00 ==> 0.00 +-0.00, -5.00 ==> -0.00 +5.00, 0.00 ==> 5.00 +5.00, -0.00 ==> -5.00 +-5.00, 0.00 ==> 5.00 +-5.00, -0.00 ==> -5.00 +0.00, 0.00 ==> 0.00 +0.00, -0.00 ==> -0.00 +-0.00, 0.00 ==> 0.00 +-0.00, -0.00 ==> -0.00 +''') + def test_llvm_intrinsics(self): if self.emcc_args == None: return self.skip('needs ta2') @@ -1269,6 +1322,7 @@ m_divisor is 1091269979 printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10)); printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), llvm_cttz_i32(1<<10)); printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), llvm_ctpop_i32(0x3101)); + printf("%d\n", (int)llvm_ctpop_i32(-594093059)); printf("%d\n", llvm_expect_i32(x % 27, 3)); @@ -1286,6 +1340,7 @@ c5,de,15,8a 23,21 40,10 5,4 +22 13 72057594037927936 ''') @@ -5095,7 +5150,7 @@ def process(filename): 0 0 0 - 0 + -0 1 1 1 @@ -10003,6 +10058,7 @@ f.close() (path_from_root('tools', 'test-js-optimizer-asm-last.js'), open(path_from_root('tools', 'test-js-optimizer-asm-last-output.js')).read(), ['asm', 'last']), ]: + print input output = Popen(listify(NODE_JS) + [path_from_root('tools', 'js-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).communicate()[0] self.assertIdentical(expected, output.replace('\r\n', '\n').replace('\n\n', '\n')) @@ -10019,13 +10075,19 @@ f.close() try: os.environ['EMCC_DEBUG'] = '1' for asm, linkable, chunks, js_chunks in [ - (0, 0, 3, 2), (0, 1, 4, 4), - (1, 0, 3, 2), (1, 1, 4, 5) + (0, 0, 3, 2), (0, 1, 3, 4), + (1, 0, 3, 2), (1, 1, 3, 4) ]: print asm, linkable, chunks, js_chunks output, err = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp'), '-O1', '-s', 'LINKABLE=%d' % linkable, '-s', 'ASM_JS=%d' % asm, '-s', 'UNRESOLVED_AS_DEAD=1'], stdout=PIPE, stderr=PIPE).communicate() - assert 'phase 2 working on %d chunks' %chunks in err, err - assert 'splitting up js optimization into %d chunks' % js_chunks in err, err + ok = False + for c in range(chunks, chunks+2): + ok = ok or ('phase 2 working on %d chunks' % c in err) + assert ok, err + ok = False + for c in range(js_chunks, js_chunks+2): + ok = ok or ('splitting up js optimization into %d chunks' % c in err) + assert ok, err finally: del os.environ['EMCC_DEBUG'] diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 48ab5a1f..5ede0ce8 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2287,19 +2287,16 @@ function minifyGlobals(ast) { function prepDotZero(ast) { traverse(ast, function(node, type) { if (type == 'unary-prefix' && node[1] == '+') { - if (node[2][0] == 'num') { + if (node[2][0] == 'num' || + (node[2][0] == 'unary-prefix' && node[2][1] == '-' && node[2][2][0] == 'num')) { return ['call', ['name', 'DOT$ZERO'], [node[2]]]; - } else if (node[2][0] == 'unary-prefix' && node[2][1] == '-' && node[2][2][0] == 'num') { - node[2][2][1] = -node[2][2][1]; - return ['call', ['name', 'DOT$ZERO'], [node[2][2]]]; } } }); } function fixDotZero(js) { - return js.replace(/DOT\$ZERO\(((0x)?[-+]?[0-9a-f]*\.?[0-9]+([eE][-+]?[0-9]+)?)\)/g, function(m, num) { - if (num.substr(0, 2) == '0x') { - if (num[2] == '-') num = '-0x' + num.substr(3); // uglify generates 0x-8000 for some reason + return js.replace(/DOT\$ZERO\(([-+]?(0x)?[0-9a-f]*\.?[0-9]+([eE][-+]?[0-9]+)?)\)/g, function(m, num) { + if (num.substr(0, 2) == '0x' || num.substr(0, 3) == '-0x') { return eval(num) + '.0'; } if (num.indexOf('.') >= 0) return num; |