Skip to content

Commit 2f2d5a8

Browse files
authored
Add various SIMD instructions to C/JS API (#3777)
Adds C/JS APIs for the SIMD instructions * PopcntVecI8x16 * AbsVecI64x2 * AllTrueVecI64x2 * BitmaskVecI64x2 * EqVecI64x2 * NeVecI64x2 * LtSVecI64x2 * GtSVecI64x2 * LeSVecI64x2 * GeSVecI64x2
1 parent b3484a7 commit 2f2d5a8

File tree

7 files changed

+248
-1
lines changed

7 files changed

+248
-1
lines changed

src/binaryen-c.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ BinaryenOp BinaryenLeSVecI32x4(void) { return LeSVecI32x4; }
508508
BinaryenOp BinaryenLeUVecI32x4(void) { return LeUVecI32x4; }
509509
BinaryenOp BinaryenGeSVecI32x4(void) { return GeSVecI32x4; }
510510
BinaryenOp BinaryenGeUVecI32x4(void) { return GeUVecI32x4; }
511+
BinaryenOp BinaryenEqVecI64x2(void) { return EqVecI64x2; }
512+
BinaryenOp BinaryenNeVecI64x2(void) { return NeVecI64x2; }
513+
BinaryenOp BinaryenLtSVecI64x2(void) { return LtSVecI64x2; }
514+
BinaryenOp BinaryenGtSVecI64x2(void) { return GtSVecI64x2; }
515+
BinaryenOp BinaryenLeSVecI64x2(void) { return LeSVecI64x2; }
516+
BinaryenOp BinaryenGeSVecI64x2(void) { return GeSVecI64x2; }
511517
BinaryenOp BinaryenEqVecF32x4(void) { return EqVecF32x4; }
512518
BinaryenOp BinaryenNeVecF32x4(void) { return NeVecF32x4; }
513519
BinaryenOp BinaryenLtVecF32x4(void) { return LtVecF32x4; }
@@ -531,6 +537,7 @@ BinaryenOp BinaryenAbsVecI8x16(void) { return AbsVecI8x16; }
531537
BinaryenOp BinaryenNegVecI8x16(void) { return NegVecI8x16; }
532538
BinaryenOp BinaryenAllTrueVecI8x16(void) { return AllTrueVecI8x16; }
533539
BinaryenOp BinaryenBitmaskVecI8x16(void) { return BitmaskVecI8x16; }
540+
BinaryenOp BinaryenPopcntVecI8x16(void) { return PopcntVecI8x16; }
534541
BinaryenOp BinaryenShlVecI8x16(void) { return ShlVecI8x16; }
535542
BinaryenOp BinaryenShrSVecI8x16(void) { return ShrSVecI8x16; }
536543
BinaryenOp BinaryenShrUVecI8x16(void) { return ShrUVecI8x16; }
@@ -581,7 +588,10 @@ BinaryenOp BinaryenMaxUVecI32x4(void) { return MaxUVecI32x4; }
581588
BinaryenOp BinaryenDotSVecI16x8ToVecI32x4(void) {
582589
return DotSVecI16x8ToVecI32x4;
583590
}
591+
BinaryenOp BinaryenAbsVecI64x2(void) { return AbsVecI64x2; }
584592
BinaryenOp BinaryenNegVecI64x2(void) { return NegVecI64x2; }
593+
BinaryenOp BinaryenAllTrueVecI64x2(void) { return AllTrueVecI64x2; }
594+
BinaryenOp BinaryenBitmaskVecI64x2(void) { return BitmaskVecI64x2; }
585595
BinaryenOp BinaryenShlVecI64x2(void) { return ShlVecI64x2; }
586596
BinaryenOp BinaryenShrSVecI64x2(void) { return ShrSVecI64x2; }
587597
BinaryenOp BinaryenShrUVecI64x2(void) { return ShrUVecI64x2; }

src/binaryen-c.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ BINARYEN_API BinaryenOp BinaryenLeSVecI32x4(void);
409409
BINARYEN_API BinaryenOp BinaryenLeUVecI32x4(void);
410410
BINARYEN_API BinaryenOp BinaryenGeSVecI32x4(void);
411411
BINARYEN_API BinaryenOp BinaryenGeUVecI32x4(void);
412+
BINARYEN_API BinaryenOp BinaryenEqVecI64x2(void);
413+
BINARYEN_API BinaryenOp BinaryenNeVecI64x2(void);
414+
BINARYEN_API BinaryenOp BinaryenLtSVecI64x2(void);
415+
BINARYEN_API BinaryenOp BinaryenGtSVecI64x2(void);
416+
BINARYEN_API BinaryenOp BinaryenLeSVecI64x2(void);
417+
BINARYEN_API BinaryenOp BinaryenGeSVecI64x2(void);
412418
BINARYEN_API BinaryenOp BinaryenEqVecF32x4(void);
413419
BINARYEN_API BinaryenOp BinaryenNeVecF32x4(void);
414420
BINARYEN_API BinaryenOp BinaryenLtVecF32x4(void);
@@ -428,7 +434,7 @@ BINARYEN_API BinaryenOp BinaryenXorVec128(void);
428434
BINARYEN_API BinaryenOp BinaryenAndNotVec128(void);
429435
BINARYEN_API BinaryenOp BinaryenBitselectVec128(void);
430436
BINARYEN_API BinaryenOp BinaryenAnyTrueVec128(void);
431-
// TODO: Add i8x16.popcnt to C and JS APIs once merged to the proposal
437+
BINARYEN_API BinaryenOp BinaryenPopcntVecI8x16(void);
432438
BINARYEN_API BinaryenOp BinaryenAbsVecI8x16(void);
433439
BINARYEN_API BinaryenOp BinaryenNegVecI8x16(void);
434440
BINARYEN_API BinaryenOp BinaryenAllTrueVecI8x16(void);
@@ -483,7 +489,10 @@ BINARYEN_API BinaryenOp BinaryenMinUVecI32x4(void);
483489
BINARYEN_API BinaryenOp BinaryenMaxSVecI32x4(void);
484490
BINARYEN_API BinaryenOp BinaryenMaxUVecI32x4(void);
485491
BINARYEN_API BinaryenOp BinaryenDotSVecI16x8ToVecI32x4(void);
492+
BINARYEN_API BinaryenOp BinaryenAbsVecI64x2(void);
486493
BINARYEN_API BinaryenOp BinaryenNegVecI64x2(void);
494+
BINARYEN_API BinaryenOp BinaryenAllTrueVecI64x2(void);
495+
BINARYEN_API BinaryenOp BinaryenBitmaskVecI64x2(void);
487496
BINARYEN_API BinaryenOp BinaryenShlVecI64x2(void);
488497
BINARYEN_API BinaryenOp BinaryenShrSVecI64x2(void);
489498
BINARYEN_API BinaryenOp BinaryenShrUVecI64x2(void);

src/js/binaryen.js-post.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ function initializeConstants() {
341341
'LeUVecI32x4',
342342
'GeSVecI32x4',
343343
'GeUVecI32x4',
344+
'EqVecI64x2',
345+
'NeVecI64x2',
346+
'LtSVecI64x2',
347+
'GtSVecI64x2',
348+
'LeSVecI64x2',
349+
'GeSVecI64x2',
344350
'EqVecF32x4',
345351
'NeVecF32x4',
346352
'LtVecF32x4',
@@ -360,6 +366,7 @@ function initializeConstants() {
360366
'AndNotVec128',
361367
'BitselectVec128',
362368
'AnyTrueVec128',
369+
'PopcntVecI8x16',
363370
'AbsVecI8x16',
364371
'NegVecI8x16',
365372
'AllTrueVecI8x16',
@@ -412,7 +419,10 @@ function initializeConstants() {
412419
'MinUVecI32x4',
413420
'MaxSVecI32x4',
414421
'MaxUVecI32x4',
422+
'AbsVecI64x2',
415423
'NegVecI64x2',
424+
'AllTrueVecI64x2',
425+
'BitmaskVecI64x2',
416426
'ShlVecI64x2',
417427
'ShrSVecI64x2',
418428
'ShrUVecI64x2',
@@ -1550,6 +1560,9 @@ function wrapModule(module, self = {}) {
15501560
'bitmask'(value) {
15511561
return Module['_BinaryenUnary'](module, Module['BitmaskVecI8x16'], value);
15521562
},
1563+
'popcnt'(value) {
1564+
return Module['_BinaryenUnary'](module, Module['PopcntVecI8x16'], value);
1565+
},
15531566
'shl'(vec, shift) {
15541567
return Module['_BinaryenSIMDShift'](module, Module['ShlVecI8x16'], vec, shift);
15551568
},
@@ -1835,9 +1848,36 @@ function wrapModule(module, self = {}) {
18351848
'replace_lane'(vec, index, value) {
18361849
return Module['_BinaryenSIMDReplace'](module, Module['ReplaceLaneVecI64x2'], vec, index, value);
18371850
},
1851+
'eq'(left, right) {
1852+
return Module['_BinaryenBinary'](module, Module['EqVecI64x2'], left, right);
1853+
},
1854+
'ne'(left, right) {
1855+
return Module['_BinaryenBinary'](module, Module['NeVecI64x2'], left, right);
1856+
},
1857+
'lt_s'(left, right) {
1858+
return Module['_BinaryenBinary'](module, Module['LtSVecI64x2'], left, right);
1859+
},
1860+
'gt_s'(left, right) {
1861+
return Module['_BinaryenBinary'](module, Module['GtSVecI64x2'], left, right);
1862+
},
1863+
'le_s'(left, right) {
1864+
return Module['_BinaryenBinary'](module, Module['LeSVecI64x2'], left, right);
1865+
},
1866+
'ge_s'(left, right) {
1867+
return Module['_BinaryenBinary'](module, Module['GeSVecI64x2'], left, right);
1868+
},
1869+
'abs'(value) {
1870+
return Module['_BinaryenUnary'](module, Module['AbsVecI64x2'], value);
1871+
},
18381872
'neg'(value) {
18391873
return Module['_BinaryenUnary'](module, Module['NegVecI64x2'], value);
18401874
},
1875+
'all_true'(value) {
1876+
return Module['_BinaryenUnary'](module, Module['AllTrueVecI64x2'], value);
1877+
},
1878+
'bitmask'(value) {
1879+
return Module['_BinaryenUnary'](module, Module['BitmaskVecI64x2'], value);
1880+
},
18411881
'shl'(vec, shift) {
18421882
return Module['_BinaryenSIMDShift'](module, Module['ShlVecI64x2'], vec, shift);
18431883
},

test/binaryen.js/kitchen-sink.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ function test_core() {
266266
module.f64x2.splat(module.f64.const(42.0)),
267267
module.v128.not(module.v128.const(v128_bytes)),
268268
module.v128.any_true(module.v128.const(v128_bytes)),
269+
module.i8x16.popcnt(module.v128.const(v128_bytes)),
269270
module.i8x16.abs(module.v128.const(v128_bytes)),
270271
module.i8x16.neg(module.v128.const(v128_bytes)),
271272
module.i8x16.all_true(module.v128.const(v128_bytes)),
@@ -278,7 +279,10 @@ function test_core() {
278279
module.i32x4.neg(module.v128.const(v128_bytes)),
279280
module.i32x4.all_true(module.v128.const(v128_bytes)),
280281
module.i32x4.bitmask(module.v128.const(v128_bytes)),
282+
module.i64x2.abs(module.v128.const(v128_bytes)),
281283
module.i64x2.neg(module.v128.const(v128_bytes)),
284+
module.i64x2.all_true(module.v128.const(v128_bytes)),
285+
module.i64x2.bitmask(module.v128.const(v128_bytes)),
282286
module.f32x4.abs(module.v128.const(v128_bytes)),
283287
module.f32x4.neg(module.v128.const(v128_bytes)),
284288
module.f32x4.sqrt(module.v128.const(v128_bytes)),
@@ -360,6 +364,12 @@ function test_core() {
360364
module.i32x4.le_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
361365
module.i32x4.ge_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
362366
module.i32x4.ge_u(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
367+
module.i64x2.eq(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
368+
module.i64x2.ne(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
369+
module.i64x2.lt_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
370+
module.i64x2.gt_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
371+
module.i64x2.le_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
372+
module.i64x2.ge_s(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
363373
module.f32x4.eq(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
364374
module.f32x4.ne(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
365375
module.f32x4.lt(module.v128.const(v128_bytes), module.v128.const(v128_bytes)),

test/binaryen.js/kitchen-sink.js.txt

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
406406
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
407407
)
408408
)
409+
(drop
410+
(i8x16.popcnt
411+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
412+
)
413+
)
409414
(drop
410415
(i8x16.abs
411416
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
@@ -466,11 +471,26 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
466471
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
467472
)
468473
)
474+
(drop
475+
(i64x2.abs
476+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
477+
)
478+
)
469479
(drop
470480
(i64x2.neg
471481
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
472482
)
473483
)
484+
(drop
485+
(i64x2.all_true
486+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
487+
)
488+
)
489+
(drop
490+
(i64x2.bitmask
491+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
492+
)
493+
)
474494
(drop
475495
(f32x4.abs
476496
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
@@ -933,6 +953,42 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
933953
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
934954
)
935955
)
956+
(drop
957+
(i64x2.eq
958+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
959+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
960+
)
961+
)
962+
(drop
963+
(i64x2.ne
964+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
965+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
966+
)
967+
)
968+
(drop
969+
(i64x2.lt_s
970+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
971+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
972+
)
973+
)
974+
(drop
975+
(i64x2.gt_s
976+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
977+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
978+
)
979+
)
980+
(drop
981+
(i64x2.le_s
982+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
983+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
984+
)
985+
)
986+
(drop
987+
(i64x2.ge_s
988+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
989+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
990+
)
991+
)
936992
(drop
937993
(f32x4.eq
938994
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
@@ -2204,6 +2260,11 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
22042260
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
22052261
)
22062262
)
2263+
(drop
2264+
(i8x16.popcnt
2265+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2266+
)
2267+
)
22072268
(drop
22082269
(i8x16.abs
22092270
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
@@ -2264,11 +2325,26 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
22642325
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
22652326
)
22662327
)
2328+
(drop
2329+
(i64x2.abs
2330+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2331+
)
2332+
)
22672333
(drop
22682334
(i64x2.neg
22692335
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
22702336
)
22712337
)
2338+
(drop
2339+
(i64x2.all_true
2340+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2341+
)
2342+
)
2343+
(drop
2344+
(i64x2.bitmask
2345+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2346+
)
2347+
)
22722348
(drop
22732349
(f32x4.abs
22742350
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
@@ -2731,6 +2807,42 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
27312807
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
27322808
)
27332809
)
2810+
(drop
2811+
(i64x2.eq
2812+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2813+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2814+
)
2815+
)
2816+
(drop
2817+
(i64x2.ne
2818+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2819+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2820+
)
2821+
)
2822+
(drop
2823+
(i64x2.lt_s
2824+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2825+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2826+
)
2827+
)
2828+
(drop
2829+
(i64x2.gt_s
2830+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2831+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2832+
)
2833+
)
2834+
(drop
2835+
(i64x2.le_s
2836+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2837+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2838+
)
2839+
)
2840+
(drop
2841+
(i64x2.ge_s
2842+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2843+
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
2844+
)
2845+
)
27342846
(drop
27352847
(f32x4.eq
27362848
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)

test/example/c-api-kitchen-sink.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ void test_core() {
404404
makeUnary(module, BinaryenSplatVecF64x2(), f64),
405405
makeUnary(module, BinaryenNotVec128(), v128),
406406
makeUnary(module, BinaryenAnyTrueVec128(), v128),
407+
makeUnary(module, BinaryenPopcntVecI8x16(), v128),
407408
makeUnary(module, BinaryenAbsVecI8x16(), v128),
408409
makeUnary(module, BinaryenNegVecI8x16(), v128),
409410
makeUnary(module, BinaryenAllTrueVecI8x16(), v128),
@@ -416,7 +417,10 @@ void test_core() {
416417
makeUnary(module, BinaryenNegVecI32x4(), v128),
417418
makeUnary(module, BinaryenAllTrueVecI32x4(), v128),
418419
makeUnary(module, BinaryenBitmaskVecI32x4(), v128),
420+
makeUnary(module, BinaryenAbsVecI64x2(), v128),
419421
makeUnary(module, BinaryenNegVecI64x2(), v128),
422+
makeUnary(module, BinaryenAllTrueVecI64x2(), v128),
423+
makeUnary(module, BinaryenBitmaskVecI64x2(), v128),
420424
makeUnary(module, BinaryenAbsVecF32x4(), v128),
421425
makeUnary(module, BinaryenNegVecF32x4(), v128),
422426
makeUnary(module, BinaryenSqrtVecF32x4(), v128),
@@ -498,6 +502,12 @@ void test_core() {
498502
makeBinary(module, BinaryenLeUVecI32x4(), v128),
499503
makeBinary(module, BinaryenGeSVecI32x4(), v128),
500504
makeBinary(module, BinaryenGeUVecI32x4(), v128),
505+
makeBinary(module, BinaryenEqVecI64x2(), v128),
506+
makeBinary(module, BinaryenNeVecI64x2(), v128),
507+
makeBinary(module, BinaryenLtSVecI64x2(), v128),
508+
makeBinary(module, BinaryenGtSVecI64x2(), v128),
509+
makeBinary(module, BinaryenLeSVecI64x2(), v128),
510+
makeBinary(module, BinaryenGeSVecI64x2(), v128),
501511
makeBinary(module, BinaryenEqVecF32x4(), v128),
502512
makeBinary(module, BinaryenNeVecF32x4(), v128),
503513
makeBinary(module, BinaryenLtVecF32x4(), v128),

0 commit comments

Comments
 (0)