Skip to content

Update SIMD to final spec #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "100.0.0",
"binaryen": "100.0.0-nightly.20210413",
"long": "^4.0.0",
"source-map-support": "^0.5.19",
"ts-node": "^6.2.0"
Expand Down
188 changes: 110 additions & 78 deletions src/builtins.ts

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ export class Compiler extends DiagnosticEmitter {
for (let i = 0, k = functionTable.length; i < k; ++i) {
functionTableNames[i] = functionTable[i].internalName;
}
module.setFunctionTable(tableBase + functionTable.length, Module.UNLIMITED_TABLE, functionTableNames, module.i32(tableBase));
module.addFunctionTable("0", tableBase + functionTable.length, Module.UNLIMITED_TABLE, functionTableNames, module.i32(tableBase));

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

// f32 to f64
if (toType.kind == TypeKind.F64) {
expr = module.unary(UnaryOp.PromoteF32, expr);
expr = module.unary(UnaryOp.PromoteF32ToF64, expr);
}

// otherwise f32 to f32

// f64 to f32
} else if (toType.kind == TypeKind.F32) {
expr = module.unary(UnaryOp.DemoteF64, expr);
expr = module.unary(UnaryOp.DemoteF64ToF32, expr);
}

// otherwise f64 to f64
Expand All @@ -3626,16 +3626,16 @@ export class Compiler extends DiagnosticEmitter {
} else if (toType.isSignedIntegerValue) {
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
if (toType.isLongIntegerValue) {
expr = module.unary(saturating ? UnaryOp.TruncF32ToI64Sat : UnaryOp.TruncF32ToI64, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToI64 : UnaryOp.TruncF32ToI64, expr);
} else {
expr = module.unary(saturating ? UnaryOp.TruncF32ToI32Sat : UnaryOp.TruncF32ToI32, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToI32 : UnaryOp.TruncF32ToI32, expr);
}
} else {
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
if (toType.isLongIntegerValue) {
expr = module.unary(saturating ? UnaryOp.TruncF32ToU64Sat : UnaryOp.TruncF32ToU64, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToU64 : UnaryOp.TruncF32ToU64, expr);
} else {
expr = module.unary(saturating ? UnaryOp.TruncF32ToU32Sat : UnaryOp.TruncF32ToU32, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF32ToU32 : UnaryOp.TruncF32ToU32, expr);
}
}

