Skip to content

Commit 86dc8df

Browse files
authored
Prepare SIMD for final spec (#1789)
1 parent 7e20ad2 commit 86dc8df

File tree

278 files changed

+3555
-3178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+3555
-3178
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
2222
},
2323
"dependencies": {
24-
"binaryen": "100.0.0",
24+
"binaryen": "100.0.0-nightly.20210413",
2525
"long": "^4.0.0",
2626
"source-map-support": "^0.5.19",
2727
"ts-node": "^6.2.0"

src/builtins.ts

+110-78
Large diffs are not rendered by default.

src/compiler.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ export class Compiler extends DiagnosticEmitter {
705705
for (let i = 0, k = functionTable.length; i < k; ++i) {
706706
functionTableNames[i] = functionTable[i].internalName;
707707
}
708-
module.setFunctionTable(tableBase + functionTable.length, Module.UNLIMITED_TABLE, functionTableNames, module.i32(tableBase));
708+
module.addFunctionTable("0", tableBase + functionTable.length, Module.UNLIMITED_TABLE, functionTableNames, module.i32(tableBase));
709709

710710
// expose the arguments length helper if there are varargs exports
711711
if (this.runtimeFeatures & RuntimeFeatures.setArgumentsLength) {
@@ -3604,14 +3604,14 @@ export class Compiler extends DiagnosticEmitter {
36043604

36053605
// f32 to f64
36063606
if (toType.kind == TypeKind.F64) {
3607-
expr = module.unary(UnaryOp.PromoteF32, expr);
3607+
expr = module.unary(UnaryOp.PromoteF32ToF64, expr);
36083608
}
36093609

36103610
// otherwise f32 to f32
36113611

36123612
// f64 to f32
36133613
} else if (toType.kind == TypeKind.F32) {
3614-
expr = module.unary(UnaryOp.DemoteF64, expr);
3614+
expr = module.unary(UnaryOp.DemoteF64ToF32, expr);
36153615
}
36163616

36173617
// otherwise f64 to f64
@@ -3626,16 +3626,16 @@ export class Compiler extends DiagnosticEmitter {
36263626
} else if (toType.isSignedIntegerValue) {
36273627
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
36283628
if (toType.isLongIntegerValue) {
3629-
expr = module.unary(saturating ? UnaryOp.TruncF32ToI64Sat : UnaryOp.TruncF32ToI64, expr);
3629+
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToI64 : UnaryOp.TruncF32ToI64, expr);
36303630
} else {
3631-
expr = module.unary(saturating ? UnaryOp.TruncF32ToI32Sat : UnaryOp.TruncF32ToI32, expr);
3631+
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToI32 : UnaryOp.TruncF32ToI32, expr);
36323632
}
36333633
} else {
36343634
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
36353635
if (toType.isLongIntegerValue) {
3636-
expr = module.unary(saturating ? UnaryOp.TruncF32ToU64Sat : UnaryOp.TruncF32ToU64, expr);
3636+
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToU64 : UnaryOp.TruncF32ToU64, expr);
36373637
} else {
3638-
expr = module.unary(saturating ? UnaryOp.TruncF32ToU32Sat : UnaryOp.TruncF32ToU32, expr);
3638+
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToU32 : UnaryOp.TruncF32ToU32, expr);
36393639
}
36403640
}
36413641

