-
Notifications
You must be signed in to change notification settings - Fork 624
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
Add all SIMD operations into switch, implement V128 comparison operations. #3833
Add all SIMD operations into switch, implement V128 comparison operations. #3833
Conversation
addr_ret = GET_OFFSET(); | ||
|
||
V128 result; | ||
for (i = 0; i < 16; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comparison operations are fine, but this should have a proper SIMD implementation later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps worth leaving a todo so we won't forget?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already have this one in another branch, will raise it next
V128 result; | ||
for (i = 0; i < 16; i++) { | ||
result.i8x16[i] = | ||
v1.i8x16[i] == v2.i8x16[i] ? 0xff : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whereas the approach for v128.*
instructions is fine, I think for opcodes like this one we should have a mechanism to override the implementation with simd instructions if they're available for a given platform. So perhaps we could have an abstraction defined and per-platform files that implement that abstraction (with the default implementation that uses plain C).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do this in the next PR? I have a commit with some NEON implemented opcodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sounds good to me.
break; | ||
} | ||
|
||
// v128 comparison operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not all of them are comparison operations, but rather bitwise operations - see https://github.com/WebAssembly/spec/blob/main/proposals/simd/SIMD.md#bitwise-operations
break; | ||
} | ||
case SIMD_v128_and: | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a lot of repetition across the bitwise operations, perhaps we could define a macro for it?
@@ -5650,6 +5652,25 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, | |||
GET_OPCODE(); | |||
|
|||
switch (opcode) { | |||
// Memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better use /* .. */
to add comment, we usually use it for C source files. Same for below.
98af4ac
to
3cd395e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \ | ||
} while (0) | ||
|
||
// In the switch statement: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better use /* .. */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the comment
3cd395e
to
77c66d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a few minor comments, but overall LGTM
addr_ret = GET_OFFSET(); | ||
|
||
V128 result; | ||
for (i = 0; i < 16; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps worth leaving a todo so we won't forget?
V128 result; | ||
for (i = 0; i < 16; i++) { | ||
result.i8x16[i] = | ||
v1.i8x16[i] == v2.i8x16[i] ? 0xff : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sounds good to me.
@@ -487,6 +487,8 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) | |||
|
|||
#define POP_F64() (GET_F64_FROM_ADDR(frame_lp + GET_OFFSET())) | |||
|
|||
#define POP_V128() (GET_V128_FROM_ADDR(frame_lp + GET_OFFSET())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this was already merged, so you might need to rebase the branch.
Tested using ``` (module (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) (memory (export "memory") 1) (func $assert_true (param v128) local.get 0 v128.any_true i32.eqz if unreachable end ) (func $main (export "_start") ;; Test v128.not v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v128.not v128.const i8x16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 i8x16.eq call $assert_true ;; Test v128.and v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.and v128.const i8x16 255 255 0 0 0 0 0 0 255 255 0 0 0 0 0 0 i8x16.eq call $assert_true ;; Test v128.andnot v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.andnot v128.const i8x16 0 0 255 255 0 0 0 0 0 0 255 255 0 0 0 0 i8x16.eq call $assert_true ;; Test v128.or v128.const i8x16 255 255 0 0 0 0 255 255 255 255 0 0 0 0 255 0 v128.const i8x16 0 0 255 255 255 255 0 0 0 0 255 255 255 255 0 0 v128.or v128.const i8x16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 i8x16.eq call $assert_true ;; Test v128.xor v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.xor v128.const i8x16 0 0 255 255 255 255 0 0 0 0 255 255 255 255 0 0 i8x16.eq call $assert_true i32.const 0 call $proc_exit ) ) ```
77c66d4
to
c1bfe2a
Compare
2e61591
into
bytecodealliance:dev/simd_for_interp
Added all of the SIMD operations into the switch statement to avoid having to refer back and forth from the header, then implemented the V128 comparison operations using this test code: