Skip to content

Commit 27dbce1

Browse files
authored
[FP16] Implement f32x4.promote_low_f16x8. (#8578)
Specified at https://github.com/WebAssembly/half-precision/blob/main/proposals/half-precision/Overview.md Note: The instruction name `promote_low_f16x8` is different than the overview. I intend to update the spec overview to fix the name to match the other promote instruction.
1 parent cfa8abd commit 27dbce1

File tree

19 files changed

+96
-10
lines changed

19 files changed

+96
-10
lines changed

scripts/gen-s-parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@
549549
("i16x8.trunc_sat_f16x8_u", "makeUnary(UnaryOp::TruncSatUVecF16x8ToVecI16x8)"),
550550
("f16x8.convert_i16x8_s", "makeUnary(UnaryOp::ConvertSVecI16x8ToVecF16x8)"),
551551
("f16x8.convert_i16x8_u", "makeUnary(UnaryOp::ConvertUVecI16x8ToVecF16x8)"),
552+
("f32x4.promote_low_f16x8", "makeUnary(UnaryOp::PromoteLowVecF16x8ToVecF32x4)"),
552553
("f16x8.madd", "makeSIMDTernary(SIMDTernaryOp::MaddVecF16x8)"),
553554
("f16x8.nmadd", "makeSIMDTernary(SIMDTernaryOp::NmaddVecF16x8)"),
554555

src/binaryen-c.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,9 @@ BinaryenOp BinaryenDemoteZeroVecF64x2ToVecF32x4(void) {
10211021
BinaryenOp BinaryenPromoteLowVecF32x4ToVecF64x2(void) {
10221022
return PromoteLowVecF32x4ToVecF64x2;
10231023
}
1024+
BinaryenOp BinaryenPromoteLowVecF16x8ToVecF32x4(void) {
1025+
return PromoteLowVecF16x8ToVecF32x4;
1026+
}
10241027
BinaryenOp BinaryenRelaxedTruncSVecF32x4ToVecI32x4(void) {
10251028
return RelaxedTruncSVecF32x4ToVecI32x4;
10261029
}

src/binaryen-c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ BINARYEN_API BinaryenOp BinaryenTruncSatZeroSVecF64x2ToVecI32x4(void);
684684
BINARYEN_API BinaryenOp BinaryenTruncSatZeroUVecF64x2ToVecI32x4(void);
685685
BINARYEN_API BinaryenOp BinaryenDemoteZeroVecF64x2ToVecF32x4(void);
686686
BINARYEN_API BinaryenOp BinaryenPromoteLowVecF32x4ToVecF64x2(void);
687+
BINARYEN_API BinaryenOp BinaryenPromoteLowVecF16x8ToVecF32x4(void);
687688
BINARYEN_API BinaryenOp BinaryenRelaxedTruncSVecF32x4ToVecI32x4(void);
688689
BINARYEN_API BinaryenOp BinaryenRelaxedTruncUVecF32x4ToVecI32x4(void);
689690
BINARYEN_API BinaryenOp BinaryenRelaxedTruncZeroSVecF64x2ToVecI32x4(void);

src/gen-s-parser.inc

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,16 +1127,27 @@ switch (buf[0]) {
11271127
}
11281128
}
11291129
case 'p': {
1130-
switch (buf[8]) {
1131-
case 'a':
1132-
if (op == "f32x4.pmax"sv) {
1133-
CHECK_ERR(makeBinary(ctx, pos, annotations, BinaryOp::PMaxVecF32x4));
1134-
return Ok{};
1130+
switch (buf[7]) {
1131+
case 'm': {
1132+
switch (buf[8]) {
1133+
case 'a':
1134+
if (op == "f32x4.pmax"sv) {
1135+
CHECK_ERR(makeBinary(ctx, pos, annotations, BinaryOp::PMaxVecF32x4));
1136+
return Ok{};
1137+
}
1138+
goto parse_error;
1139+
case 'i':
1140+
if (op == "f32x4.pmin"sv) {
1141+
CHECK_ERR(makeBinary(ctx, pos, annotations, BinaryOp::PMinVecF32x4));
1142+
return Ok{};
1143+
}
1144+
goto parse_error;
1145+
default: goto parse_error;
11351146
}
1136-
goto parse_error;
1137-
case 'i':
1138-
if (op == "f32x4.pmin"sv) {
1139-
CHECK_ERR(makeBinary(ctx, pos, annotations, BinaryOp::PMinVecF32x4));
1147+
}
1148+
case 'r':
1149+
if (op == "f32x4.promote_low_f16x8"sv) {
1150+
CHECK_ERR(makeUnary(ctx, pos, annotations, UnaryOp::PromoteLowVecF16x8ToVecF32x4));
11401151
return Ok{};
11411152
}
11421153
goto parse_error;

src/ir/child-typer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
447447
case TruncSatUVecF16x8ToVecI16x8:
448448
case ConvertSVecI16x8ToVecF16x8:
449449
case ConvertUVecI16x8ToVecF16x8:
450+
case PromoteLowVecF16x8ToVecF32x4:
450451
case AnyTrueVec128:
451452
case AllTrueVecI8x16:
452453
case AllTrueVecI16x8:

src/ir/cost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
284284
case TruncSatUVecF16x8ToVecI16x8:
285285
case ConvertSVecI16x8ToVecF16x8:
286286
case ConvertUVecI16x8ToVecF16x8:
287+
case PromoteLowVecF16x8ToVecF32x4:
287288
ret = 1;
288289
break;
289290
case InvalidUnary:

src/literal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ class Literal {
723723
Literal truncSatZeroUToI32x4() const;
724724
Literal demoteZeroToF32x4() const;
725725
Literal promoteLowToF64x2() const;
726+
Literal promoteLowF16x8ToF32x4() const;
726727
Literal truncSatToSI16x8() const;
727728
Literal truncSatToUI16x8() const;
728729
Literal convertSToF16x8() const;

src/passes/Print.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,9 @@ struct PrintExpressionContents
14011401
case ConvertUVecI16x8ToVecF16x8:
14021402
o << "f16x8.convert_i16x8_u";
14031403
break;
1404+
case PromoteLowVecF16x8ToVecF32x4:
1405+
o << "f32x4.promote_low_f16x8";
1406+
break;
14041407
case InvalidUnary:
14051408
WASM_UNREACHABLE("unvalid unary operator");
14061409
}

src/tools/fuzzing/fuzzing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4526,7 +4526,8 @@ Expression* TranslateToFuzzReader::makeUnary(Type type) {
45264526
TruncSatSVecF16x8ToVecI16x8,
45274527
TruncSatUVecF16x8ToVecI16x8,
45284528
ConvertSVecI16x8ToVecF16x8,
4529-
ConvertUVecI16x8ToVecF16x8)),
4529+
ConvertUVecI16x8ToVecF16x8,
4530+
PromoteLowVecF16x8ToVecF32x4)),
45304531
make(Type::v128)});
45314532
}
45324533
WASM_UNREACHABLE("invalid value");

src/wasm-binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ enum ASTNodes {
11261126
I16x8TruncSatF16x8U = 0x146,
11271127
F16x8ConvertI16x8S = 0x147,
11281128
F16x8ConvertI16x8U = 0x148,
1129+
F32x4PromoteLowF16x8 = 0x14b,
11291130

11301131
// bulk memory opcodes
11311132

0 commit comments

Comments
 (0)