Skip to content
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
24 changes: 12 additions & 12 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "92.0.0-nightly.20200426",
"binaryen": "93.0.0-nightly.20200514",
"long": "^4.0.0",
"source-map-support": "^0.5.19",
"ts-node": "^6.2.0"
},
"devDependencies": {
"@types/node": "^13.13.2",
"@types/node": "^14.0.1",
"browser-process-hrtime": "^1.0.0",
"diff": "^4.0.2",
"glob": "^7.1.6",
"physical-cpu-count": "^2.0.0",
"source-map-support": "^0.5.19",
"ts-loader": "^6.2.2",
"ts-loader": "^7.0.4",
"ts-node": "^6.2.0",
"tslint": "^5.20.1",
"typescript": "^3.8.3",
"typescript": "^3.9.2",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
Expand Down
104 changes: 104 additions & 0 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ export namespace BuiltinNames {
export const v128_bitmask = "~lib/builtins/v128.bitmask";
export const v128_min = "~lib/builtins/v128.min";
export const v128_max = "~lib/builtins/v128.max";
export const v128_pmin = "~lib/builtins/v128.pmin";
export const v128_pmax = "~lib/builtins/v128.pmax";
export const v128_dot = "~lib/builtins/v128.dot";
export const v128_avgr = "~lib/builtins/v128.avgr";
export const v128_abs = "~lib/builtins/v128.abs";
Expand Down Expand Up @@ -521,6 +523,8 @@ export namespace BuiltinNames {
export const f32x4_neg = "~lib/builtins/f32x4.neg";
export const f32x4_min = "~lib/builtins/f32x4.min";
export const f32x4_max = "~lib/builtins/f32x4.max";
export const f32x4_pmin = "~lib/builtins/f32x4.pmin";
export const f32x4_pmax = "~lib/builtins/f32x4.pmax";
export const f32x4_abs = "~lib/builtins/f32x4.abs";
export const f32x4_sqrt = "~lib/builtins/f32x4.sqrt";
export const f32x4_eq = "~lib/builtins/f32x4.eq";
Expand All @@ -544,6 +548,8 @@ export namespace BuiltinNames {
export const f64x2_neg = "~lib/builtins/f64x2.neg";
export const f64x2_min = "~lib/builtins/f64x2.min";
export const f64x2_max = "~lib/builtins/f64x2.max";
export const f64x2_pmin = "~lib/builtins/f64x2.pmin";
export const f64x2_pmax = "~lib/builtins/f64x2.pmax";
export const f64x2_abs = "~lib/builtins/f64x2.abs";
export const f64x2_sqrt = "~lib/builtins/f64x2.sqrt";
export const f64x2_eq = "~lib/builtins/f64x2.eq";
Expand Down Expand Up @@ -3969,6 +3975,68 @@ function builtin_v128_max(ctx: BuiltinContext): ExpressionRef {
}
builtins.set(BuiltinNames.v128_max, builtin_v128_max);

// v128.pmin<T!>(a: v128, b: v128) -> v128
function builtin_v128_pmin(ctx: BuiltinContext): ExpressionRef {
var compiler = ctx.compiler;
var module = compiler.module;
if (
checkFeatureEnabled(ctx, Feature.SIMD) |
checkTypeRequired(ctx) |
checkArgsRequired(ctx, 2)
) {
compiler.currentType = Type.v128;
return module.unreachable();
}
var operands = ctx.operands;
var typeArguments = ctx.typeArguments!;
var type = typeArguments[0];
var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT);
var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT);
if (!type.is(TypeFlags.REFERENCE)) {
switch (type.kind) {
case TypeKind.F32: return module.binary(BinaryOp.PminF32x4, arg0, arg1);
case TypeKind.F64: return module.binary(BinaryOp.PminF64x2, arg0, arg1);
}
}
compiler.error(
DiagnosticCode.Operation_0_cannot_be_applied_to_type_1,
ctx.reportNode.typeArgumentsRange, "v128.pmin", type.toString()
);
return module.unreachable();
}
builtins.set(BuiltinNames.v128_pmin, builtin_v128_pmin);

// v128.pmax<T!>(a: v128, b: v128) -> v128
function builtin_v128_pmax(ctx: BuiltinContext): ExpressionRef {
var compiler = ctx.compiler;
var module = compiler.module;
if (
checkFeatureEnabled(ctx, Feature.SIMD) |
checkTypeRequired(ctx) |
checkArgsRequired(ctx, 2)
) {
compiler.currentType = Type.v128;
return module.unreachable();
}
var operands = ctx.operands;
var typeArguments = ctx.typeArguments!;
var type = typeArguments[0];
var arg0 = compiler.compileExpression(operands[0], Type.v128, Constraints.CONV_IMPLICIT);
var arg1 = compiler.compileExpression(operands[1], Type.v128, Constraints.CONV_IMPLICIT);
if (!type.is(TypeFlags.REFERENCE)) {
switch (type.kind) {
case TypeKind.F32: return module.binary(BinaryOp.PmaxF32x4, arg0, arg1);
case TypeKind.F64: return module.binary(BinaryOp.PmaxF64x2, arg0, arg1);
}
}
compiler.error(
DiagnosticCode.Operation_0_cannot_be_applied_to_type_1,
ctx.reportNode.typeArgumentsRange, "v128.pmax", type.toString()
);
return module.unreachable();
}
builtins.set(BuiltinNames.v128_pmax, builtin_v128_pmax);

// v128.dot<T!>(a: v128, b: v128) -> v128
function builtin_v128_dot(ctx: BuiltinContext): ExpressionRef {
var compiler = ctx.compiler;
Expand Down Expand Up @@ -7444,6 +7512,24 @@ function builtin_f32x4_max(ctx: BuiltinContext): ExpressionRef {
}
builtins.set(BuiltinNames.f32x4_max, builtin_f32x4_max);

// f32x4.pmin -> v128.pmin<f32>
function builtin_f32x4_pmin(ctx: BuiltinContext): ExpressionRef {
checkTypeAbsent(ctx);
ctx.typeArguments = [ Type.f32 ];
ctx.contextualType = Type.v128;
return builtin_v128_pmin(ctx);
}
builtins.set(BuiltinNames.f32x4_pmin, builtin_f32x4_pmin);

// f32x4.pmax -> v128.pmax<f32>
function builtin_f32x4_pmax(ctx: BuiltinContext): ExpressionRef {
checkTypeAbsent(ctx);
ctx.typeArguments = [ Type.f32 ];
ctx.contextualType = Type.v128;
return builtin_v128_pmax(ctx);
}
builtins.set(BuiltinNames.f32x4_pmax, builtin_f32x4_pmax);

// f32x4.abs -> v128.abs<f32>
function builtin_f32x4_abs(ctx: BuiltinContext): ExpressionRef {
checkTypeAbsent(ctx);
Expand Down Expand Up @@ -7642,6 +7728,24 @@ function builtin_f64x2_max(ctx: BuiltinContext): ExpressionRef {
}
builtins.set(BuiltinNames.f64x2_max, builtin_f64x2_max);

// f64x2.pmin -> v128.pmin<f64>
function builtin_f64x2_pmin(ctx: BuiltinContext): ExpressionRef {
checkTypeAbsent(ctx);
ctx.typeArguments = [ Type.f64 ];
ctx.contextualType = Type.v128;
return builtin_v128_pmin(ctx);
}
builtins.set(BuiltinNames.f64x2_pmin, builtin_f64x2_pmin);

// f64x2.pmax -> v128.pmax<f64>
function builtin_f64x2_pmax(ctx: BuiltinContext): ExpressionRef {
checkTypeAbsent(ctx);
ctx.typeArguments = [ Type.f64 ];
ctx.contextualType = Type.v128;
return builtin_v128_pmax(ctx);
}
builtins.set(BuiltinNames.f64x2_pmax, builtin_f64x2_pmax);

// f64x2.abs -> v128.abs<f64>
function builtin_f64x2_abs(ctx: BuiltinContext): ExpressionRef {
checkTypeAbsent(ctx);
Expand Down
3 changes: 1 addition & 2 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ export declare function _BinaryenPop(module: BinaryenModuleRef, type: BinaryenTy
export declare function _BinaryenExpressionGetId(expr: BinaryenExpressionRef): BinaryenExpressionId;
export declare function _BinaryenExpressionGetType(expr: BinaryenExpressionRef): BinaryenType;
export declare function _BinaryenExpressionPrint(expr: BinaryenExpressionRef): void;
export declare function _BinaryenExpressionCopy(expr: BinaryenExpressionRef, module: BinaryenModuleRef): BinaryenExpressionRef;

export declare function _BinaryenBlockGetName(expr: BinaryenExpressionRef): usize;
export declare function _BinaryenBlockGetNumChildren(expr: BinaryenExpressionRef): BinaryenIndex;
Expand Down Expand Up @@ -837,5 +838,3 @@ export declare function _BinaryenGetFlexibleInlineMaxSize(): BinaryenIndex;
export declare function _BinaryenSetFlexibleInlineMaxSize(size: BinaryenIndex): void;
export declare function _BinaryenGetOneCallerInlineMaxSize(): BinaryenIndex;
export declare function _BinaryenSetOneCallerInlineMaxSize(size: BinaryenIndex): void;

export declare function _BinaryenSetAPITracing(on: bool): void;
30 changes: 19 additions & 11 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,21 @@ export enum BinaryOp {
DivF32x4 = 159 /* _BinaryenDivVecF32x4 */,
MinF32x4 = 160 /* _BinaryenMinVecF32x4 */,
MaxF32x4 = 161 /* _BinaryenMaxVecF32x4 */,
AddF64x2 = 162 /* _BinaryenAddVecF64x2 */,
SubF64x2 = 163 /* _BinaryenSubVecF64x2 */,
MulF64x2 = 164 /* _BinaryenMulVecF64x2 */,
DivF64x2 = 165 /* _BinaryenDivVecF64x2 */,
MinF64x2 = 166 /* _BinaryenMinVecF64x2 */,
MaxF64x2 = 167 /* _BinaryenMaxVecF64x2 */,
NarrowI16x8ToI8x16 = 168 /* _BinaryenNarrowSVecI16x8ToVecI8x16 */,
NarrowU16x8ToU8x16 = 169 /* _BinaryenNarrowUVecI16x8ToVecI8x16 */,
NarrowI32x4ToI16x8 = 170 /* _BinaryenNarrowSVecI32x4ToVecI16x8 */,
NarrowU32x4ToU16x8 = 171 /* _BinaryenNarrowUVecI32x4ToVecI16x8 */,
SwizzleV8x16 = 172 /* _BinaryenSwizzleVec8x16 */
PminF32x4 = 162 /* _BinaryenPMinVecF32x4 */,
PmaxF32x4 = 163 /* _BinaryenPMaxVecF32x4 */,
AddF64x2 = 164 /* _BinaryenAddVecF64x2 */,
SubF64x2 = 165 /* _BinaryenSubVecF64x2 */,
MulF64x2 = 166 /* _BinaryenMulVecF64x2 */,
DivF64x2 = 167 /* _BinaryenDivVecF64x2 */,
MinF64x2 = 168 /* _BinaryenMinVecF64x2 */,
MaxF64x2 = 169 /* _BinaryenMaxVecF64x2 */,
PminF64x2 = 170 /* _BinaryenPMinVecF64x2 */,
PmaxF64x2 = 171 /* _BinaryenPMaxVecF64x2 */,
NarrowI16x8ToI8x16 = 172 /* _BinaryenNarrowSVecI16x8ToVecI8x16 */,
NarrowU16x8ToU8x16 = 173 /* _BinaryenNarrowUVecI16x8ToVecI8x16 */,
NarrowI32x4ToI16x8 = 174 /* _BinaryenNarrowSVecI32x4ToVecI16x8 */,
NarrowU32x4ToU16x8 = 175 /* _BinaryenNarrowUVecI32x4ToVecI16x8 */,
SwizzleV8x16 = 176 /* _BinaryenSwizzleVec8x16 */
}

export enum HostOp {
Expand Down Expand Up @@ -1778,6 +1782,10 @@ export class Module {
return 0;
}

copyExpression(expr: ExpressionRef): ExpressionRef {
return binaryen._BinaryenExpressionCopy(expr, this.ref);
}

runExpression(expr: ExpressionRef, flags: ExpressionRunnerFlags, maxDepth: i32 = 50, maxLoopIterations: i32 = 1): ExpressionRef {
var runner = binaryen._ExpressionRunnerCreate(this.ref, flags, maxDepth, maxLoopIterations);
var precomp = binaryen._ExpressionRunnerRunAndDispose(runner, expr);
Expand Down
24 changes: 24 additions & 0 deletions std/assembly/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,14 @@ export namespace v128 {
@builtin
export declare function max<T>(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function pmin<T>(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function pmax<T>(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function dot<T>(a: v128, b: v128): v128; // i16 only
Expand Down Expand Up @@ -1763,6 +1771,14 @@ export namespace f32x4 {
@builtin
export declare function max(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function pmin(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function pmax(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function abs(a: v128): v128;
Expand Down Expand Up @@ -1858,6 +1874,14 @@ export namespace f64x2 {
@builtin
export declare function max(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function pmin(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function pmax(a: v128, b: v128): v128;

// @ts-ignore: decorator
@builtin
export declare function abs(a: v128): v128;
Expand Down
12 changes: 12 additions & 0 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ declare namespace v128 {
export function min<T>(a: v128, b: v128): v128;
/** Computes the maximum of each lane. */
export function max<T>(a: v128, b: v128): v128;
/** Computes the pseudo-minimum of each lane. */
export function pmin<T>(a: v128, b: v128): v128;
/** Computes the pseudo-maximum of each lane. */
export function pmax<T>(a: v128, b: v128): v128;
/** Computes the dot product of two lanes each, yielding lanes one size wider than the input. */
export function dot<T = i16>(a: v128, b: v128): v128;
/** Computes the average of each lane. */
Expand Down Expand Up @@ -933,6 +937,10 @@ declare namespace f32x4 {
export function min(a: v128, b: v128): v128;
/** Computes the maximum of each 32-bit float lane. */
export function max(a: v128, b: v128): v128;
/** Computes the pseudo-minimum of each 32-bit float lane. */
export function pmin(a: v128, b: v128): v128;
/** Computes the pseudo-maximum of each 32-bit float lane. */
export function pmax(a: v128, b: v128): v128;
/** Computes the absolute value of each 32-bit float lane. */
export function abs(a: v128): v128;
/** Computes the square root of each 32-bit float lane. */
Expand Down Expand Up @@ -981,6 +989,10 @@ declare namespace f64x2 {
export function min(a: v128, b: v128): v128;
/** Computes the maximum of each 64-bit float lane. */
export function max(a: v128, b: v128): v128;
/** Computes the pseudo-minimum of each 64-bit float lane. */
export function pmin(a: v128, b: v128): v128;
/** Computes the pseudo-maximum of each 64-bit float lane. */
export function pmax(a: v128, b: v128): v128;
/** Computes the absolute value of each 64-bit float lane. */
export function abs(a: v128): v128;
/** Computes the square root of each 64-bit float lane. */
Expand Down