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

Implement RISC-V Vector Extension #504

Open
howjmay opened this issue Oct 19, 2024 · 3 comments · May be fixed by #545
Open

Implement RISC-V Vector Extension #504

howjmay opened this issue Oct 19, 2024 · 3 comments · May be fixed by #545
Labels
enhancement New feature or request

Comments

@howjmay
Copy link
Collaborator

howjmay commented Oct 19, 2024

RISC-V "V" Vector Extension (shorten as RVV) is the instruction extension that introduces vector process capabilities to RISCV.

The staged goal of this issue is to explore the possibility to run RVV instructions with rv32emu.

  • Configure vtype and vl CSRs with vsetvli/vsetivli/vsetvl. This is required because RVV vector register is variable-legnth.
  • Unit-Stride store/load instructions. This can help us to build the minimum POC.
  • Basic integer ALU instructions ( vadd, vsub, vmin, vmax, vand, vor, vxor) and permutation instructions (vrgather, vslideup, vslidedown)

To achieve the goals we need to

  1. Implement the instruction decoder (in decode.c). This decoder should be able to decode all three instructions formats (valu, vcfg, vmem)
  2. Add the corresponding CSRs (vl, vtype)
  3. Implement RVV instructions into custom IRs. Some of RVV may be implemented as a loop of basic instructions (like vadd from add). To maintain the readability of throughout the entire codebase, adding a new src file rvv_template.c for the RVV's IRs may be a better idea.
  4. Study the further implementations (exception handling, rounding mode, float-points, comparison, mask instructions, etc.)

We can refer the following resource

  1. RVV spec https://github.com/riscv/riscv-isa-manual/blob/main/src/v-st-ext.adoc
  2. instruction tables https://github.com/riscv/riscv-isa-manual/blob/main/src/images/wavedrom/v-inst-table.edn
  3. alu instructions formats https://github.com/riscv/riscv-isa-manual/blob/main/src/images/wavedrom/valu-format.edn
  4. vector configuration instructions format https://github.com/riscv/riscv-isa-manual/blob/main/src/images/wavedrom/vcfg-format.edn
  5. Spike's bit masks for decoding instructions https://github.com/riscv-software-src/riscv-isa-sim/blob/master/riscv/encoding.h
@howjmay howjmay changed the title rvv: Verify the possibility to implement RISC-V "V" Vector Extension rvv: Explore the possible implementation of RVV instructions Oct 19, 2024
@howjmay
Copy link
Collaborator Author

howjmay commented Oct 20, 2024

the size of rv_insn.opcode may need to be extended

@howjmay
Copy link
Collaborator Author

howjmay commented Oct 25, 2024

Saw another tool may benefit us from testing https://github.com/hushenwei2000/rvv-atg

@jserv jserv changed the title rvv: Explore the possible implementation of RVV instructions Implement RISC-V Vector Extension Oct 28, 2024
@howjmay
Copy link
Collaborator Author

howjmay commented Dec 1, 2024

The complexity of RVV makes me hesitant to implement it. Due to the size and complexity of RVV. I doubt I have the ability to keep the codebase as concise and small like it is right now.
Some of the challenges are listed in the following.

  1. Most of the RVV instructions have three forms vi, vv, vx. This may be solvable, but do increase the code size.
  2. RVV's length-agonistic feature, force us to support multiple VLEN (the max vector register length), and dynamic vl (every instruction can explicitly claims the vector register size they need)
  3. The c implementation for rv32 instruction in rv32_template.c cant be reused at all for RVV, because RVV needs to support (un)signed integers from 8 bits to 64 bits. And in a lot of case, 64 bits operation may encounter edge case so the implementation for other bit size cant be applied to 64 bits either.
  4. The more complex instructions like ld, and st may further introduce complexity.

@jserv jserv linked a pull request Jan 27, 2025 that will close this issue
@jserv jserv added the enhancement New feature or request label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants