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.
I think the comparison operations are fine, but this should have a proper SIMD implementation later.
There was a problem hiding this comment.
perhaps worth leaving a todo so we won't forget?
There was a problem hiding this comment.
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.
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.
I'll do this in the next PR? I have a commit with some NEON implemented opcodes
| break; | ||
| } | ||
|
|
||
| // v128 comparison operations |
There was a problem hiding this comment.
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.
I think there's a lot of repetition across the bitwise operations, perhaps we could define a macro for it?
| GET_OPCODE(); | ||
|
|
||
| switch (opcode) { | ||
| // Memory |
There was a problem hiding this comment.
Had better use /* .. */ to add comment, we usually use it for C source files. Same for below.
98af4ac to
3cd395e
Compare
| PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \ | ||
| } while (0) | ||
|
|
||
| // In the switch statement: |
There was a problem hiding this comment.
Removed the comment
3cd395e to
77c66d4
Compare
loganek
left a comment
There was a problem hiding this comment.
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.
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; |
|
|
||
| #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.
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
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: