diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-11-16 11:13:08 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-11-16 11:26:55 -0800 |
commit | 76071e42f3dcb22fec93c0ea963710988b566df0 (patch) | |
tree | f8a22498d9ea0aef9bdae9dfa43a485b8f705909 | |
parent | 9953de1d753ccf77494b42b0c19577413e5de6a1 (diff) |
print out hexadecimal 64-bit values properly, and fix some bugs with I64_PRECISE mode 2; fixes #716
-rw-r--r-- | src/library.js | 11 | ||||
-rwxr-xr-x | tests/runner.py | 17 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/library.js b/src/library.js index fd5e0fae..eb4aad40 100644 --- a/src/library.js +++ b/src/library.js @@ -2741,7 +2741,7 @@ LibraryManager.library = { var signed = next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0); argSize = argSize || 4; var currArg = getNextArg('i' + (argSize * 8)); -#if PRECISE_I64_MATH == 1 +#if PRECISE_I64_MATH var origArg = currArg; #endif var argText; @@ -2760,12 +2760,12 @@ LibraryManager.library = { var currAbsArg = Math.abs(currArg); var prefix = ''; if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) { -#if PRECISE_I64_MATH == 1 - if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1]); else +#if PRECISE_I64_MATH + if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1], null); else #endif argText = reSign(currArg, 8 * argSize, 1).toString(10); } else if (next == 'u'.charCodeAt(0)) { -#if PRECISE_I64_MATH == 1 +#if PRECISE_I64_MATH if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1], true); else #endif argText = unSign(currArg, 8 * argSize, 1).toString(10); @@ -2774,6 +2774,9 @@ LibraryManager.library = { argText = (flagAlternative ? '0' : '') + currAbsArg.toString(8); } else if (next == 'x'.charCodeAt(0) || next == 'X'.charCodeAt(0)) { prefix = flagAlternative ? '0x' : ''; +#if PRECISE_I64_MATH + if (argSize == 8 && i64Math) argText = (origArg[1]>>>0).toString(16) + (origArg[0]>>>0).toString(16); else +#endif if (currArg < 0) { // Represent negative numbers in hex as 2's complement. currArg = -currArg; diff --git a/tests/runner.py b/tests/runner.py index f454d098..de964809 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -996,12 +996,27 @@ m_divisor is 1091269979 code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read() assert 'goog.math.Long' not in code, 'i64 precise math should not have been included if not actually used' - # But if we force it to be included, it is + # But if we force it to be included, it is. First, a case where we don't need it Settings.PRECISE_I64_MATH = 2 self.do_run(open(path_from_root('tests', 'hello_world.c')).read(), 'hello') code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read() assert 'goog.math.Long' in code, 'i64 precise math should be included if forced' + # and now one where we do + self.do_run(r''' + #include <stdio.h> + + int main( int argc, char ** argv ) + { + unsigned long a = 0x60DD1695U; + unsigned long b = 0xCA8C4E7BU; + unsigned long long c = (unsigned long long)a * b; + printf( "c = %016llx\n", c ); + + return 0; + } + ''', 'c = 4ca38a6bd2973f97') + def test_i64_zextneg(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2') |