Skip to content

Add various SIMD instructions to C/JS API #3777

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 2 commits into from
Apr 7, 2021
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
10 changes: 10 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ BinaryenOp BinaryenLeSVecI32x4(void) { return LeSVecI32x4; }
BinaryenOp BinaryenLeUVecI32x4(void) { return LeUVecI32x4; }
BinaryenOp BinaryenGeSVecI32x4(void) { return GeSVecI32x4; }
BinaryenOp BinaryenGeUVecI32x4(void) { return GeUVecI32x4; }
BinaryenOp BinaryenEqVecI64x2(void) { return EqVecI64x2; }
BinaryenOp BinaryenNeVecI64x2(void) { return NeVecI64x2; }
BinaryenOp BinaryenLtSVecI64x2(void) { return LtSVecI64x2; }
BinaryenOp BinaryenGtSVecI64x2(void) { return GtSVecI64x2; }
BinaryenOp BinaryenLeSVecI64x2(void) { return LeSVecI64x2; }
BinaryenOp BinaryenGeSVecI64x2(void) { return GeSVecI64x2; }
BinaryenOp BinaryenEqVecF32x4(void) { return EqVecF32x4; }
BinaryenOp BinaryenNeVecF32x4(void) { return NeVecF32x4; }
BinaryenOp BinaryenLtVecF32x4(void) { return LtVecF32x4; }
Expand All @@ -531,6 +537,7 @@ BinaryenOp BinaryenAbsVecI8x16(void) { return AbsVecI8x16; }
BinaryenOp BinaryenNegVecI8x16(void) { return NegVecI8x16; }
BinaryenOp BinaryenAllTrueVecI8x16(void) { return AllTrueVecI8x16; }
BinaryenOp BinaryenBitmaskVecI8x16(void) { return BitmaskVecI8x16; }
BinaryenOp BinaryenPopcntVecI8x16(void) { return PopcntVecI8x16; }
BinaryenOp BinaryenShlVecI8x16(void) { return ShlVecI8x16; }
BinaryenOp BinaryenShrSVecI8x16(void) { return ShrSVecI8x16; }
BinaryenOp BinaryenShrUVecI8x16(void) { return ShrUVecI8x16; }
Expand Down Expand Up @@ -581,7 +588,10 @@ BinaryenOp BinaryenMaxUVecI32x4(void) { return MaxUVecI32x4; }
BinaryenOp BinaryenDotSVecI16x8ToVecI32x4(void) {
return DotSVecI16x8ToVecI32x4;
}
BinaryenOp BinaryenAbsVecI64x2(void) { return AbsVecI64x2; }
BinaryenOp BinaryenNegVecI64x2(void) { return NegVecI64x2; }
BinaryenOp BinaryenAllTrueVecI64x2(void) { return AllTrueVecI64x2; }
BinaryenOp BinaryenBitmaskVecI64x2(void) { return BitmaskVecI64x2; }
BinaryenOp BinaryenShlVecI64x2(void) { return ShlVecI64x2; }
BinaryenOp BinaryenShrSVecI64x2(void) { return ShrSVecI64x2; }
BinaryenOp BinaryenShrUVecI64x2(void) { return ShrUVecI64x2; }
Expand Down
11 changes: 10 additions & 1 deletion src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ BINARYEN_API BinaryenOp BinaryenLeSVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenLeUVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenGeSVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenGeUVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenEqVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenNeVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenLtSVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenGtSVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenLeSVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenGeSVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenEqVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenNeVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenLtVecF32x4(void);
Expand All @@ -428,7 +434,7 @@ BINARYEN_API BinaryenOp BinaryenXorVec128(void);
BINARYEN_API BinaryenOp BinaryenAndNotVec128(void);
BINARYEN_API BinaryenOp BinaryenBitselectVec128(void);
BINARYEN_API BinaryenOp BinaryenAnyTrueVec128(void);
// TODO: Add i8x16.popcnt to C and JS APIs once merged to the proposal
BINARYEN_API BinaryenOp BinaryenPopcntVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenAbsVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenNegVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenAllTrueVecI8x16(void);
Expand Down Expand Up @@ -483,7 +489,10 @@ BINARYEN_API BinaryenOp BinaryenMinUVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenMaxSVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenMaxUVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenDotSVecI16x8ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenAbsVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenNegVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenAllTrueVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenBitmaskVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenShlVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenShrSVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenShrUVecI64x2(void);
Expand Down
40 changes: 40 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ function initializeConstants() {
'LeUVecI32x4',
'GeSVecI32x4',
'GeUVecI32x4',
'EqVecI64x2',
'NeVecI64x2',
'LtSVecI64x2',
'GtSVecI64x2',
'LeSVecI64x2',
'GeSVecI64x2',
'EqVecF32x4',
'NeVecF32x4',
'LtVecF32x4',
Expand All @@ -360,6 +366,7 @@ function initializeConstants() {
'AndNotVec128',
'BitselectVec128',
'AnyTrueVec128',
'PopcntVecI8x16',
'AbsVecI8x16',
'NegVecI8x16',
'AllTrueVecI8x16',
Expand Down Expand Up @@ -412,7 +419,10 @@ function initializeConstants() {
'MinUVecI32x4',
'MaxSVecI32x4',
'MaxUVecI32x4',
'AbsVecI64x2',
'NegVecI64x2',
'AllTrueVecI64x2',
'BitmaskVecI64x2',
'ShlVecI64x2',
'ShrSVecI64x2',
'ShrUVecI64x2',
Expand Down Expand Up @@ -1550,6 +1560,9 @@ function wrapModule(module, self = {}) {
'bitmask'(value) {
return Module['_BinaryenUnary'](module, Module['BitmaskVecI8x16'], value);
},
'popcnt'(value) {
return Module['_BinaryenUnary'](module, Module['PopcntVecI8x16'], value);
},
'shl'(vec, shift) {
return Module['_BinaryenSIMDShift'](module, Module['ShlVecI8x16'], vec, shift);
},
Expand Down Expand Up @@ -1835,9 +1848,36 @@ function wrapModule(module, self = {}) {
'replace_lane'(vec, index, value) {
return Module['_BinaryenSIMDReplace'](module, Module['ReplaceLaneVecI64x2'], vec, index, value);
},
'eq'(left, right) {
return Module['_BinaryenBinary'](module, Module['EqVecI64x2'], left, right);
},
'ne'(left, right) {
return Module['_BinaryenBinary'](module, Module['NeVecI64x2'], left, right);
},
'lt_s'(left, right) {
return Module['_BinaryenBinary'](module, Module['LtSVecI64x2'], left, right);
},
'gt_s'(left, right) {
return Module['_BinaryenBinary'](module, Module['GtSVecI64x2'], left, right);
},
'le_s'(left, right) {
return Module['_BinaryenBinary'](module, Module['LeSVecI64x2'], left, right);
},
'ge_s'(left, right) {
return Module['_BinaryenBinary'](module, Module['GeSVecI64x2'], left, right);
},
'abs'(value) {
return Module['_BinaryenUnary'](module, Module['AbsVecI64x2'], value);
},
'neg'(value) {
return Module['_BinaryenUnary'](module, Module['NegVecI64x2'], value);
},
'all_true'(value) {
return Module['_BinaryenUnary'](module, Module['AllTrueVecI64x2'], value);
},
'bitmask'(value) {
return Module['_BinaryenUnary'](module, Module['BitmaskVecI64x2'], value);
},
'shl'(vec, shift) {
return Module['_BinaryenSIMDShift'](module, Module['ShlVecI64x2'], vec, shift);
},
Expand Down
10 changes: 10 additions & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ function test_core() {
module.f64x2.splat(module.f64.const(42.0)),
module.v128.not(module.v128.const(v128_bytes)),
module.v128.any_true(module.v128.const(v128_bytes)),
module.i8x16.popcnt(module.v128.const(v128_bytes)),
module.i8x16.abs(module.v128.const(v128_bytes)),
module.i8x16.neg(module.v128.const(v128_bytes)),
module.i8x16.all_true(module.v128.const(v128_bytes)),
Expand All @@ -278,7 +279,10 @@ function test_core() {
module.i32x4.neg(module.v128.const(v128_bytes)),
module.i32x4.all_true(module.v128.const(v128_bytes)),
module.i32x4.bitmask(module.v128.const(v128_bytes)),
module.i64x2.abs(module.v128.const(v128_bytes)),
module.i64x2.neg(module.v128.const(v128_bytes)),
module.i64x2.all_true(module.v128.const(v128_bytes)),
module.i64x2.bitmask(module.v128.const(v128_bytes)),
module.f32x4.abs(module.v128.const(v128_bytes)),
module.f32x4.neg(module.v128.const(v128_bytes)),
module.f32x4.sqrt(module.v128.const(v128_bytes)),
Expand Down Expand Up @@ -360,6 +364,12 @@ function test_core() {
module.i32x4.le_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i32x4.ge_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i32x4.ge_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i64x2.eq(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i64x2.ne(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i64x2.lt_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i64x2.gt_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i64x2.le_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.i64x2.ge_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.f32x4.eq(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.f32x4.ne(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
module.f32x4.lt(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
Expand Down
112 changes: 112 additions & 0 deletions test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i8x16.popcnt
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i8x16.abs
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -466,11 +471,26 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.abs
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.neg
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.all_true
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.bitmask
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.abs
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -933,6 +953,42 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.ne
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.lt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.gt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.le_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.ge_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -2204,6 +2260,11 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i8x16.popcnt
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i8x16.abs
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -2264,11 +2325,26 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.abs
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.neg
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.all_true
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.bitmask
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.abs
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -2731,6 +2807,42 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.ne
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.lt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.gt_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.le_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.ge_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down
10 changes: 10 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ void test_core() {
makeUnary(module, BinaryenSplatVecF64x2(), f64),
makeUnary(module, BinaryenNotVec128(), v128),
makeUnary(module, BinaryenAnyTrueVec128(), v128),
makeUnary(module, BinaryenPopcntVecI8x16(), v128),
makeUnary(module, BinaryenAbsVecI8x16(), v128),
makeUnary(module, BinaryenNegVecI8x16(), v128),
makeUnary(module, BinaryenAllTrueVecI8x16(), v128),
Expand All @@ -416,7 +417,10 @@ void test_core() {
makeUnary(module, BinaryenNegVecI32x4(), v128),
makeUnary(module, BinaryenAllTrueVecI32x4(), v128),
makeUnary(module, BinaryenBitmaskVecI32x4(), v128),
makeUnary(module, BinaryenAbsVecI64x2(), v128),
makeUnary(module, BinaryenNegVecI64x2(), v128),
makeUnary(module, BinaryenAllTrueVecI64x2(), v128),
makeUnary(module, BinaryenBitmaskVecI64x2(), v128),
makeUnary(module, BinaryenAbsVecF32x4(), v128),
makeUnary(module, BinaryenNegVecF32x4(), v128),
makeUnary(module, BinaryenSqrtVecF32x4(), v128),
Expand Down Expand Up @@ -498,6 +502,12 @@ void test_core() {
makeBinary(module, BinaryenLeUVecI32x4(), v128),
makeBinary(module, BinaryenGeSVecI32x4(), v128),
makeBinary(module, BinaryenGeUVecI32x4(), v128),
makeBinary(module, BinaryenEqVecI64x2(), v128),
makeBinary(module, BinaryenNeVecI64x2(), v128),
makeBinary(module, BinaryenLtSVecI64x2(), v128),
makeBinary(module, BinaryenGtSVecI64x2(), v128),
makeBinary(module, BinaryenLeSVecI64x2(), v128),
makeBinary(module, BinaryenGeSVecI64x2(), v128),
makeBinary(module, BinaryenEqVecF32x4(), v128),
makeBinary(module, BinaryenNeVecF32x4(), v128),
makeBinary(module, BinaryenLtVecF32x4(), v128),
Expand Down
Loading