Skip to content

Commit

Permalink
zext sign correction for bitcasting from <32 bits to i64
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Apr 19, 2012
1 parent 8cbede3 commit a00c765
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/analyzer.js
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions tests/runner.py
Expand Up @@ -909,6 +909,27 @@ def test_i64_precise(self):
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')
Expand Down

0 comments on commit a00c765

Please sign in to comment.