-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
riscv64: Implement SIMD swizzle
and shuffle
#6515
Merged
afonso360
merged 5 commits into
bytecodealliance:main
from
afonso360:riscv-simd-swizzle-shuffle
Jun 6, 2023
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8ab222
riscv64: Implement SIMD `swizzle`
afonso360 5ad5159
riscv64: Implement SIMD `shuffle`
afonso360 b344e63
wasmtime: Enable more RISC-V SIMD tests
afonso360 90352ce
riscv64: Add TODO issue numbers
afonso360 6dfe822
riscv64: Fix trailing newline issues
afonso360 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,7 @@ | |
(VmergeVVM) | ||
(VredmaxuVS) | ||
(VredminuVS) | ||
(VrgatherVV) | ||
|
||
;; Vector-Scalar Opcodes | ||
(VaddVX) | ||
|
@@ -145,6 +146,7 @@ | |
(VfrdivVF) | ||
(VmergeVXM) | ||
(VfmergeVFM) | ||
(VrgatherVX) | ||
(VmsltVX) | ||
)) | ||
|
||
|
@@ -163,6 +165,7 @@ | |
(VxorVI) | ||
(VslidedownVI) | ||
(VmergeVIM) | ||
(VrgatherVI) | ||
)) | ||
|
||
;; Imm only ALU Ops | ||
|
@@ -718,6 +721,25 @@ | |
(rule (rv_vredmaxu_vs vs2 vs1 mask vstate) | ||
(vec_alu_rrr (VecAluOpRRR.VredmaxuVS) vs2 vs1 mask vstate)) | ||
|
||
;; Helper for emitting the `vrgather.vv` instruction. | ||
;; | ||
;; vd[i] = (vs1[i] >= VLMAX) ? 0 : vs2[vs1[i]]; | ||
(decl rv_vrgather_vv (VReg VReg VecOpMasking VState) VReg) | ||
(rule (rv_vrgather_vv vs2 vs1 mask vstate) | ||
(vec_alu_rrr (VecAluOpRRR.VrgatherVV) vs2 vs1 mask vstate)) | ||
|
||
;; Helper for emitting the `vrgather.vx` instruction. | ||
;; | ||
;; vd[i] = (x[rs1] >= VLMAX) ? 0 : vs2[x[rs1]] | ||
(decl rv_vrgather_vx (VReg XReg VecOpMasking VState) VReg) | ||
(rule (rv_vrgather_vx vs2 vs1 mask vstate) | ||
(vec_alu_rrr (VecAluOpRRR.VrgatherVX) vs2 vs1 mask vstate)) | ||
|
||
;; Helper for emitting the `vrgather.vi` instruction. | ||
(decl rv_vrgather_vi (VReg UImm5 VecOpMasking VState) VReg) | ||
(rule (rv_vrgather_vi vs2 imm mask vstate) | ||
(vec_alu_rr_uimm5 (VecAluOpRRImm5.VrgatherVI) vs2 imm mask vstate)) | ||
|
||
;; Helper for emitting the `vmslt.vx` (Vector Mask Set Less Than) instruction. | ||
(decl rv_vmslt_vx (VReg XReg VecOpMasking VState) VReg) | ||
(rule (rv_vmslt_vx vs2 vs1 mask vstate) | ||
|
@@ -757,4 +779,20 @@ | |
;; Materialize the mask into an X register, and move it into the bottom of | ||
;; the vector register. | ||
(rule (gen_vec_mask mask) | ||
(rv_vmv_sx (imm $I64 mask) (vstate_from_type $I64X2))) | ||
(rv_vmv_sx (imm $I64 mask) (vstate_from_type $I64X2))) | ||
|
||
|
||
;; Loads a `VCodeConstant` value into a vector register. For some special `VCodeConstant`s | ||
;; we can use a dedicated instruction, otherwise we load the value from the pool. | ||
;; | ||
;; Type is the preferred type to use when loading the constant. | ||
(decl gen_constant (Type VCodeConstant) VReg) | ||
|
||
;; The fallback case is to load the constant from the pool. | ||
(rule (gen_constant ty n) | ||
(vec_load | ||
(element_width_from_type ty) | ||
(VecAMode.UnitStride (gen_const_amode n)) | ||
(mem_flags_trusted) | ||
(unmasked) | ||
ty)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: missing trailing newline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cranelift/filetests/filetests/isa/riscv64/simd-shuffle.clif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
test compile precise-output | ||
set unwind_info=false | ||
target riscv64 has_v | ||
|
||
function %shuffle_i8x16(i8x16, i8x16) -> i8x16 { | ||
block0(v0: i8x16, v1: i8x16): | ||
v2 = shuffle v0, v1, [3 0 31 26 4 6 12 11 23 13 24 4 2 15 17 5] | ||
return v2 | ||
} | ||
|
||
; VCode: | ||
; add sp,-16 | ||
; sd ra,8(sp) | ||
; sd fp,0(sp) | ||
; mv fp,sp | ||
; block0: | ||
; vle8.v v1,16(fp) #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vle8.v v3,32(fp) #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vle8.v v6,[const(0)] #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vrgather.vv v8,v1,v6 #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vadd.vi v10,v6,-16 #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vrgather.vv v12,v3,v10 #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vor.vv v14,v8,v12 #avl=16, #vtype=(e8, m1, ta, ma) | ||
; vse8.v v14,0(a0) #avl=16, #vtype=(e8, m1, ta, ma) | ||
; ld ra,8(sp) | ||
; ld fp,0(sp) | ||
; add sp,+16 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; addi sp, sp, -0x10 | ||
; sd ra, 8(sp) | ||
; sd s0, 0(sp) | ||
; ori s0, sp, 0 | ||
; block1: ; offset 0x10 | ||
; .byte 0x57, 0x70, 0x08, 0xcc | ||
; addi t6, s0, 0x10 | ||
; .byte 0x87, 0x80, 0x0f, 0x02 | ||
; addi t6, s0, 0x20 | ||
; .byte 0x87, 0x81, 0x0f, 0x02 | ||
; auipc t6, 0 | ||
; addi t6, t6, 0x3c | ||
; .byte 0x07, 0x83, 0x0f, 0x02 | ||
; .byte 0x57, 0x04, 0x13, 0x32 | ||
; .byte 0x57, 0x35, 0x68, 0x02 | ||
; .byte 0x57, 0x06, 0x35, 0x32 | ||
; .byte 0x57, 0x07, 0x86, 0x2a | ||
; .byte 0x27, 0x07, 0x05, 0x02 | ||
; ld ra, 8(sp) | ||
; ld s0, 0(sp) | ||
; addi sp, sp, 0x10 | ||
; ret | ||
; .byte 0x00, 0x00, 0x00, 0x00 | ||
; .byte 0x00, 0x00, 0x00, 0x00 | ||
; .byte 0x00, 0x00, 0x00, 0x00 | ||
; lb zero, 0x1a1(t5) | ||
; .byte 0x04, 0x06, 0x0c, 0x0b | ||
; auipc s10, 0x4180 | ||
; .byte 0x02, 0x0f, 0x11, 0x05 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
Can you either resolve this TODO in this PR or turn it into
TODO(#1234)
with a reference to a follow up issue?