diff options
-rw-r--r-- | src/analyzer.js | 4 | ||||
-rwxr-xr-x | tests/runner.py | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 8ded86f1..1453b22c 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -544,6 +544,10 @@ function analyzer(data, sidePass) { params: [(signed && j + whole > sourceElements.length) ? signedKeepAlive : null], type: 'i32', }; + if (j == 0 && isUnsignedOp(value.op) && sourceBits < 32) { + // zext sign correction + result.ident = makeSignOp(result.ident, 'i' + sourceBits, 'un', 1, 1); + } if (fraction != 0) { var other = { intertype: 'value', diff --git a/tests/runner.py b/tests/runner.py index cfb0832c..ecda863e 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -909,6 +909,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 and 'jsbn' not in code, 'i64 precise math should not have been included if not actually used' + def test_i64_zextneg(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2') + + src = r''' + #include <stdint.h> + #include <stdio.h> + + int main(int argc, char *argv[]) + { + uint8_t byte = 0x80; + uint16_t two = byte; + uint32_t four = byte; + uint64_t eight = byte; + + printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight); + + return 0; + } + ''' + self.do_run(src, 'value: 128,128,128,128.') + def test_cube2hash(self): # A good test of i64 math if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2 C-style memory aliasing') |