Skip to content

Commit 991649f

Browse files
committed
support bitcasts of doubles to i64s in i64 mode 1
1 parent c707fc8 commit 991649f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/parseTools.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,20 @@ function processMathop(item) {
16871687
case 'sdiv': case 'udiv': warnI64_1(); return splitI64(makeRounding(mergeI64(ident1) + '/' + mergeI64(ident2), bits, op[0] === 's'));
16881688
case 'mul': warnI64_1(); return handleOverflow(splitI64(mergeI64(ident1) + '*' + mergeI64(ident2)), bits);
16891689
case 'urem': case 'srem': warnI64_1(); return splitI64(mergeI64(ident1) + '%' + mergeI64(ident2));
1690-
default: throw 'Unsupported i64 mode 1 op: ' + item.op;
1690+
case 'bitcast': {
1691+
// Pointers are not 64-bit, so there is really only one possible type of bitcast here, int to float or vice versa
1692+
assert(USE_TYPED_ARRAYS == 2, 'Can only bitcast ints <-> floats with typed arrays mode 2');
1693+
var inType = item.param1.type;
1694+
var outType = item.type;
1695+
if (inType in Runtime.INT_TYPES && outType in Runtime.FLOAT_TYPES) {
1696+
return makeInlineCalculation('tempDoubleI32[0]=VALUE[0],tempDoubleI32[1]=VALUE[1],tempDoubleF64[0]', ident1, 'tempI64');
1697+
} else if (inType in Runtime.FLOAT_TYPES && outType in Runtime.INT_TYPES) {
1698+
return '(tempDoubleF64[0]=' + ident1 + ',[tempDoubleI32[0],tempDoubleI32[1]])';
1699+
} else {
1700+
throw 'Invalid I64_MODE1 bitcast: ' + dump(item) + ' : ' + item.param1.type;
1701+
}
1702+
}
1703+
default: throw 'Unsupported i64 mode 1 op: ' + item.op + ' : ' + dump(item);
16911704
}
16921705
}
16931706

@@ -1822,7 +1835,7 @@ function processMathop(item) {
18221835
if ((inType in Runtime.INT_TYPES && outType in Runtime.FLOAT_TYPES) ||
18231836
(inType in Runtime.FLOAT_TYPES && outType in Runtime.INT_TYPES)) {
18241837
assert(USE_TYPED_ARRAYS == 2, 'Can only bitcast ints <-> floats with typed arrays mode 2');
1825-
assert(inType == 'i32' || inType == 'float', 'Can only bitcast ints <-> floats with 32 bits, for now');
1838+
assert(inType == 'i32' || inType == 'float', 'Can only bitcast ints <-> floats with 32 bits (try I64_MODE=1)');
18261839
if (inType in Runtime.INT_TYPES) {
18271840
return '(tempDoubleI32[0] = ' + ident1 + ',tempDoubleF32[0])';
18281841
} else {

0 commit comments

Comments
 (0)