Expand All @@ -3646,16 +3646,16 @@ export class Compiler extends DiagnosticEmitter {
} else if (toType.isSignedIntegerValue) {
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
if (toType.isLongIntegerValue) {
expr = module.unary(saturating ? UnaryOp.TruncF64ToI64Sat : UnaryOp.TruncF64ToI64, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToI64 : UnaryOp.TruncF64ToI64, expr);
} else {
expr = module.unary(saturating ? UnaryOp.TruncF64ToI32Sat : UnaryOp.TruncF64ToI32, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToI32 : UnaryOp.TruncF64ToI32, expr);
}
} else {
let saturating = this.options.hasFeature(Feature.NONTRAPPING_F2I);
if (toType.isLongIntegerValue) {
expr = module.unary(saturating ? UnaryOp.TruncF64ToU64Sat : UnaryOp.TruncF64ToU64, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToU64 : UnaryOp.TruncF64ToU64, expr);
} else {
expr = module.unary(saturating ? UnaryOp.TruncF64ToU32Sat : UnaryOp.TruncF64ToU32, expr);
expr = module.unary(saturating ? UnaryOp.TruncSatF64ToU32 : UnaryOp.TruncF64ToU32, expr);
}
}
}
Expand Down Expand Up @@ -3715,13 +3715,13 @@ export class Compiler extends DiagnosticEmitter {
if (toType.isBooleanValue) {
expr = module.binary(BinaryOp.NeI64, expr, module.i64(0));
} else if (!toType.isLongIntegerValue) {
expr = module.unary(UnaryOp.WrapI64, expr); // discards upper bits
expr = module.unary(UnaryOp.WrapI64ToI32, expr); // discards upper bits
}

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

Expand Down Expand Up @@ -5013,7 +5013,7 @@ export class Compiler extends DiagnosticEmitter {
return module.binary(BinaryOp.NeF64, leftExpr, rightExpr);
}
case TypeKind.V128: {
return module.unary(UnaryOp.AnyTrueI8x16,
return module.unary(UnaryOp.AnyTrueV128,
module.binary(BinaryOp.NeI8x16, leftExpr, rightExpr)
);
}
Expand Down Expand Up @@ -9827,7 +9827,7 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.I8: {
if (flow.canOverflow(expr, type)) {
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
? module.unary(UnaryOp.ExtendI8ToI32, expr)
? module.unary(UnaryOp.Extend8I32, expr)
: module.binary(BinaryOp.ShrI32,
module.binary(BinaryOp.ShlI32,
expr,
Expand All @@ -9841,7 +9841,7 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.I16: {
if (flow.canOverflow(expr, type)) {
expr = this.options.hasFeature(Feature.SIGN_EXTENSION)
? module.unary(UnaryOp.ExtendI16ToI32, expr)
? module.unary(UnaryOp.Extend16I32, expr)
: module.binary(BinaryOp.ShrI32,
module.binary(BinaryOp.ShlI32,
expr,
Expand Down Expand Up @@ -10101,7 +10101,7 @@ export class Compiler extends DiagnosticEmitter {
return module.binary(BinaryOp.LeU32,
module.binary(BinaryOp.SubI32,
module.binary(BinaryOp.ShlI32,
module.unary(UnaryOp.ReinterpretF32, expr),
module.unary(UnaryOp.ReinterpretF32ToI32, expr),
module.i32(1)
),
module.i32(2) // 1 << 1
Expand All @@ -10118,7 +10118,7 @@ export class Compiler extends DiagnosticEmitter {
return module.binary(BinaryOp.LeU64,
module.binary(BinaryOp.SubI64,
module.binary(BinaryOp.ShlI64,
module.unary(UnaryOp.ReinterpretF64, expr),
module.unary(UnaryOp.ReinterpretF64ToI64, expr),
module.i64(1)
),
module.i64(2) // 1 << 1
Expand Down
12 changes: 10 additions & 2 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,7 @@ export declare function _BinaryenEventGetResults(event: BinaryenEventRef): Binar

type BinaryenTableRef = usize;

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

type BinaryenElementSegmentRef = usize;

export declare function _BinaryenAddActiveElementSegment(module: BinaryenModuleRef, table: BinaryenString, name: BinaryenString, funcNames: BinaryenArray<BinaryenString>, numFuncNames: BinaryenIndex, offset: BinaryenExpressionRef): BinaryenElementSegmentRef;
export declare function _BinaryenAddPassiveElementSegment(module: BinaryenModuleRef, name: BinaryenString, funcNames: BinaryenArray<BinaryenString>, numFuncNames: BinaryenIndex): BinaryenElementSegmentRef;
export declare function _BinaryenRemoveElementSegment(module: BinaryenModuleRef, name: BinaryenString): void;
export declare function _BinaryenGetNumElementSegments(module: BinaryenModuleRef, name: BinaryenString): BinaryenIndex;
export declare function _BinaryenGetElementSegment(module: BinaryenModuleRef, name: BinaryenString): BinaryenElementSegmentRef;
export declare function _BinaryenGetElementSegmentByIndex(module: BinaryenModuleRef, index: BinaryenIndex): BinaryenElementSegmentRef;

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;
export declare function _BinaryenGetNumMemorySegments(module: BinaryenModuleRef): BinaryenIndex;
export declare function _BinaryenGetMemorySegmentByteOffset(module: BinaryenModuleRef, index: BinaryenIndex): u32;
Expand Down
Loading