@@ -197,10 +197,20 @@ function isStructPointerType(type) {
197
197
return ! Compiletime . isNumberType ( type ) && type [ 0 ] == '%' ;
198
198
}
199
199
200
+ const POINTER_SIZE = MEMORY64 ? 8 : 4 ;
201
+ const POINTER_BITS = POINTER_SIZE * 8 ;
202
+ const POINTER_TYPE = 'i' + POINTER_BITS ;
203
+
204
+ const SIZE_TYPE = POINTER_TYPE ;
205
+
200
206
function isPointerType ( type ) {
201
207
return type [ type . length - 1 ] == '*' ;
202
208
}
203
209
210
+ function sizeT ( x ) {
211
+ return MEMORY64 ? `BigInt(${ x } )` : x ;
212
+ }
213
+
204
214
function isArrayType ( type ) {
205
215
return / ^ \[ \d + \ x \ ( .* ) \] / . test ( type ) ;
206
216
}
@@ -235,7 +245,7 @@ function isIntImplemented(type) {
235
245
236
246
// Note: works for iX types and structure types, not pointers (even though they are implemented as ints)
237
247
function getBits ( type , allowPointers ) {
238
- if ( allowPointers && isPointerType ( type ) ) return 32 ;
248
+ if ( allowPointers && isPointerType ( type ) ) return POINTER_SIZE ;
239
249
if ( ! type ) return 0 ;
240
250
if ( type [ 0 ] == 'i' ) {
241
251
const left = type . substr ( 1 ) ;
@@ -480,7 +490,7 @@ function checkSafeHeap() {
480
490
}
481
491
482
492
function getHeapOffset ( offset , type ) {
483
- if ( type == 'i64' ) {
493
+ if ( ! WASM_BIGINT && Runtime . getNativeFieldSize ( type ) > 4 && type == 'i64' ) {
484
494
// we emulate 64-bit integer values as 32 in asmjs-unknown-emscripten, but not double
485
495
type = 'i32' ;
486
496
}
@@ -623,7 +633,16 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa
623
633
return asmCoercion ( 'SAFE_HEAP_LOAD' + ( ( type in Compiletime . FLOAT_TYPES ) ? '_D' : '' ) + '(' + asmCoercion ( offset , 'i32' ) + ', ' + Runtime . getNativeTypeSize ( type ) + ', ' + ( ! ! unsigned + 0 ) + ')' , type , unsigned ? 'u' : undefined ) ;
624
634
}
625
635
}
626
- return getHeapForType ( type , unsigned ) + '[' + getHeapOffset ( offset , type ) + ']' ;
636
+
637
+ const slab = getHeapForType ( type , unsigned ) ;
638
+ let ret = slab + '[' + getHeapOffset ( offset , type ) + ']' ;
639
+ if ( slab . substr ( slab . length - 2 ) == '64' ) {
640
+ ret = `Number(${ ret } )` ;
641
+ }
642
+ if ( forceAsm ) {
643
+ ret = asmCoercion ( ret , type ) ;
644
+ }
645
+ return ret ;
627
646
}
628
647
629
648
/**
@@ -665,7 +684,7 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe,
665
684
return '(' + makeSetTempDouble ( 0 , 'double' , value ) + ',' +
666
685
makeSetValue ( ptr , pos , makeGetTempDouble ( 0 , 'i32' ) , 'i32' , noNeedFirst , ignore , align , noSafe , ',' ) + ',' +
667
686
makeSetValue ( ptr , getFastValue ( pos , '+' , Runtime . getNativeTypeSize ( 'i32' ) ) , makeGetTempDouble ( 1 , 'i32' ) , 'i32' , noNeedFirst , ignore , align , noSafe , ',' ) + ')' ;
668
- } else if ( type == 'i64' ) {
687
+ } else if ( ! WASM_BIGINT && type == 'i64' ) {
669
688
return '(tempI64 = [' + splitI64 ( value ) + '],' +
670
689
makeSetValue ( ptr , pos , 'tempI64[0]' , 'i32' , noNeedFirst , ignore , align , noSafe , ',' ) + ',' +
671
690
makeSetValue ( ptr , getFastValue ( pos , '+' , Runtime . getNativeTypeSize ( 'i32' ) ) , 'tempI64[1]' , 'i32' , noNeedFirst , ignore , align , noSafe , ',' ) + ')' ;
@@ -705,7 +724,12 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe,
705
724
return 'SAFE_HEAP_STORE' + ( ( type in Compiletime . FLOAT_TYPES ) ? '_D' : '' ) + '(' + asmCoercion ( offset , 'i32' ) + ', ' + asmCoercion ( value , type ) + ', ' + Runtime . getNativeTypeSize ( type ) + ')' ;
706
725
}
707
726
}
708
- return getHeapForType ( type ) + '[' + getHeapOffset ( offset , type ) + '] = ' + value ;
727
+
728
+ const slab = getHeapForType ( type ) ;
729
+ if ( slab == 'HEAPU64' || slab == 'HEAP64' ) {
730
+ value = `BigInt(${ value } )` ;
731
+ }
732
+ return slab + '[' + getHeapOffset ( offset , type ) + '] = ' + value ;
709
733
}
710
734
711
735
const UNROLL_LOOP_MAX = 8 ;
@@ -862,23 +886,29 @@ function getFastValue(a, op, b, type) {
862
886
863
887
function calcFastOffset ( ptr , pos , noNeedFirst ) {
864
888
assert ( ! noNeedFirst ) ;
889
+ if ( typeof ptr == 'bigint' ) ptr = Number ( ptr ) ;
890
+ if ( typeof pos == 'bigint' ) pos = Number ( pos ) ;
865
891
return getFastValue ( ptr , '+' , pos , 'i32' ) ;
866
892
}
867
893
868
894
function getHeapForType ( type , unsigned ) {
869
895
assert ( type ) ;
870
896
if ( isPointerType ( type ) ) {
871
- type = 'i32' ; // Hardcoded 32-bit
897
+ type = POINTER_TYPE ;
872
898
}
873
899
switch ( type ) {
874
900
case 'i1' :
875
901
case 'i8' :
876
902
return unsigned ? 'HEAPU8' : 'HEAP8' ;
877
903
case 'i16' :
878
904
return unsigned ? 'HEAPU16' : 'HEAP16' ;
905
+ case 'i64' :
906
+ if ( WASM_BIGINT ) {
907
+ return unsigned ? 'HEAPU64' : 'HEAP64' ;
908
+ }
909
+ // fall through
879
910
case '<4 x i32>' :
880
911
case 'i32' :
881
- case 'i64' :
882
912
return unsigned ? 'HEAPU32' : 'HEAP32' ;
883
913
case 'double' :
884
914
return 'HEAPF64' ;
@@ -908,10 +938,7 @@ function makeThrow(what) {
908
938
}
909
939
910
940
function makeSignOp ( value , type , op , force , ignore ) {
911
- if ( type == 'i64' ) {
912
- return value ; // these are always assumed to be two 32-bit unsigneds.
913
- }
914
- if ( isPointerType ( type ) ) type = 'i32' ; // Pointers are treated as 32-bit ints
941
+ if ( isPointerType ( type ) ) type = POINTER_TYPE ;
915
942
if ( ! value ) return value ;
916
943
let bits ;
917
944
let full ;
@@ -1292,6 +1319,26 @@ function sendI64Argument(low, high) {
1292
1319
return low + ', ' + high ;
1293
1320
}
1294
1321
1322
+ // Any function called from wasm64 may have bigint args, this function takes
1323
+ // a list of variable names to convert to number.
1324
+ function from64 ( x ) {
1325
+ if ( ! MEMORY64 ) {
1326
+ return '' ;
1327
+ }
1328
+ if ( Array . isArray ( x ) ) {
1329
+ let ret = '' ;
1330
+ for ( e of x ) ret += from64 ( e ) ;
1331
+ return ret ;
1332
+ } else {
1333
+ return `${ x } = Number(${ x } );` ;
1334
+ }
1335
+ }
1336
+
1337
+ function to64 ( x ) {
1338
+ if ( ! MEMORY64 ) return x ;
1339
+ return `BigInt(${ x } )` ;
1340
+ }
1341
+
1295
1342
// Add assertions to catch common errors when using the Promise object we
1296
1343
// create on Module.ready() and return from MODULARIZE Module() invocations.
1297
1344
function addReadyPromiseAssertions ( promise ) {
0 commit comments