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
1 change: 1 addition & 0 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
("v128.store16_lane", "makeSIMDLoadStoreLane(s, StoreLaneVec16x8)"),
("v128.store32_lane", "makeSIMDLoadStoreLane(s, StoreLaneVec32x4)"),
("v128.store64_lane", "makeSIMDLoadStoreLane(s, StoreLaneVec64x2)"),
("i8x16.popcnt", "makeUnary(s, UnaryOp::PopcntVecI8x16)"),
("i8x16.abs", "makeUnary(s, UnaryOp::AbsVecI8x16)"),
("i8x16.neg", "makeUnary(s, UnaryOp::NegVecI8x16)"),
("i8x16.any_true", "makeUnary(s, UnaryOp::AnyTrueVecI8x16)"),
Expand Down
1 change: 1 addition & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ BINARYEN_API BinaryenOp BinaryenOrVec128(void);
BINARYEN_API BinaryenOp BinaryenXorVec128(void);
BINARYEN_API BinaryenOp BinaryenAndNotVec128(void);
BINARYEN_API BinaryenOp BinaryenBitselectVec128(void);
// TODO: Add i8x16.popcnt to C and JS APIs once merged to proposal
BINARYEN_API BinaryenOp BinaryenAbsVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenNegVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenAnyTrueVecI8x16(void);
Expand Down
3 changes: 3 additions & 0 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2492,6 +2492,9 @@ switch (op[0]) {
default: goto parse_error;
}
}
case 'p':
if (strcmp(op, "i8x16.popcnt") == 0) { return makeUnary(s, UnaryOp::PopcntVecI8x16); }
goto parse_error;
case 'r':
if (strcmp(op, "i8x16.replace_lane") == 0) { return makeSIMDReplace(s, SIMDReplaceOp::ReplaceLaneVecI8x16, 16); }
goto parse_error;
Expand Down
1 change: 1 addition & 0 deletions src/ir/cost.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> {
case AnyTrueVecI8x16:
case AllTrueVecI8x16:
case BitmaskVecI8x16:
case PopcntVecI8x16:
case AbsVecI16x8:
case NegVecI16x8:
case AnyTrueVecI16x8:
Expand Down
1 change: 1 addition & 0 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class Literal {
Literal maxSI8x16(const Literal& other) const;
Literal maxUI8x16(const Literal& other) const;
Literal avgrUI8x16(const Literal& other) const;
Literal popcntI8x16() const;
Literal absI16x8() const;
Literal negI16x8() const;
Literal anyTrueI16x8() const;
Expand Down
3 changes: 3 additions & 0 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ struct PrintExpressionContents
case BitmaskVecI8x16:
o << "i8x16.bitmask";
break;
case PopcntVecI8x16:
o << "i8x16.popcnt";
break;
case AbsVecI16x8:
o << "i16x8.abs";
break;
Expand Down
1 change: 1 addition & 0 deletions src/tools/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,7 @@ class TranslateToFuzzReader {
return buildUnary({SplatVecF64x2, make(Type::f64)});
case 4:
return buildUnary({pick(NotVec128,
// TODO: i8x16.popcnt once merged
NegVecI8x16,
NegVecI16x8,
NegVecI32x4,
Expand Down
2 changes: 2 additions & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ enum ASTNodes {
I8x16MaxU = 0x79,
I8x16AvgrU = 0x7b,

I8x16Popcnt = 0x7c,

I16x8Abs = 0x80,
I16x8Neg = 0x81,
I16x8AnyTrue = 0x82,
Expand Down
2 changes: 2 additions & 0 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
return value.allTrueI8x16();
case BitmaskVecI8x16:
return value.bitmaskI8x16();
case PopcntVecI8x16:
return value.popcntI8x16();
case AbsVecI16x8:
return value.absI16x8();
case NegVecI16x8:
Expand Down
1 change: 1 addition & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ enum UnaryOp {
AnyTrueVecI8x16,
AllTrueVecI8x16,
BitmaskVecI8x16,
PopcntVecI8x16,
AbsVecI16x8,
NegVecI16x8,
AnyTrueVecI16x8,
Expand Down
3 changes: 3 additions & 0 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,9 @@ Literal Literal::absI32x4() const {
Literal Literal::negI8x16() const {
return unary<16, &Literal::getLanesUI8x16, &Literal::neg>(*this);
}
Literal Literal::popcntI8x16() const {
return unary<16, &Literal::getLanesUI8x16, &Literal::popCount>(*this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is each lane signed or unsigned? The LLVM builtin says it's signed though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signedness doesn't really make a difference for popcnt since it doesn't interpret the bits as a number. However, it's important to use the unsigned lane extraction function here because it will zero-extend each lane. If we instead used the signed lane extraction function, it would sign-extend each lane which could change the population counts.

}
Literal Literal::negI16x8() const {
return unary<8, &Literal::getLanesUI16x8, &Literal::neg>(*this);
}
Expand Down
4 changes: 4 additions & 0 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4478,6 +4478,10 @@ bool WasmBinaryBuilder::maybeVisitSIMDUnary(Expression*& out, uint32_t code) {
curr = allocator.alloc<Unary>();
curr->op = NotVec128;
break;
case BinaryConsts::I8x16Popcnt:
curr = allocator.alloc<Unary>();
curr->op = PopcntVecI8x16;
break;
case BinaryConsts::I8x16Abs:
curr = allocator.alloc<Unary>();
curr->op = AbsVecI8x16;
Expand Down
4 changes: 4 additions & 0 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,10 @@ void BinaryInstWriter::visitUnary(Unary* curr) {
o << int8_t(BinaryConsts::SIMDPrefix)
<< U32LEB(BinaryConsts::I8x16Bitmask);
break;
case PopcntVecI8x16:
o << int8_t(BinaryConsts::SIMDPrefix)
<< U32LEB(BinaryConsts::I8x16Popcnt);
break;
case AbsVecI16x8:
o << int8_t(BinaryConsts::SIMDPrefix) << U32LEB(BinaryConsts::I16x8Abs);
break;
Expand Down
1 change: 1 addition & 0 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ void FunctionValidator::visitUnary(Unary* curr) {
curr->value->type, Type(Type::f64), curr, "expected f64 splat value");
break;
case NotVec128:
case PopcntVecI8x16:
case AbsVecI8x16:
case AbsVecI16x8:
case AbsVecI32x4:
Expand Down
1 change: 1 addition & 0 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ void Unary::finalize() {
case AbsVecI8x16:
case AbsVecI16x8:
case AbsVecI32x4:
case PopcntVecI8x16:
case NegVecI8x16:
case NegVecI16x8:
case NegVecI32x4:
Expand Down
16 changes: 8 additions & 8 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,10 @@ void test_core() {
makeBinary(module, BinaryenMaxVecF32x4(), v128),
makeBinary(module, BinaryenPMinVecF32x4(), v128),
makeBinary(module, BinaryenPMaxVecF32x4(), v128),
makeBinary(module, BinaryenCeilVecF32x4(), v128),
makeBinary(module, BinaryenFloorVecF32x4(), v128),
makeBinary(module, BinaryenTruncVecF32x4(), v128),
makeBinary(module, BinaryenNearestVecF32x4(), v128),
makeUnary(module, BinaryenCeilVecF32x4(), v128),
makeUnary(module, BinaryenFloorVecF32x4(), v128),
makeUnary(module, BinaryenTruncVecF32x4(), v128),
makeUnary(module, BinaryenNearestVecF32x4(), v128),
makeBinary(module, BinaryenAddVecF64x2(), v128),
makeBinary(module, BinaryenSubVecF64x2(), v128),
makeBinary(module, BinaryenMulVecF64x2(), v128),
Expand All @@ -592,10 +592,10 @@ void test_core() {
makeBinary(module, BinaryenMaxVecF64x2(), v128),
makeBinary(module, BinaryenPMinVecF64x2(), v128),
makeBinary(module, BinaryenPMaxVecF64x2(), v128),
makeBinary(module, BinaryenCeilVecF64x2(), v128),
makeBinary(module, BinaryenFloorVecF64x2(), v128),
makeBinary(module, BinaryenTruncVecF64x2(), v128),
makeBinary(module, BinaryenNearestVecF64x2(), v128),
makeUnary(module, BinaryenCeilVecF64x2(), v128),
makeUnary(module, BinaryenFloorVecF64x2(), v128),
makeUnary(module, BinaryenTruncVecF64x2(), v128),
makeUnary(module, BinaryenNearestVecF64x2(), v128),
makeBinary(module, BinaryenNarrowSVecI16x8ToVecI8x16(), v128),
makeBinary(module, BinaryenNarrowUVecI16x8ToVecI8x16(), v128),
makeBinary(module, BinaryenNarrowSVecI32x4ToVecI16x8(), v128),
Expand Down
24 changes: 8 additions & 16 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1235,26 +1235,22 @@ BinaryenFeatureAll: 4095
)
)
(drop
(i16x8.lt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f32x4.ceil
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i16x8.lt_u
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f32x4.floor
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i16x8.gt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f32x4.trunc
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i16x8.gt_u
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f32x4.nearest
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
Expand Down Expand Up @@ -1307,26 +1303,22 @@ BinaryenFeatureAll: 4095
)
)
(drop
(i16x8.ge_u
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f64x2.ceil
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f64x2.floor
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.ne
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f64x2.trunc
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.lt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(f64x2.nearest
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
Expand Down
5 changes: 5 additions & 0 deletions test/simd.wast
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@
(local.get $1)
)
)
(func $i8x16.popcnt (param $0 v128) (result v128)
(i8x16.popcnt
(local.get $0)
)
)
(func $i8x16.abs (param $0 v128) (result v128)
(i8x16.abs
(local.get $0)
Expand Down
5 changes: 5 additions & 0 deletions test/simd.wast.from-wast
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@
(local.get $1)
)
)
(func $i8x16.popcnt (param $0 v128) (result v128)
(i8x16.popcnt
(local.get $0)
)
)
(func $i8x16.abs (param $0 v128) (result v128)
(i8x16.abs
(local.get $0)
Expand Down
5 changes: 5 additions & 0 deletions test/simd.wast.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@
(local.get $1)
)
)
(func $i8x16.popcnt (param $0 v128) (result v128)
(i8x16.popcnt
(local.get $0)
)
)
(func $i8x16.abs (param $0 v128) (result v128)
(i8x16.abs
(local.get $0)
Expand Down
Loading