Skip to content
Closed
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
76 changes: 76 additions & 0 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ export namespace BuiltinSymbols {
export const i16x8_shr_u = "~lib/builtins/i16x8.shr_u";
export const i16x8_any_true = "~lib/builtins/i16x8.any_true";
export const i16x8_all_true = "~lib/builtins/i16x8.all_true";
export const i16x8_min = "~lib/builtins/i16x8.min";
export const i16x8_max = "~lib/builtins/i16x8.max";
export const i16x8_eq = "~lib/builtins/i16x8.eq";
export const i16x8_ne = "~lib/builtins/i16x8.ne";
export const i16x8_lt_s = "~lib/builtins/i16x8.lt_s";
Expand All @@ -391,6 +393,8 @@ export namespace BuiltinSymbols {
export const i32x4_shr_u = "~lib/builtins/i32x4.shr_u";
export const i32x4_any_true = "~lib/builtins/i32x4.any_true";
export const i32x4_all_true = "~lib/builtins/i32x4.all_true";
export const i32x4_min = "~lib/builtins/i32x4.min";
export const i32x4_max = "~lib/builtins/i32x4.max";
export const i32x4_eq = "~lib/builtins/i32x4.eq";
export const i32x4_ne = "~lib/builtins/i32x4.ne";
export const i32x4_lt_s = "~lib/builtins/i32x4.lt_s";
Expand All @@ -415,6 +419,8 @@ export namespace BuiltinSymbols {
export const i64x2_shr_u = "~lib/builtins/i64x2.shr_u";
export const i64x2_any_true = "~lib/builtins/i64x2.any_true";
export const i64x2_all_true = "~lib/builtins/i64x2.all_true"; // i64x2 has no .eq etc.
export const i64x2_min = "~lib/builtins/i64x2.min";
export const i64x2_max = "~lib/builtins/i64x2.max";
export const i64x2_trunc_s_f64x2_sat = "~lib/builtins/i64x2.trunc_s_f64x2_sat";
export const i64x2_trunc_u_f64x2_sat = "~lib/builtins/i64x2.trunc_u_f64x2_sat";

Expand Down Expand Up @@ -4840,6 +4846,41 @@ export function compileCall(
}
let op: BinaryOp;
switch (type.kind) {
case TypeKind.I8:
case TypeKind.U8:
case TypeKind.I16:
case TypeKind.U16:
case TypeKind.I32:
case TypeKind.U32: {
// case TypeKind.I64:
// case TypeKind.U64: {
let flow = compiler.currentFlow;
arg0 = compiler.compileExpression(operands[0], Type.v128, ConversionKind.IMPLICIT, WrapMode.NONE);
arg1 = compiler.compileExpression(operands[1], Type.v128, ConversionKind.IMPLICIT, WrapMode.NONE);
let tempLocal0 = flow.getTempLocal(Type.v128);
let tempLocal1 = flow.getAndFreeTempLocal(Type.v128, false);
flow.freeTempLocal(tempLocal0);
switch (type.kind) {
case TypeKind.I8: { op = BinaryOp.LtSVecI8x16; break; }
case TypeKind.U8: { op = BinaryOp.LtUVecI8x16; break; }
case TypeKind.I16: { op = BinaryOp.LtSVecI16x8; break; }
case TypeKind.U16: { op = BinaryOp.LtUVecI16x8; break; }
case TypeKind.I32: { op = BinaryOp.LtSVecI32x4; break; }
case TypeKind.U32: { op = BinaryOp.LtUVecI32x4; break; }
// case TypeKind.I64: { op = BinaryOp.LtSVecI64x2; break; }
// case TypeKind.U64: { op = BinaryOp.LtUVecI64x2; break; }
default: { op = BinaryOp.LtSVecI8x16; break; }
}

return module.createSIMDBitselect(
module.createTeeLocal(tempLocal0.index, arg0),
module.createTeeLocal(tempLocal1.index, arg1),
module.createBinary(op,
module.createGetLocal(tempLocal0.index, NativeType.V128),
module.createGetLocal(tempLocal1.index, NativeType.V128)
)
);
}
case TypeKind.F32: { op = BinaryOp.MinVecF32x4; break; }
case TypeKind.F64: { op = BinaryOp.MinVecF64x2; break; }
default: {
Expand Down Expand Up @@ -4882,6 +4923,41 @@ export function compileCall(
}
let op: BinaryOp;
switch (type.kind) {
case TypeKind.I8:
case TypeKind.U8:
case TypeKind.I16:
case TypeKind.U16:
case TypeKind.I32:
case TypeKind.U32: {
// case TypeKind.I64:
// case TypeKind.U64: {
let flow = compiler.currentFlow;
arg0 = compiler.compileExpression(operands[0], Type.v128, ConversionKind.IMPLICIT, WrapMode.NONE);
arg1 = compiler.compileExpression(operands[1], Type.v128, ConversionKind.IMPLICIT, WrapMode.NONE);
let tempLocal0 = flow.getTempLocal(Type.v128);
let tempLocal1 = flow.getAndFreeTempLocal(Type.v128, false);
flow.freeTempLocal(tempLocal0);
switch (type.kind) {
case TypeKind.I8: { op = BinaryOp.GtSVecI8x16; break; }
case TypeKind.U8: { op = BinaryOp.GtUVecI8x16; break; }
case TypeKind.I16: { op = BinaryOp.GtSVecI16x8; break; }
case TypeKind.U16: { op = BinaryOp.GtUVecI16x8; break; }
case TypeKind.I32: { op = BinaryOp.GtSVecI32x4; break; }
case TypeKind.U32: { op = BinaryOp.GtUVecI32x4; break; }
// case TypeKind.I64: { op = BinaryOp.GtSVecI64x2; break; }
// case TypeKind.U64: { op = BinaryOp.GtUVecI64x2; break; }
default: { op = BinaryOp.GtSVecI8x16; break; }
}

return module.createSIMDBitselect(
module.createTeeLocal(tempLocal0.index, arg0),
module.createTeeLocal(tempLocal1.index, arg1),
module.createBinary(op,
module.createGetLocal(tempLocal0.index, NativeType.V128),
module.createGetLocal(tempLocal1.index, NativeType.V128)
)
);
}
case TypeKind.F32: { op = BinaryOp.MaxVecF32x4; break; }
case TypeKind.F64: { op = BinaryOp.MaxVecF64x2; break; }
default: {
Expand Down
8 changes: 6 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ export class Module {
var nested1: ExpressionRef,
nested2: ExpressionRef;

switch (_BinaryenExpressionGetId(expr)) {
switch (_BinaryenExpressionGetId(expr)) {
case ExpressionId.Const: {
switch (_BinaryenExpressionGetType(expr)) {
case NativeType.I32: {
Expand All @@ -1196,6 +1196,9 @@ export class Module {
case NativeType.F64: {
return this.createF64(_BinaryenConstGetValueF64(expr));
}
/*case NativeType.V128: {
return this.createV128(_BinaryenConstGetValueV128(expr));
}*/
default: {
throw new Error("concrete type expected");
}
Expand Down Expand Up @@ -1751,7 +1754,8 @@ export function needsExplicitUnreachable(expr: ExpressionRef): bool {
case NativeType.I32:
case NativeType.I64:
case NativeType.F32:
case NativeType.F64: return false;
case NativeType.F64:
case NativeType.V128: return false;
}
switch (_BinaryenExpressionGetId(expr)) {
case ExpressionId.Unreachable:
Expand Down
59 changes: 59 additions & 0 deletions tests/compiler/simd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,65 @@ function test_v128(): void {
) ==
v128(16, 2, 14, 4, 12, 6, 10, 8, 8, 10, 6, 12, 4, 14, 2, 16),
);
/*
assert(
v128.max<u8>(
v128(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),
v128(0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2),
) ==
v128(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2),
);
assert(
v128.min<i8>(
v128(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0),
v128( 0,-2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2),
) ==
v128(-1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2),
);
*/
var t0 = v128(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0);
var t1 = v128(0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2);
assert(
v128.bitselect(
t0,
t1,
i8x16.gt_u(
t0,
t1
)
) ==
v128(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
);
/*assert(
v128.bitselect(
v128(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),
v128(0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2),
i8x16.gt_u(
v128(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),
v128(0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2)
)
) ==
v128(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
);*/

t0 = v128(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0);
t1 = v128( 0,-2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2);
assert(
v128.bitselect(t0, t1, i8x16.lt_s(t0, t1))
==
v128(-1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2)
);
/*assert(
v128.bitselect(
v128(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0),
v128( 0,-2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2),
i8x16.lt_s(
v128(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0),
v128( 0,-2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2, 0, -2)
)
) ==
v128(-1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2)
);*/
// generic operations are tested by the aliases below already

// FIXME: node/nightly currently fails to validate this. works in node/v8-canary.
Expand Down
Loading