Skip to content
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

Conversation

afonso360
Copy link
Contributor

@afonso360 afonso360 commented Jun 3, 2023

👋 Hey,

This PR implements the swizzle and shuffle instructions in the RISC-V backend.

swizzle maps directly onto vrgather with a SEW of 8, so that's a fairly simple implementation. For shuffle we have to do two vrgathers one for values in the range of the first register and the second for values in range of the second register and merge them together.

I double checked the shuffle implementation, and it seems to match what v8 does.

vrgather is a somewhat special instruction in that it forbids the destination register from being the same as any of the source registers (including the mask register). I've modeled this as an early_def, which seems to be correct based on what I've read from regalloc2 docs, but I'm not 100% sure.

There are a few other instructions like this, but none that we have implemented yet.

@afonso360 afonso360 requested review from a team as code owners June 3, 2023 17:49
@afonso360 afonso360 requested review from fitzgen and removed request for a team June 3, 2023 17:49
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. labels Jun 3, 2023
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the following little nitpicks. Thanks!

@@ -1573,6 +1573,12 @@

;; UImm5 Helpers

;; Extractor that matches a `Value` equivalent to a replicated UImm5 on all lanes.
;; TODO: Try matching vconst here as well
Copy link
Member

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?

(mem_flags_trusted)
(unmasked)
ty))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: missing trailing newline

@afonso360 afonso360 enabled auto-merge June 6, 2023 17:50
@afonso360 afonso360 added this pull request to the merge queue Jun 6, 2023
Merged via the queue into bytecodealliance:main with commit 579918c Jun 6, 2023
@afonso360 afonso360 deleted the riscv-simd-swizzle-shuffle branch June 6, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants