Skip to content
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

Add prototype SIMD rounding instructions #2895

Merged
merged 1 commit into from
Jun 5, 2020
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
8 changes: 8 additions & 0 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@
("f32x4.max", "makeBinary(s, BinaryOp::MaxVecF32x4)"),
("f32x4.pmin", "makeBinary(s, BinaryOp::PMinVecF32x4)"),
("f32x4.pmax", "makeBinary(s, BinaryOp::PMaxVecF32x4)"),
("f32x4.ceil", "makeUnary(s, UnaryOp::CeilVecF32x4)"),
("f32x4.floor", "makeUnary(s, UnaryOp::FloorVecF32x4)"),
("f32x4.trunc", "makeUnary(s, UnaryOp::TruncVecF32x4)"),
("f32x4.nearest", "makeUnary(s, UnaryOp::NearestVecF32x4)"),
("f64x2.abs", "makeUnary(s, UnaryOp::AbsVecF64x2)"),
("f64x2.neg", "makeUnary(s, UnaryOp::NegVecF64x2)"),
("f64x2.sqrt", "makeUnary(s, UnaryOp::SqrtVecF64x2)"),
Expand All @@ -450,6 +454,10 @@
("f64x2.max", "makeBinary(s, BinaryOp::MaxVecF64x2)"),
("f64x2.pmin", "makeBinary(s, BinaryOp::PMinVecF64x2)"),
("f64x2.pmax", "makeBinary(s, BinaryOp::PMaxVecF64x2)"),
("f64x2.ceil", "makeUnary(s, UnaryOp::CeilVecF64x2)"),
("f64x2.floor", "makeUnary(s, UnaryOp::FloorVecF64x2)"),
("f64x2.trunc", "makeUnary(s, UnaryOp::TruncVecF64x2)"),
("f64x2.nearest", "makeUnary(s, UnaryOp::NearestVecF64x2)"),
("i32x4.trunc_sat_f32x4_s", "makeUnary(s, UnaryOp::TruncSatSVecF32x4ToVecI32x4)"),
("i32x4.trunc_sat_f32x4_u", "makeUnary(s, UnaryOp::TruncSatUVecF32x4ToVecI32x4)"),
("i64x2.trunc_sat_f64x2_s", "makeUnary(s, UnaryOp::TruncSatSVecF64x2ToVecI64x2)"),
Expand Down
8 changes: 8 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ BinaryenOp BinaryenDivVecF32x4(void) { return DivVecF32x4; }
BinaryenOp BinaryenMinVecF32x4(void) { return MinVecF32x4; }
BinaryenOp BinaryenMaxVecF32x4(void) { return MaxVecF32x4; }
BinaryenOp BinaryenPMinVecF32x4(void) { return PMinVecF32x4; }
BinaryenOp BinaryenCeilVecF32x4(void) { return CeilVecF32x4; }
BinaryenOp BinaryenFloorVecF32x4(void) { return FloorVecF32x4; }
BinaryenOp BinaryenTruncVecF32x4(void) { return TruncVecF32x4; }
BinaryenOp BinaryenNearestVecF32x4(void) { return NearestVecF32x4; }
BinaryenOp BinaryenPMaxVecF32x4(void) { return PMaxVecF32x4; }
BinaryenOp BinaryenAbsVecF64x2(void) { return AbsVecF64x2; }
BinaryenOp BinaryenNegVecF64x2(void) { return NegVecF64x2; }
Expand All @@ -696,6 +700,10 @@ BinaryenOp BinaryenMinVecF64x2(void) { return MinVecF64x2; }
BinaryenOp BinaryenMaxVecF64x2(void) { return MaxVecF64x2; }
BinaryenOp BinaryenPMinVecF64x2(void) { return PMinVecF64x2; }
BinaryenOp BinaryenPMaxVecF64x2(void) { return PMaxVecF64x2; }
BinaryenOp BinaryenCeilVecF64x2(void) { return CeilVecF64x2; }
BinaryenOp BinaryenFloorVecF64x2(void) { return FloorVecF64x2; }
BinaryenOp BinaryenTruncVecF64x2(void) { return TruncVecF64x2; }
BinaryenOp BinaryenNearestVecF64x2(void) { return NearestVecF64x2; }
BinaryenOp BinaryenTruncSatSVecF32x4ToVecI32x4(void) {
return TruncSatSVecF32x4ToVecI32x4;
}
Expand Down
8 changes: 8 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@ BINARYEN_API BinaryenOp BinaryenMinVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenMaxVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenPMinVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenPMaxVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenCeilVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenFloorVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenTruncVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenNearestVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenAbsVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenNegVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenSqrtVecF64x2(void);
Expand All @@ -556,6 +560,10 @@ BINARYEN_API BinaryenOp BinaryenMinVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenMaxVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenPMinVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenPMaxVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenCeilVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenFloorVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenTruncVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenNearestVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenTruncSatSVecF32x4ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenTruncSatUVecF32x4ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenTruncSatSVecF64x2ToVecI64x2(void);
Expand Down
58 changes: 46 additions & 12 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,21 @@ switch (op[0]) {
}
}
case 'c': {
switch (op[20]) {
case 's':
if (strcmp(op, "f32x4.convert_i32x4_s") == 0) { return makeUnary(s, UnaryOp::ConvertSVecI32x4ToVecF32x4); }
goto parse_error;
case 'u':
if (strcmp(op, "f32x4.convert_i32x4_u") == 0) { return makeUnary(s, UnaryOp::ConvertUVecI32x4ToVecF32x4); }
switch (op[7]) {
case 'e':
if (strcmp(op, "f32x4.ceil") == 0) { return makeUnary(s, UnaryOp::CeilVecF32x4); }
goto parse_error;
case 'o': {
switch (op[20]) {
case 's':
if (strcmp(op, "f32x4.convert_i32x4_s") == 0) { return makeUnary(s, UnaryOp::ConvertSVecI32x4ToVecF32x4); }
goto parse_error;
case 'u':
if (strcmp(op, "f32x4.convert_i32x4_u") == 0) { return makeUnary(s, UnaryOp::ConvertUVecI32x4ToVecF32x4); }
goto parse_error;
default: goto parse_error;
}
}
default: goto parse_error;
}
}
Expand All @@ -291,6 +299,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'f':
if (strcmp(op, "f32x4.floor") == 0) { return makeUnary(s, UnaryOp::FloorVecF32x4); }
goto parse_error;
case 'g': {
switch (op[7]) {
case 'e':
Expand Down Expand Up @@ -332,6 +343,9 @@ switch (op[0]) {
case '\0':
if (strcmp(op, "f32x4.ne") == 0) { return makeBinary(s, BinaryOp::NeVecF32x4); }
goto parse_error;
case 'a':
if (strcmp(op, "f32x4.nearest") == 0) { return makeUnary(s, UnaryOp::NearestVecF32x4); }
goto parse_error;
case 'g':
if (strcmp(op, "f32x4.neg") == 0) { return makeUnary(s, UnaryOp::NegVecF32x4); }
goto parse_error;
Expand Down Expand Up @@ -377,6 +391,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 't':
if (strcmp(op, "f32x4.trunc") == 0) { return makeUnary(s, UnaryOp::TruncVecF32x4); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down Expand Up @@ -559,13 +576,21 @@ switch (op[0]) {
}
}
case 'c': {
switch (op[20]) {
case 's':
if (strcmp(op, "f64x2.convert_i64x2_s") == 0) { return makeUnary(s, UnaryOp::ConvertSVecI64x2ToVecF64x2); }
goto parse_error;
case 'u':
if (strcmp(op, "f64x2.convert_i64x2_u") == 0) { return makeUnary(s, UnaryOp::ConvertUVecI64x2ToVecF64x2); }
switch (op[7]) {
case 'e':
if (strcmp(op, "f64x2.ceil") == 0) { return makeUnary(s, UnaryOp::CeilVecF64x2); }
goto parse_error;
case 'o': {
switch (op[20]) {
case 's':
if (strcmp(op, "f64x2.convert_i64x2_s") == 0) { return makeUnary(s, UnaryOp::ConvertSVecI64x2ToVecF64x2); }
goto parse_error;
case 'u':
if (strcmp(op, "f64x2.convert_i64x2_u") == 0) { return makeUnary(s, UnaryOp::ConvertUVecI64x2ToVecF64x2); }
goto parse_error;
default: goto parse_error;
}
}
default: goto parse_error;
}
}
Expand All @@ -583,6 +608,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'f':
if (strcmp(op, "f64x2.floor") == 0) { return makeUnary(s, UnaryOp::FloorVecF64x2); }
goto parse_error;
case 'g': {
switch (op[7]) {
case 'e':
Expand Down Expand Up @@ -624,6 +652,9 @@ switch (op[0]) {
case '\0':
if (strcmp(op, "f64x2.ne") == 0) { return makeBinary(s, BinaryOp::NeVecF64x2); }
goto parse_error;
case 'a':
if (strcmp(op, "f64x2.nearest") == 0) { return makeUnary(s, UnaryOp::NearestVecF64x2); }
goto parse_error;
case 'g':
if (strcmp(op, "f64x2.neg") == 0) { return makeUnary(s, UnaryOp::NegVecF64x2); }
goto parse_error;
Expand Down Expand Up @@ -669,6 +700,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 't':
if (strcmp(op, "f64x2.trunc") == 0) { return makeUnary(s, UnaryOp::TruncVecF64x2); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/ir/cost.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,17 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> {
case AbsVecF32x4:
case NegVecF32x4:
case SqrtVecF32x4:
case CeilVecF32x4:
case FloorVecF32x4:
case TruncVecF32x4:
case NearestVecF32x4:
case AbsVecF64x2:
case NegVecF64x2:
case SqrtVecF64x2:
case CeilVecF64x2:
case FloorVecF64x2:
case TruncVecF64x2:
case NearestVecF64x2:
case TruncSatSVecF32x4ToVecI32x4:
case TruncSatUVecF32x4ToVecI32x4:
case TruncSatSVecF64x2ToVecI64x2:
Expand Down
32 changes: 32 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ function initializeConstants() {
'MaxVecF32x4',
'PMinVecF32x4',
'PMaxVecF32x4',
'CeilVecF32x4',
'FloorVecF32x4',
'TruncVecF32x4',
'NearestVecF32x4',
'AbsVecF64x2',
'NegVecF64x2',
'SqrtVecF64x2',
Expand All @@ -436,6 +440,10 @@ function initializeConstants() {
'MaxVecF64x2',
'PMinVecF64x2',
'PMaxVecF64x2',
'CeilVecF64x2',
'FloorVecF64x2',
'TruncVecF64x2',
'NearestVecF64x2',
'TruncSatSVecF32x4ToVecI32x4',
'TruncSatUVecF32x4ToVecI32x4',
'TruncSatSVecF64x2ToVecI64x2',
Expand Down Expand Up @@ -1918,6 +1926,18 @@ function wrapModule(module, self) {
'pmax': function(left, right) {
return Module['_BinaryenBinary'](module, Module['PMaxVecF32x4'], left, right);
},
'ceil': function(value) {
return Module['_BinaryenUnary'](module, Module['CeilVecF32x4'], value);
},
'floor': function(value) {
return Module['_BinaryenUnary'](module, Module['FloorVecF32x4'], value);
},
'trunc': function(value) {
return Module['_BinaryenUnary'](module, Module['TruncVecF32x4'], value);
},
'nearest': function(value) {
return Module['_BinaryenUnary'](module, Module['NearestVecF32x4'], value);
},
'convert_i32x4_s': function(value) {
return Module['_BinaryenUnary'](module, Module['ConvertSVecI32x4ToVecF32x4'], value);
},
Expand Down Expand Up @@ -1993,6 +2013,18 @@ function wrapModule(module, self) {
'pmax': function(left, right) {
return Module['_BinaryenBinary'](module, Module['PMaxVecF64x2'], left, right);
},
'ceil': function(value) {
return Module['_BinaryenUnary'](module, Module['CeilVecF64x2'], value);
},
'floor': function(value) {
return Module['_BinaryenUnary'](module, Module['FloorVecF64x2'], value);
},
'trunc': function(value) {
return Module['_BinaryenUnary'](module, Module['TruncVecF64x2'], value);
},
'nearest': function(value) {
return Module['_BinaryenUnary'](module, Module['NearestVecF64x2'], value);
},
'convert_i64x2_s': function(value) {
return Module['_BinaryenUnary'](module, Module['ConvertSVecI64x2ToVecF64x2'], value);
},
Expand Down
8 changes: 8 additions & 0 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ class Literal {
Literal maxF32x4(const Literal& other) const;
Literal pminF32x4(const Literal& other) const;
Literal pmaxF32x4(const Literal& other) const;
Literal ceilF32x4() const;
Literal floorF32x4() const;
Literal truncF32x4() const;
Literal nearestF32x4() const;
Literal absF64x2() const;
Literal negF64x2() const;
Literal sqrtF64x2() const;
Expand All @@ -440,6 +444,10 @@ class Literal {
Literal maxF64x2(const Literal& other) const;
Literal pminF64x2(const Literal& other) const;
Literal pmaxF64x2(const Literal& other) const;
Literal ceilF64x2() const;
Literal floorF64x2() const;
Literal truncF64x2() const;
Literal nearestF64x2() const;
Literal truncSatToSI32x4() const;
Literal truncSatToUI32x4() const;
Literal truncSatToSI64x2() const;
Expand Down
24 changes: 24 additions & 0 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,18 @@ struct PrintExpressionContents
case SqrtVecF32x4:
o << "f32x4.sqrt";
break;
case CeilVecF32x4:
o << "f32x4.ceil";
break;
case FloorVecF32x4:
o << "f32x4.floor";
break;
case TruncVecF32x4:
o << "f32x4.trunc";
break;
case NearestVecF32x4:
o << "f32x4.nearest";
break;
case AbsVecF64x2:
o << "f64x2.abs";
break;
Expand All @@ -789,6 +801,18 @@ struct PrintExpressionContents
case SqrtVecF64x2:
o << "f64x2.sqrt";
break;
case CeilVecF64x2:
o << "f64x2.ceil";
break;
case FloorVecF64x2:
o << "f64x2.floor";
break;
case TruncVecF64x2:
o << "f64x2.trunc";
break;
case NearestVecF64x2:
o << "f64x2.nearest";
break;
case TruncSatSVecF32x4ToVecI32x4:
o << "i32x4.trunc_sat_f32x4_s";
break;
Expand Down
9 changes: 9 additions & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,15 @@ enum ASTNodes {
F32x4PMin = 0xea,
F32x4PMax = 0xeb,

F32x4Ceil = 0xd8,
F32x4Floor = 0xd9,
F32x4Trunc = 0xda,
F32x4Nearest = 0xdb,
F64x2Ceil = 0xdc,
F64x2Floor = 0xdd,
F64x2Trunc = 0xde,
F64x2Nearest = 0xdf,

F64x2Abs = 0xec,
F64x2Neg = 0xed,
F64x2Sqrt = 0xef,
Expand Down
16 changes: 16 additions & 0 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,28 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
return value.negF32x4();
case SqrtVecF32x4:
return value.sqrtF32x4();
case CeilVecF32x4:
return value.ceilF32x4();
case FloorVecF32x4:
return value.floorF32x4();
case TruncVecF32x4:
return value.truncF32x4();
case NearestVecF32x4:
return value.nearestF32x4();
case AbsVecF64x2:
return value.absF64x2();
case NegVecF64x2:
return value.negF64x2();
case SqrtVecF64x2:
return value.sqrtF64x2();
case CeilVecF64x2:
return value.ceilF64x2();
case FloorVecF64x2:
return value.floorF64x2();
case TruncVecF64x2:
return value.truncF64x2();
case NearestVecF64x2:
return value.nearestF64x2();
case TruncSatSVecF32x4ToVecI32x4:
return value.truncSatToSI32x4();
case TruncSatUVecF32x4ToVecI32x4:
Expand Down
8 changes: 8 additions & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,17 @@ enum UnaryOp {
AbsVecF32x4,
NegVecF32x4,
SqrtVecF32x4,
CeilVecF32x4,
FloorVecF32x4,
TruncVecF32x4,
NearestVecF32x4,
AbsVecF64x2,
NegVecF64x2,
SqrtVecF64x2,
CeilVecF64x2,
FloorVecF64x2,
TruncVecF64x2,
NearestVecF64x2,

// SIMD conversions
TruncSatSVecF32x4ToVecI32x4,
Expand Down
Loading