aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-16 10:49:47 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-11-16 10:49:47 -0800
commit9953de1d753ccf77494b42b0c19577413e5de6a1 (patch)
tree0a283e1bde7949b33c22da831823e3a908130dd3
parentd82d4ea70fc43816a857038cd16eb5520ddd14c6 (diff)
add PRECISE_I64_MATH mode 2, to force inclusion of i64 code even when we can't tell at compile time it is needed. helps with #716
-rw-r--r--src/modules.js5
-rw-r--r--src/settings.js4
-rwxr-xr-xtests/runner.py10
3 files changed, 15 insertions, 4 deletions
diff --git a/src/modules.js b/src/modules.js
index 1449e3f4..f85794bc 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -207,8 +207,9 @@ var Types = {
needAnalysis: {}, // Types noticed during parsing, that need analysis
- preciseI64MathUsed: false // Set to true if we actually use precise i64 math: If PRECISE_I64_MATH is set, and also such math is actually
- // needed (+,-,*,/,% - we do not need it for bitops)
+ // Set to true if we actually use precise i64 math: If PRECISE_I64_MATH is set, and also such math is actually
+ // needed (+,-,*,/,% - we do not need it for bitops), or PRECISE_I64_MATH is 2 (forced)
+ preciseI64MathUsed: (PRECISE_I64_MATH == 2)
};
var Functions = {
diff --git a/src/settings.js b/src/settings.js
index 58635950..9cdb496b 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -88,6 +88,10 @@ var PRECISE_I64_MATH = 1; // If enabled, i64 addition etc. is emulated - which i
// 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.
+ // If set to 2, we always include the i64 math code, which is necessary in the case
+ // that we can't know at compile time that 64-bit math is needed. For example, if you
+ // print 64-bit values with printf, but never add them, we can't know at compile time
+ // and you need to set this to 2.
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
diff --git a/tests/runner.py b/tests/runner.py
index 0baf79dc..f454d098 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -970,7 +970,7 @@ m_divisor is 1091269979
Settings.PRECISE_I64_MATH = 0
self.do_run(src, 'unsigned')
code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read()
- assert 'goog.math.Long' not in code and 'jsbn' not in code, 'i64 precise math should not have been included if not asked for'
+ assert 'goog.math.Long' not in code, 'i64 precise math should not have been included if not asked for'
# Verify that even if we ask for precision, if it is not needed it is not included
Settings.PRECISE_I64_MATH = 1
@@ -994,7 +994,13 @@ m_divisor is 1091269979
'''
self.do_run(src, '*4903566027370624, 153236438355333*')
code = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read()
- assert 'goog.math.Long' not in code and 'jsbn' not in code, 'i64 precise math should not have been included if not actually used'
+ 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
+ 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'
def test_i64_zextneg(self):
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')