@@ -3646,16 +3646,16 @@ export class Compiler extends DiagnosticEmitter {
36463646
} else if (toType.isSignedIntegerValue) {
36473647
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
36483648
if (toType.isLongIntegerValue) {
3649-
expr = module.unary(saturating ? UnaryOp.TruncF64ToI64Sat : UnaryOp.TruncF64ToI64, expr);
3649+
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToI64 : UnaryOp.TruncF64ToI64, expr);
36503650
} else {
3651-
expr = module.unary(saturating ? UnaryOp.TruncF64ToI32Sat : UnaryOp.TruncF64ToI32, expr);
3651+
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToI32 : UnaryOp.TruncF64ToI32, expr);
36523652
}
36533653
} else {
36543654
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
36553655
if (toType.isLongIntegerValue) {
3656-
expr = module.unary(saturating ? UnaryOp.TruncF64ToU64Sat : UnaryOp.TruncF64ToU64, expr);
3656+
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToU64 : UnaryOp.TruncF64ToU64, expr);
36573657
} else {
3658-
expr = module.unary(saturating ? UnaryOp.TruncF64ToU32Sat : UnaryOp.TruncF64ToU32, expr);
3658+
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToU32 : UnaryOp.TruncF64ToU32, expr);
36593659
}
36603660
}
36613661
}
@@ -3715,13 +3715,13 @@ export class Compiler extends DiagnosticEmitter {
37153715
if (toType.isBooleanValue) {
37163716
expr = module.binary(BinaryOp.NeI64, expr, module.i64(0));
37173717
} else if (!toType.isLongIntegerValue) {
3718-
expr = module.unary(UnaryOp.WrapI64, expr); // discards upper bits
3718+
expr = module.unary(UnaryOp.WrapI64ToI32, expr); // discards upper bits
37193719
}
37203720

37213721
// i32 or smaller to i64
37223722
} else if (toType.isLongIntegerValue) {
37233723
expr = module.unary(
3724-
fromType.isSignedIntegerValue ? UnaryOp.ExtendI32 : UnaryOp.ExtendU32,
3724+
fromType.isSignedIntegerValue ? UnaryOp.ExtendI32ToI64 : UnaryOp.ExtendU32ToU64,
37253725
this.ensureSmallIntegerWrap(expr, fromType) // must clear garbage bits
37263726
);
37273727

@@ -5013,7 +5013,7 @@ export class Compiler extends DiagnosticEmitter {
50135013
return module.binary(BinaryOp.NeF64, leftExpr, rightExpr);
50145014
}
50155015
case TypeKind.V128: {
5016-
return module.unary(UnaryOp.AnyTrueI8x16,
5016+
return module.unary(UnaryOp.AnyTrueV128,
50175017
module.binary(BinaryOp.NeI8x16, leftExpr, rightExpr)
50185018
);
50195019
}
@@ -9827,7 +9827,7 @@ export class Compiler extends DiagnosticEmitter {
98279827
case TypeKind.I8: {
98289828
if (flow.canOverflow(expr, type)) {
98299829
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
9830-
? module.unary(UnaryOp.ExtendI8ToI32, expr)
9830+
? module.unary(UnaryOp.Extend8I32, expr)
98319831
: module.binary(BinaryOp.ShrI32,
98329832
module.binary(BinaryOp.ShlI32,
98339833
expr,
@@ -9841,7 +9841,7 @@ export class Compiler extends DiagnosticEmitter {
98419841
case TypeKind.I16: {
98429842
if (flow.canOverflow(expr, type)) {
98439843
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
9844-
? module.unary(UnaryOp.ExtendI16ToI32, expr)
9844+
? module.unary(UnaryOp.Extend16I32, expr)
98459845
: module.binary(BinaryOp.ShrI32,
98469846
module.binary(BinaryOp.ShlI32,
98479847
expr,
@@ -10101,7 +10101,7 @@ export class Compiler extends DiagnosticEmitter {
1010110101
return module.binary(BinaryOp.LeU32,
1010210102
module.binary(BinaryOp.SubI32,
1010310103
module.binary(BinaryOp.ShlI32,
10104-
module.unary(UnaryOp.ReinterpretF32, expr),
10104+
module.unary(UnaryOp.ReinterpretF32ToI32, expr),
1010510105
module.i32(1)
1010610106
),
1010710107
module.i32(2) // 1 << 1
@@ -10118,7 +10118,7 @@ export class Compiler extends DiagnosticEmitter {
1011810118
return module.binary(BinaryOp.LeU64,
1011910119
module.binary(BinaryOp.SubI64,
1012010120
module.binary(BinaryOp.ShlI64,
10121-
module.unary(UnaryOp.ReinterpretF64, expr),
10121+
module.unary(UnaryOp.ReinterpretF64ToI64, expr),
1012210122
module.i64(1)
1012310123
),
1012410124
module.i64(2) // 1 << 1

src/glue/binaryen.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,7 @@ export declare function _BinaryenEventGetResults(event: BinaryenEventRef): Binar
958958

959959
type BinaryenTableRef = usize;
960960

961-
export declare function _BinaryenSetFunctionTable(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, funcs: BinaryenArray<BinaryenString>, numFuncs: BinaryenIndex, offset: BinaryenExpressionRef): void;
962-
export declare function _BinaryenAddTable(module: BinaryenModuleRef, name: BinaryenString, initial: BinaryenIndex, maximum: BinaryenIndex, funcNames: BinaryenArray<BinaryenString>, numFunctNames: BinaryenIndex, offset: BinaryenExpressionRef): BinaryenTableRef;
961+
export declare function _BinaryenAddTable(module: BinaryenModuleRef, name: BinaryenString, initial: BinaryenIndex, maximum: BinaryenIndex): BinaryenTableRef;
963962
export declare function _BinaryenRemoveTable(module: BinaryenModuleRef, table: BinaryenString): void;
964963
export declare function _BinaryenGetNumTables(module: BinaryenModuleRef): BinaryenIndex;
965964
export declare function _BinaryenGetTable(module: BinaryenModuleRef, name: BinaryenString): BinaryenTableRef;
@@ -973,6 +972,15 @@ export declare function _BinaryenTableHasMax(table: BinaryenTableRef): bool;
973972
export declare function _BinaryenTableGetMax(table: BinaryenTableRef): BinaryenIndex;
974973
export declare function _BinaryenTableSetMax(table: BinaryenTableRef, max: BinaryenIndex): void;
975974

975+
type BinaryenElementSegmentRef = usize;
976+
977+
export declare function _BinaryenAddActiveElementSegment(module: BinaryenModuleRef, table: BinaryenString, name: BinaryenString, funcNames: BinaryenArray<BinaryenString>, numFuncNames: BinaryenIndex, offset: BinaryenExpressionRef): BinaryenElementSegmentRef;
978+
export declare function _BinaryenAddPassiveElementSegment(module: BinaryenModuleRef, name: BinaryenString, funcNames: BinaryenArray<BinaryenString>, numFuncNames: BinaryenIndex): BinaryenElementSegmentRef;
979+
export declare function _BinaryenRemoveElementSegment(module: BinaryenModuleRef, name: BinaryenString): void;
980+
export declare function _BinaryenGetNumElementSegments(module: BinaryenModuleRef, name: BinaryenString): BinaryenIndex;
981+
export declare function _BinaryenGetElementSegment(module: BinaryenModuleRef, name: BinaryenString): BinaryenElementSegmentRef;
982+
export declare function _BinaryenGetElementSegmentByIndex(module: BinaryenModuleRef, index: BinaryenIndex): BinaryenElementSegmentRef;
983+
976984
export declare function _BinaryenSetMemory(module: BinaryenModuleRef, initial: BinaryenIndex, maximum: BinaryenIndex, exportName: BinaryenString, segments: BinaryenArray<BinaryenArray<u8>>, segmentPassive: BinaryenArray<bool>, segmentOffsets: BinaryenArray<usize>, segmentSizes: BinaryenArray<u32>, numSegments: BinaryenIndex, shared: bool): void;
977985
export declare function _BinaryenGetNumMemorySegments(module: BinaryenModuleRef): BinaryenIndex;
978986
export declare function _BinaryenGetMemorySegmentByteOffset(module: BinaryenModuleRef, index: BinaryenIndex): u32;

0 commit comments

Comments
 (0)