Skip to content

Add new SIMD conversion instructions to C/JS API #3781

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
Apr 8, 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
18 changes: 18 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,24 @@ BinaryenOp BinaryenExtendLowUVecI32x4ToVecI64x2(void) {
BinaryenOp BinaryenExtendHighUVecI32x4ToVecI64x2(void) {
return ExtendHighUVecI32x4ToVecI64x2;
}
BinaryenOp BinaryenConvertLowSVecI32x4ToVecF64x2(void) {
return ConvertLowSVecI32x4ToVecF64x2;
}
BinaryenOp BinaryenConvertLowUVecI32x4ToVecF64x2(void) {
return ConvertLowUVecI32x4ToVecF64x2;
}
BinaryenOp BinaryenTruncSatZeroSVecF64x2ToVecI32x4(void) {
return TruncSatZeroSVecF64x2ToVecI32x4;
}
BinaryenOp BinaryenTruncSatZeroUVecF64x2ToVecI32x4(void) {
return TruncSatZeroUVecF64x2ToVecI32x4;
}
BinaryenOp BinaryenDemoteZeroVecF64x2ToVecF32x4(void) {
return DemoteZeroVecF64x2ToVecF32x4;
}
BinaryenOp BinaryenPromoteLowVecF32x4ToVecF64x2(void) {
return PromoteLowVecF32x4ToVecF64x2;
}
BinaryenOp BinaryenSwizzleVec8x16(void) { return SwizzleVec8x16; }
BinaryenOp BinaryenRefIsNull(void) { return RefIsNull; }
BinaryenOp BinaryenRefIsFunc(void) { return RefIsFunc; }
Expand Down
6 changes: 6 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ BINARYEN_API BinaryenOp BinaryenExtendLowSVecI32x4ToVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenExtendHighSVecI32x4ToVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenExtendLowUVecI32x4ToVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenExtendHighUVecI32x4ToVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenConvertLowSVecI32x4ToVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenConvertLowUVecI32x4ToVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenTruncSatZeroSVecF64x2ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenTruncSatZeroUVecF64x2ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenDemoteZeroVecF64x2ToVecF32x4(void);
BINARYEN_API BinaryenOp BinaryenPromoteLowVecF32x4ToVecF64x2(void);
BINARYEN_API BinaryenOp BinaryenSwizzleVec8x16(void);
BINARYEN_API BinaryenOp BinaryenRefIsNull(void);
BINARYEN_API BinaryenOp BinaryenRefIsFunc(void);
Expand Down
24 changes: 24 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ function initializeConstants() {
'ExtendHighSVecI32x4ToVecI64x2',
'ExtendLowUVecI32x4ToVecI64x2',
'ExtendHighUVecI32x4ToVecI64x2',
'ConvertLowSVecI32x4ToVecF64x2',
'ConvertLowUVecI32x4ToVecF64x2',
'TruncSatZeroSVecF64x2ToVecI32x4',
'TruncSatZeroUVecF64x2ToVecI32x4',
'DemoteZeroVecF64x2ToVecF32x4',
'PromoteLowVecF32x4ToVecF64x2',
'SwizzleVec8x16',
'RefIsNull',
'RefIsFunc',
Expand Down Expand Up @@ -1840,6 +1846,12 @@ function wrapModule(module, self = {}) {
'extend_high_i16x8_u'(value) {
return Module['_BinaryenUnary'](module, Module['ExtendHighUVecI16x8ToVecI32x4'], value);
},
'trunc_sat_f64x2_s_zero'(value) {
return Module['_BinaryenUnary'](module, Module['TruncSatZeroSVecF64x2ToVecI32x4'], value);
},
'trunc_sat_f64x2_u_zero'(value) {
return Module['_BinaryenUnary'](module, Module['TruncSatZeroUVecF64x2ToVecI32x4'], value);
},
};

self['i64x2'] = {
Expand Down Expand Up @@ -1993,6 +2005,9 @@ function wrapModule(module, self = {}) {
'convert_i32x4_u'(value) {
return Module['_BinaryenUnary'](module, Module['ConvertUVecI32x4ToVecF32x4'], value);
},
'demote_f64x2_zero'(value) {
return Module['_BinaryenUnary'](module, Module['DemoteZeroVecF64x2ToVecF32x4'], value);
},
};

self['f64x2'] = {
Expand Down Expand Up @@ -2068,6 +2083,15 @@ function wrapModule(module, self = {}) {
'nearest'(value) {
return Module['_BinaryenUnary'](module, Module['NearestVecF64x2'], value);
},
'convert_low_i32x4_s'(value) {
return Module['_BinaryenUnary'](module, Module['ConvertLowSVecI32x4ToVecF64x2'], value);
},
'convert_low_i32x4_u'(value) {
return Module['_BinaryenUnary'](module, Module['ConvertLowUVecI32x4ToVecF64x2'], value);
},
'promote_low_f32x4'(value) {
return Module['_BinaryenUnary'](module, Module['PromoteLowVecF32x4ToVecF64x2'], value);
},
};

self['funcref'] = {
Expand Down
6 changes: 6 additions & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,14 @@ function test_core() {
module.f64x2.abs(module.v128.const(v128_bytes)),
module.f64x2.neg(module.v128.const(v128_bytes)),
module.f64x2.sqrt(module.v128.const(v128_bytes)),
module.f64x2.convert_low_i32x4_s(module.v128.const(v128_bytes)),
module.f64x2.convert_low_i32x4_u(module.v128.const(v128_bytes)),
module.f64x2.promote_low_f32x4(module.v128.const(v128_bytes)),
module.i32x4.trunc_sat_f32x4_s(module.v128.const(v128_bytes)),
module.i32x4.trunc_sat_f32x4_u(module.v128.const(v128_bytes)),
module.f32x4.convert_i32x4_s(module.v128.const(v128_bytes)),
module.f32x4.convert_i32x4_u(module.v128.const(v128_bytes)),
module.f32x4.demote_f64x2_zero(module.v128.const(v128_bytes)),
module.i16x8.extend_low_i8x16_s(module.v128.const(v128_bytes)),
module.i16x8.extend_high_i8x16_s(module.v128.const(v128_bytes)),
module.i16x8.extend_low_i8x16_u(module.v128.const(v128_bytes)),
Expand All @@ -301,6 +305,8 @@ function test_core() {
module.i32x4.extend_high_i16x8_s(module.v128.const(v128_bytes)),
module.i32x4.extend_low_i16x8_u(module.v128.const(v128_bytes)),
module.i32x4.extend_high_i16x8_u(module.v128.const(v128_bytes)),
module.i32x4.trunc_sat_f64x2_s_zero(module.v128.const(v128_bytes)),
module.i32x4.trunc_sat_f64x2_u_zero(module.v128.const(v128_bytes)),
module.i64x2.extend_low_i32x4_s(module.v128.const(v128_bytes)),
module.i64x2.extend_high_i32x4_s(module.v128.const(v128_bytes)),
module.i64x2.extend_low_i32x4_u(module.v128.const(v128_bytes)),
Expand Down
60 changes: 60 additions & 0 deletions test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,21 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.convert_low_i32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.convert_low_i32x4_u
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.promote_low_f32x4
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand All @@ -541,6 +556,11 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.demote_f64x2_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i16x8.extend_low_i8x16_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -581,6 +601,16 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f64x2_s_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f64x2_u_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.extend_low_i32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -2395,6 +2425,21 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.convert_low_i32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.convert_low_i32x4_u
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.promote_low_f32x4
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand All @@ -2415,6 +2460,11 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.demote_f64x2_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i16x8.extend_low_i8x16_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -2455,6 +2505,16 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f64x2_s_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f64x2_u_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i64x2.extend_low_i32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down
6 changes: 6 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,12 @@ void test_core() {
makeUnary(module, BinaryenExtendHighSVecI32x4ToVecI64x2(), v128),
makeUnary(module, BinaryenExtendLowUVecI32x4ToVecI64x2(), v128),
makeUnary(module, BinaryenExtendHighUVecI32x4ToVecI64x2(), v128),
makeUnary(module, BinaryenConvertLowSVecI32x4ToVecF64x2(), v128),
makeUnary(module, BinaryenConvertLowUVecI32x4ToVecF64x2(), v128),
makeUnary(module, BinaryenTruncSatZeroSVecF64x2ToVecI32x4(), v128),
makeUnary(module, BinaryenTruncSatZeroUVecF64x2ToVecI32x4(), v128),
makeUnary(module, BinaryenDemoteZeroVecF64x2ToVecF32x4(), v128),
makeUnary(module, BinaryenPromoteLowVecF32x4ToVecF64x2(), v128),
// Binary
makeBinary(module, BinaryenAddInt32(), i32),
makeBinary(module, BinaryenSubFloat64(), f64),
Expand Down
30 changes: 30 additions & 0 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,36 @@ BinaryenFeatureAll: 8191
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.convert_low_i32x4_s
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.convert_low_i32x4_u
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f64x2_s_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32x4.trunc_sat_f64x2_u_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f32x4.demote_f64x2_zero
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(f64x2.promote_low_f32x4
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(i32.add
(i32.const -10)
Expand Down