Skip to content

Add v128.load/storeN_lane SIMD instructions to C/JS API #3784

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 5 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,14 @@ BinaryenOp BinaryenLoadExtSVec32x2ToVecI64x2(void) {
BinaryenOp BinaryenLoadExtUVec32x2ToVecI64x2(void) {
return LoadExtUVec32x2ToVecI64x2;
}
BinaryenOp BinaryenLoadLaneVec8x16(void) { return LoadLaneVec8x16; }
BinaryenOp BinaryenLoadLaneVec16x8(void) { return LoadLaneVec16x8; }
BinaryenOp BinaryenLoadLaneVec32x4(void) { return LoadLaneVec32x4; }
BinaryenOp BinaryenLoadLaneVec64x2(void) { return LoadLaneVec64x2; }
BinaryenOp BinaryenStoreLaneVec8x16(void) { return StoreLaneVec8x16; }
BinaryenOp BinaryenStoreLaneVec16x8(void) { return StoreLaneVec16x8; }
BinaryenOp BinaryenStoreLaneVec32x4(void) { return StoreLaneVec32x4; }
BinaryenOp BinaryenStoreLaneVec64x2(void) { return StoreLaneVec64x2; }
BinaryenOp BinaryenNarrowSVecI16x8ToVecI8x16(void) {
return NarrowSVecI16x8ToVecI8x16;
}
Expand Down Expand Up @@ -1161,6 +1169,22 @@ BinaryenExpressionRef BinaryenSIMDLoad(BinaryenModuleRef module,
.makeSIMDLoad(
SIMDLoadOp(op), Address(offset), Address(align), (Expression*)ptr));
}
BinaryenExpressionRef BinaryenSIMDLoadStoreLane(BinaryenModuleRef module,
BinaryenOp op,
uint32_t offset,
uint32_t align,
uint8_t index,
BinaryenExpressionRef ptr,
BinaryenExpressionRef vec) {
return static_cast<Expression*>(
Builder(*(Module*)module)
.makeSIMDLoadStoreLane(SIMDLoadStoreLaneOp(op),
Address(offset),
Address(align),
index,
(Expression*)ptr,
(Expression*)vec));
}
BinaryenExpressionRef BinaryenMemoryInit(BinaryenModuleRef module,
uint32_t segment,
BinaryenExpressionRef dest,
Expand Down
16 changes: 16 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,14 @@ BINARYEN_API BinaryenOp BinaryenLoadExtUVec16x4ToVecI32x4(void);
BINARYEN_API BinaryenOp BinaryenLoadExtSVec32x2ToVecI64x2(void);
BINARYEN_API BinaryenOp BinaryenLoadExtUVec32x2ToVecI64x2(void);
// TODO: Add Load{32,64}Zero to C and JS APIs once merged to proposal
BINARYEN_API BinaryenOp BinaryenLoadLaneVec8x16(void);
BINARYEN_API BinaryenOp BinaryenLoadLaneVec16x8(void);
BINARYEN_API BinaryenOp BinaryenLoadLaneVec32x4(void);
BINARYEN_API BinaryenOp BinaryenLoadLaneVec64x2(void);
BINARYEN_API BinaryenOp BinaryenStoreLaneVec8x16(void);
BINARYEN_API BinaryenOp BinaryenStoreLaneVec16x8(void);
BINARYEN_API BinaryenOp BinaryenStoreLaneVec32x4(void);
BINARYEN_API BinaryenOp BinaryenStoreLaneVec64x2(void);
BINARYEN_API BinaryenOp BinaryenNarrowSVecI16x8ToVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenNarrowUVecI16x8ToVecI8x16(void);
BINARYEN_API BinaryenOp BinaryenNarrowSVecI32x4ToVecI16x8(void);
Expand Down Expand Up @@ -791,6 +799,14 @@ BINARYEN_API BinaryenExpressionRef BinaryenSIMDLoad(BinaryenModuleRef module,
uint32_t align,
BinaryenExpressionRef ptr);
BINARYEN_API BinaryenExpressionRef
BinaryenSIMDLoadStoreLane(BinaryenModuleRef module,
BinaryenOp op,
uint32_t offset,
uint32_t align,
uint8_t index,
BinaryenExpressionRef ptr,
BinaryenExpressionRef vec);
BINARYEN_API BinaryenExpressionRef
BinaryenMemoryInit(BinaryenModuleRef module,
uint32_t segment,
BinaryenExpressionRef dest,
Expand Down
32 changes: 32 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ function initializeConstants() {
'LoadExtUVec16x4ToVecI32x4',
'LoadExtSVec32x2ToVecI64x2',
'LoadExtUVec32x2ToVecI64x2',
'LoadLaneVec8x16',
'LoadLaneVec16x8',
'LoadLaneVec32x4',
'LoadLaneVec64x2',
'StoreLaneVec8x16',
'StoreLaneVec16x8',
'StoreLaneVec32x4',
'StoreLaneVec64x2',
'NarrowSVecI16x8ToVecI8x16',
'NarrowUVecI16x8ToVecI8x16',
'NarrowSVecI32x4ToVecI16x8',
Expand Down Expand Up @@ -1477,6 +1485,30 @@ function wrapModule(module, self = {}) {
'load32x2_u'(offset, align, ptr) {
return Module['_BinaryenSIMDLoad'](module, Module['LoadExtUVec32x2ToVecI64x2'], offset, align, ptr);
},
'load8_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['LoadLaneVec8x16'], offset, align, index, ptr, vec);
},
'load16_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['LoadLaneVec16x8'], offset, align, index, ptr, vec);
},
'load32_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['LoadLaneVec32x4'], offset, align, index, ptr, vec);
},
'load64_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['LoadLaneVec64x2'], offset, align, index, ptr, vec);
},
'store8_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['StoreLaneVec8x16'], offset, align, index, ptr, vec);
},
'store16_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['StoreLaneVec16x8'], offset, align, index, ptr, vec);
},
'store32_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['StoreLaneVec32x4'], offset, align, index, ptr, vec);
},
'store64_lane'(offset, align, index, ptr, vec) {
return Module['_BinaryenSIMDLoadStoreLane'](module, Module['StoreLaneVec64x2'], offset, align, index, ptr, vec);
},
'store'(offset, align, ptr, value) {
return Module['_BinaryenStore'](module, 16, offset, align, ptr, value, Module['v128']);
},
Expand Down
9 changes: 9 additions & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,15 @@ function test_core() {
module.v128.load16x4_u(0, 8, module.i32.const(128)),
module.v128.load32x2_s(0, 8, module.i32.const(128)),
module.v128.load32x2_u(0, 8, module.i32.const(128)),
// SIMD load/store lane
module.v128.load8_lane(0, 1, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.load16_lane(0, 2, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.load32_lane(0, 4, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.load64_lane(0, 8, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.store8_lane(0, 1, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.store16_lane(0, 2, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.store32_lane(0, 4, 0, module.i32.const(128), module.v128.const(v128_bytes)),
module.v128.store64_lane(0, 8, 0, module.i32.const(128), module.v128.const(v128_bytes)),
// Other SIMD
module.i8x16.shuffle(module.v128.const(v128_bytes), module.v128.const(v128_bytes), v128_bytes),
module.v128.bitselect(module.v128.const(v128_bytes), module.v128.const(v128_bytes), module.v128.const(v128_bytes)),
Expand Down
80 changes: 80 additions & 0 deletions test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,46 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(i32.const 128)
)
)
(drop
(v128.load8_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load16_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load32_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load64_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(v128.store8_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store16_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store32_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store64_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(drop
(i8x16.shuffle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down Expand Up @@ -3647,6 +3687,46 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7}
(i32.const 128)
)
)
(drop
(v128.load8_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load16_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load32_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load64_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(v128.store8_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store16_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store32_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store64_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(drop
(i8x16.shuffle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down
58 changes: 58 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,64 @@ void test_core() {
0,
8,
makeInt32(module, 128)),
// SIMD load/store lane
BinaryenSIMDLoadStoreLane(module,
BinaryenLoadLaneVec8x16(),
0,
1,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
BinaryenSIMDLoadStoreLane(module,
BinaryenLoadLaneVec16x8(),
0,
2,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
BinaryenSIMDLoadStoreLane(module,
BinaryenLoadLaneVec32x4(),
0,
4,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
BinaryenSIMDLoadStoreLane(module,
BinaryenLoadLaneVec64x2(),
0,
8,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),

BinaryenSIMDLoadStoreLane(module,
BinaryenStoreLaneVec8x16(),
0,
1,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
BinaryenSIMDLoadStoreLane(module,
BinaryenStoreLaneVec16x8(),
0,
2,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
BinaryenSIMDLoadStoreLane(module,
BinaryenStoreLaneVec32x4(),
0,
4,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
BinaryenSIMDLoadStoreLane(module,
BinaryenStoreLaneVec64x2(),
0,
8,
0,
makeInt32(module, 128),
makeVec128(module, v128_bytes)),
// Other SIMD
makeSIMDShuffle(module),
makeSIMDTernary(module, BinaryenBitselectVec128()),
Expand Down
40 changes: 40 additions & 0 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,46 @@ BinaryenFeatureAll: 8191
(i32.const 128)
)
)
(drop
(v128.load8_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load16_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load32_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(drop
(v128.load64_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
)
(v128.store8_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store16_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store32_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(v128.store64_lane 0
(i32.const 128)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
(drop
(i8x16.shuffle 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
Expand Down