Skip to content

SIMD {i8x16,i16x8}.avgr_u instructions #2539

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 1 commit into from
Dec 18, 2019
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
2 changes: 2 additions & 0 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
("i8x16.min_u", "makeBinary(s, BinaryOp::MinUVecI8x16)"),
("i8x16.max_s", "makeBinary(s, BinaryOp::MaxSVecI8x16)"),
("i8x16.max_u", "makeBinary(s, BinaryOp::MaxUVecI8x16)"),
("i8x16.avgr_u", "makeBinary(s, BinaryOp::AvgrUVecI8x16)"),
("i16x8.neg", "makeUnary(s, UnaryOp::NegVecI16x8)"),
("i16x8.any_true", "makeUnary(s, UnaryOp::AnyTrueVecI16x8)"),
("i16x8.all_true", "makeUnary(s, UnaryOp::AllTrueVecI16x8)"),
Expand All @@ -392,6 +393,7 @@
("i16x8.min_u", "makeBinary(s, BinaryOp::MinUVecI16x8)"),
("i16x8.max_s", "makeBinary(s, BinaryOp::MaxSVecI16x8)"),
("i16x8.max_u", "makeBinary(s, BinaryOp::MaxUVecI16x8)"),
("i16x8.avgr_u", "makeBinary(s, BinaryOp::AvgrUVecI16x8)"),
("i32x4.neg", "makeUnary(s, UnaryOp::NegVecI32x4)"),
("i32x4.any_true", "makeUnary(s, UnaryOp::AnyTrueVecI32x4)"),
("i32x4.all_true", "makeUnary(s, UnaryOp::AllTrueVecI32x4)"),
Expand Down
2 changes: 2 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ BinaryenOp BinaryenMinSVecI8x16(void) { return MinSVecI8x16; }
BinaryenOp BinaryenMinUVecI8x16(void) { return MinUVecI8x16; }
BinaryenOp BinaryenMaxSVecI8x16(void) { return MaxSVecI8x16; }
BinaryenOp BinaryenMaxUVecI8x16(void) { return MaxUVecI8x16; }
BinaryenOp BinaryenAvgrUVecI8x16(void) { return AvgrUVecI8x16; }
BinaryenOp BinaryenNegVecI16x8(void) { return NegVecI16x8; }
BinaryenOp BinaryenAnyTrueVecI16x8(void) { return AnyTrueVecI16x8; }
BinaryenOp BinaryenAllTrueVecI16x8(void) { return AllTrueVecI16x8; }
Expand All @@ -797,6 +798,7 @@ BinaryenOp BinaryenMinSVecI16x8(void) { return MinSVecI16x8; }
BinaryenOp BinaryenMinUVecI16x8(void) { return MinUVecI16x8; }
BinaryenOp BinaryenMaxSVecI16x8(void) { return MaxSVecI16x8; }
BinaryenOp BinaryenMaxUVecI16x8(void) { return MaxUVecI16x8; }
BinaryenOp BinaryenAvgrUVecI16x8(void) { return AvgrUVecI16x8; }
BinaryenOp BinaryenNegVecI32x4(void) { return NegVecI32x4; }
BinaryenOp BinaryenAnyTrueVecI32x4(void) { return AnyTrueVecI32x4; }
BinaryenOp BinaryenAllTrueVecI32x4(void) { return AllTrueVecI32x4; }
Expand Down
2 changes: 2 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ BINARYEN_API BinaryenOp BinaryenMinSVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenMinUVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenMaxSVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenMaxUVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenAvgrUVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenNegVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenAnyTrueVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenAllTrueVecI16x8(void);
Expand All @@ -491,6 +492,7 @@ BINARYEN_API BinaryenOp BinaryenMinSVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenMinUVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenMaxSVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenMaxUVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenAvgrUVecI16x8(void);
BINARYEN_API BinaryenOp BinaryenNegVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenAnyTrueVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenAllTrueVecI32x4(void);
Expand Down
6 changes: 6 additions & 0 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ switch (op[0]) {
case 'n':
if (strcmp(op, "i16x8.any_true") == 0) { return makeUnary(s, UnaryOp::AnyTrueVecI16x8); }
goto parse_error;
case 'v':
if (strcmp(op, "i16x8.avgr_u") == 0) { return makeBinary(s, BinaryOp::AvgrUVecI16x8); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down Expand Up @@ -2241,6 +2244,9 @@ switch (op[0]) {
case 'n':
if (strcmp(op, "i8x16.any_true") == 0) { return makeUnary(s, UnaryOp::AnyTrueVecI8x16); }
goto parse_error;
case 'v':
if (strcmp(op, "i8x16.avgr_u") == 0) { return makeBinary(s, BinaryOp::AvgrUVecI8x16); }
goto parse_error;
default: goto parse_error;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/ir/cost.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> {
case MaxUVecI8x16:
ret = 1;
break;
case AvgrUVecI8x16:
ret = 1;
break;
case AddVecI16x8:
ret = 1;
break;
Expand Down Expand Up @@ -627,6 +630,9 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> {
case MaxUVecI16x8:
ret = 1;
break;
case AvgrUVecI16x8:
ret = 1;
break;
case AddVecI32x4:
ret = 1;
break;
Expand Down
8 changes: 8 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ Module['MinSVecI8x16'] = Module['_BinaryenMinSVecI8x16']();
Module['MinUVecI8x16'] = Module['_BinaryenMinUVecI8x16']();
Module['MaxSVecI8x16'] = Module['_BinaryenMaxSVecI8x16']();
Module['MaxUVecI8x16'] = Module['_BinaryenMaxUVecI8x16']();
Module['AvgrUVecI8x16'] = Module['_BinaryenAvgrUVecI8x16']();
Module['NegVecI16x8'] = Module['_BinaryenNegVecI16x8']();
Module['AnyTrueVecI16x8'] = Module['_BinaryenAnyTrueVecI16x8']();
Module['AllTrueVecI16x8'] = Module['_BinaryenAllTrueVecI16x8']();
Expand All @@ -376,6 +377,7 @@ Module['MinSVecI16x8'] = Module['_BinaryenMinSVecI16x8']();
Module['MinUVecI16x8'] = Module['_BinaryenMinUVecI16x8']();
Module['MaxSVecI16x8'] = Module['_BinaryenMaxSVecI16x8']();
Module['MaxUVecI16x8'] = Module['_BinaryenMaxUVecI16x8']();
Module['AvgrUVecI16x8'] = Module['_BinaryenAvgrUVecI16x8']();
Module['DotSVecI16x8ToVecI32x4'] = Module['_BinaryenDotSVecI16x8ToVecI32x4']();
Module['NegVecI32x4'] = Module['_BinaryenNegVecI32x4']();
Module['AnyTrueVecI32x4'] = Module['_BinaryenAnyTrueVecI32x4']();
Expand Down Expand Up @@ -1492,6 +1494,9 @@ function wrapModule(module, self) {
'max_u': function(left, right) {
return Module['_BinaryenBinary'](module, Module['MaxUVecI8x16'], left, right);
},
'avgr_u': function(left, right) {
return Module['_BinaryenBinary'](module, Module['AvgrUVecI8x16'], left, right);
},
'narrow_i16x8_s': function(left, right) {
return Module['_BinaryenBinary'](module, Module['NarrowSVecI16x8ToVecI8x16'], left, right);
},
Expand Down Expand Up @@ -1594,6 +1599,9 @@ function wrapModule(module, self) {
'max_u': function(left, right) {
return Module['_BinaryenBinary'](module, Module['MaxUVecI16x8'], left, right);
},
'avgr_u': function(left, right) {
return Module['_BinaryenBinary'](module, Module['AvgrUVecI16x8'], left, right);
},
'narrow_i32x4_s': function(left, right) {
return Module['_BinaryenBinary'](module, Module['NarrowSVecI32x4ToVecI16x8'], left, right);
},
Expand Down
3 changes: 3 additions & 0 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class Literal {
Literal minUI8x16(const Literal& other) const;
Literal maxSI8x16(const Literal& other) const;
Literal maxUI8x16(const Literal& other) const;
Literal avgrUI8x16(const Literal& other) const;
Literal negI16x8() const;
Literal anyTrueI16x8() const;
Literal allTrueI16x8() const;
Expand All @@ -351,6 +352,7 @@ class Literal {
Literal minUI16x8(const Literal& other) const;
Literal maxSI16x8(const Literal& other) const;
Literal maxUI16x8(const Literal& other) const;
Literal avgrUI16x8(const Literal& other) const;
Literal negI32x4() const;
Literal anyTrueI32x4() const;
Literal allTrueI32x4() const;
Expand Down Expand Up @@ -426,6 +428,7 @@ class Literal {
Literal maxInt(const Literal& other) const;
Literal minUInt(const Literal& other) const;
Literal maxUInt(const Literal& other) const;
Literal avgrUInt(const Literal& other) const;
};

} // namespace wasm
Expand Down
6 changes: 6 additions & 0 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,9 @@ struct PrintExpressionContents
case MaxUVecI8x16:
o << "i8x16.max_u";
break;
case AvgrUVecI8x16:
o << "i8x16.avgr_u";
break;
case AddVecI16x8:
o << "i16x8.add";
break;
Expand Down Expand Up @@ -1237,6 +1240,9 @@ struct PrintExpressionContents
case MaxUVecI16x8:
o << "i16x8.max_u";
break;
case AvgrUVecI16x8:
o << "i16x8.avgr_u";
break;
case AddVecI32x4:
o << "i32x4.add";
break;
Expand Down
4 changes: 3 additions & 1 deletion src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ enum ASTNodes {
I8x16MinU = 0x5f,
I8x16MaxS = 0x60,
I8x16MaxU = 0x61,
I8x16AvgrU = 0xd9,
I16x8Neg = 0x62,
I16x8AnyTrue = 0x63,
I16x8AllTrue = 0x64,
Expand All @@ -782,6 +783,7 @@ enum ASTNodes {
I16x8MinU = 0x70,
I16x8MaxS = 0x71,
I16x8MaxU = 0x72,
I16x8AvgrU = 0xda,
I32x4Neg = 0x73,
I32x4AnyTrue = 0x74,
I32x4AllTrue = 0x75,
Expand All @@ -795,7 +797,7 @@ enum ASTNodes {
I32x4MinU = 0x81,
I32x4MaxS = 0x82,
I32x4MaxU = 0x83,
I32x4DotSVecI16x8 = 0xd9,
I32x4DotSVecI16x8 = 0xdb,
I64x2Neg = 0x84,
I64x2AnyTrue = 0x85,
I64x2AllTrue = 0x86,
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,8 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
return left.maxSI8x16(right);
case MaxUVecI8x16:
return left.maxUI8x16(right);
case AvgrUVecI8x16:
return left.avgrUI8x16(right);
case AddVecI16x8:
return left.addI16x8(right);
case AddSatSVecI16x8:
Expand All @@ -787,6 +789,8 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
return left.maxSI16x8(right);
case MaxUVecI16x8:
return left.maxUI16x8(right);
case AvgrUVecI16x8:
return left.avgrUI16x8(right);
case AddVecI32x4:
return left.addI32x4(right);
case SubVecI32x4:
Expand Down
2 changes: 2 additions & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ enum BinaryOp {
MinUVecI8x16,
MaxSVecI8x16,
MaxUVecI8x16,
AvgrUVecI8x16,
AddVecI16x8,
AddSatSVecI16x8,
AddSatUVecI16x8,
Expand All @@ -376,6 +377,7 @@ enum BinaryOp {
MinUVecI16x8,
MaxSVecI16x8,
MaxUVecI16x8,
AvgrUVecI16x8,
AddVecI32x4,
SubVecI32x4,
MulVecI32x4,
Expand Down
10 changes: 10 additions & 0 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,10 @@ Literal Literal::maxUInt(const Literal& other) const {
return uint32_t(geti32()) > uint32_t(other.geti32()) ? *this : other;
}

Literal Literal::avgrUInt(const Literal& other) const {
return Literal((geti32() + other.geti32() + 1) / 2);
}

Literal Literal::and_(const Literal& other) const {
switch (type) {
case Type::i32:
Expand Down Expand Up @@ -1729,6 +1733,9 @@ Literal Literal::maxSI8x16(const Literal& other) const {
Literal Literal::maxUI8x16(const Literal& other) const {
return binary<16, &Literal::getLanesUI8x16, &Literal::maxInt>(*this, other);
}
Literal Literal::avgrUI8x16(const Literal& other) const {
return binary<16, &Literal::getLanesUI8x16, &Literal::avgrUInt>(*this, other);
}
Literal Literal::addI16x8(const Literal& other) const {
return binary<8, &Literal::getLanesUI16x8, &Literal::add>(*this, other);
}
Expand Down Expand Up @@ -1766,6 +1773,9 @@ Literal Literal::maxSI16x8(const Literal& other) const {
Literal Literal::maxUI16x8(const Literal& other) const {
return binary<8, &Literal::getLanesUI16x8, &Literal::maxInt>(*this, other);
}
Literal Literal::avgrUI16x8(const Literal& other) const {
return binary<8, &Literal::getLanesUI16x8, &Literal::avgrUInt>(*this, other);
}
Literal Literal::addI32x4(const Literal& other) const {
return binary<4, &Literal::getLanesI32x4, &Literal::add>(*this, other);
}
Expand Down
8 changes: 8 additions & 0 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,10 @@ bool WasmBinaryBuilder::maybeVisitSIMDBinary(Expression*& out, uint32_t code) {
curr = allocator.alloc<Binary>();
curr->op = MaxUVecI8x16;
break;
case BinaryConsts::I8x16AvgrU:
curr = allocator.alloc<Binary>();
curr->op = AvgrUVecI8x16;
break;
case BinaryConsts::I16x8Add:
curr = allocator.alloc<Binary>();
curr->op = AddVecI16x8;
Expand Down Expand Up @@ -3633,6 +3637,10 @@ bool WasmBinaryBuilder::maybeVisitSIMDBinary(Expression*& out, uint32_t code) {
curr = allocator.alloc<Binary>();
curr->op = MaxUVecI16x8;
break;
case BinaryConsts::I16x8AvgrU:
curr = allocator.alloc<Binary>();
curr->op = AvgrUVecI16x8;
break;
case BinaryConsts::I32x4Add:
curr = allocator.alloc<Binary>();
curr->op = AddVecI32x4;
Expand Down
6 changes: 6 additions & 0 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,9 @@ void BinaryInstWriter::visitBinary(Binary* curr) {
case MaxUVecI8x16:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I8x16MaxU);
break;
case AvgrUVecI8x16:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I8x16AvgrU);
break;
case AddVecI16x8:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I16x8Add);
break;
Expand Down Expand Up @@ -1438,6 +1441,9 @@ void BinaryInstWriter::visitBinary(Binary* curr) {
case MaxUVecI16x8:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I16x8MaxU);
break;
case AvgrUVecI16x8:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I16x8AvgrU);
break;
case AddVecI32x4:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I32x4Add);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ void FunctionValidator::visitBinary(Binary* curr) {
case MinUVecI8x16:
case MaxSVecI8x16:
case MaxUVecI8x16:
case AvgrUVecI8x16:
case AddVecI16x8:
case AddSatSVecI16x8:
case AddSatUVecI16x8:
Expand All @@ -1355,6 +1356,7 @@ void FunctionValidator::visitBinary(Binary* curr) {
case MinUVecI16x8:
case MaxSVecI16x8:
case MaxUVecI16x8:
case AvgrUVecI16x8:
case AddVecI32x4:
case SubVecI32x4:
case MulVecI32x4:
Expand Down
2 changes: 2 additions & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ function test_core() {
module.i8x16.min_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i8x16.max_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i8x16.max_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i8x16.avgr_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i16x8.add(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i16x8.add_saturate_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i16x8.add_saturate_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
Expand All @@ -366,6 +367,7 @@ function test_core() {
module.i16x8.min_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i16x8.max_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i16x8.max_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i16x8.avgr_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i32x4.add(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i32x4.sub(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i32x4.mul(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
Expand Down
Loading