Skip to content

Latest commit

 

History

History
715 lines (458 loc) · 19.9 KB

rvv-intrinsic-api.md

File metadata and controls

715 lines (458 loc) · 19.9 KB

RISC-V Vector Extension Intrinsic API Reference Manual

1. Preface

These builtins targets on rvv 0.9 and trying to document rvv_intrinsics programming model.

2. Design Decisions and philosophy

Please see rvv-intrinsic-rfc.md

3. None

Keep this chapter none to aligned to riscv-v-spec chapters

4. None

Keep this chapter none to aligned to riscv-v-spec chapters

5. General Naming Rules

Please see rvv-intrinsic-rfc.md

6. Configuration-Setting and Utility Functions

Instructions

  • vsetvli
  • vsetvl

Set vl and vtype Functions

Set vl to VLMAX with specific vtype

Read vl value

Reinterpret Cast Conversion Functions

Reinterpret the contents of a data as a different type, without changing any bits and generating any RVV instructions.

Vector Initialization Functions

Read/Write URW vector CSRs

enum RVV_CSR {
  RVV_VSTART = 0,
  RVV_VXSAT,
  RVV_VXRM,
  RVV_VCSR,
};

unsigned long vread_csr(enum RVV_CSR csr);
void vwrite_csr(enum RVV_CSR csr, unsigned long value);

7. Vector Loads and Stores

7.4. Vector Unit-Stride Operations

Instructions

  • vle<eew>.v
  • vse<eew>.v

7.5. Vector Strided Load/Store Operations

Instructions

  • vlse<eew>.v
  • vsse<eew>.v

7.6. Vector Indexed Load/Store Operations

Instructions

  • vlxei<eew>.v
  • vsxei<eew>.v
  • vsuxei<eew>.v

7.7. Unit-stride Fault-Only-First Loads Operations

Instructions

  • vle<eew>ff.v

Notes

  • Execute a regular load and stop load operation if there is 0 value of element, and then set vl equals the index of last non-zero value.

7.8. Vector Load/Store Segment Operations (Zvlsseg)

7.8.1. Vector Unit-Stride Segment Loads and Stores

Instructions

  • vlsege<eew>.v
  • vssege<eew>.v

7.8.2. Vector Strided Segment Loads and Stores

Instructions

  • vlssege<eew>.v
  • vsssege<eew>.v

7.8.3. Vector Indexed Segment Loads and Stores

Instructions

  • vlxsegei<eew>.v
  • vsxsegei<eew>.v

8. Vector AMO Operations (Zvamo)

Instructions

  • vamoswapei<eew>.v
  • vamoaddei<eew>.v
  • vamoxorei<eew>.v
  • vamoandei<eew>.v
  • vamoorei<eew>.v
  • vamominei<eew>.v
  • vamomaxei<eew>.v
  • vamominuei<eew>.v
  • vamomaxuei<eew>.v

9. None

Keep this chapter none to aligned to riscv-v-spec chapters

10. None

Keep this chapter none to aligned to riscv-v-spec chapters

11. None

Keep this chapter none to aligned to riscv-v-spec chapters

12. Vector Integer Arithmetic Operations

12.1. Vector Single-Width Integer Add and Subtract

Instructions

  • vadd.{vv,vx,vi}
  • vsub.{vv,vx}
  • vrsub.{vx,vi}

12.2. Vector Widening Integer Add/Subtract Operations

Instructions

  • vwaddu.{vv,vx,wv,wx}
  • vwsubu.{vv,vx,wv,wx}
  • vwadd.{vv,vx,wv,wx}
  • vwsub.{vv,vx,wv,wx}

12.3 Vector Integer Extension

Instructions

  • vzext.vf{2,4,8}
  • vsext.vf{2,4,8}

12.4. Vector Integer Add-with-Carry / Subtract-with-Borrow Operations

Instructions

  • vadc.{vvm,vxm,vim}
  • vmadc.{vvm,vxm,vim}
  • vsbc.{vvm,vxm}
  • vmsbc.{vvm,vxm}

12.5. Vector Bitwise Logical Operations

Instructions

  • vand.{vv,vx,vi}
  • vxor.{vv,vx,vi}
  • vor.{vv,vx,vi}

12.6. Vector Single-Width Bit Shift Operations

Instructions

  • vsll.{vv,vx,vi}
  • vsrl.{vv,vx,vi}
  • vsra.{vv,vx,vi}

Notes

  • A full complement of vector shift instructions are provided, including logical shift left, and logical (zero-extending) and arithmetic (sign-extending) shift right.

12.7. Vector Narrowing Integer Right Shift Operations

Instructions

  • vnsra.{vv,vx,vi}
  • vnsrl.{vv,vx,vi}

12.8. Vector Integer Comparison Operations

Instructions

  • vmseq.{vv,vx,vi}
  • vmsne.{vv,vx,vi}
  • vmsltu.{vv,vx}
  • vmslt.{vv,vx}
  • vmsleu.{vv,vx,vi}
  • vmsle.{vv,vx,vi}
  • vmsgtu.{vx,vi}
  • vmsgt.{vx,vi}

12.9. Vector Integer Min/Max Operations

Instructions

  • vminu_{vv,vx}
  • vmin_{vv,vx}
  • vmaxu_{vv,vx}
  • vmax_{vv,vx}

12.10. Vector Single-Width Integer Multiply Operations

Instructions

  • vmul_{vv,vx}
  • vmulh_{vv,vx}
  • vmulhu_{vv,vx}
  • vmulhsu_{vv,vx}

12.11. Vector Integer Divide Operations

Instructions

  • vdivu.{vv,vx}
  • vdiv.{vv,vx}
  • vremu.{vv,vx}
  • vrem.{vv,vx}

12.12. Vector Widening Integer Multiply Operations

Instructions

  • vwmul.{vv,vx}
  • vwmulu.{vv,vx}
  • vwmulsu.{vv,vx}

12.13. Vector Single-Width Integer Multiply-Add Operations

Instructions

  • vmacc_{vv,vx}
  • vnmsac_{vv,vx}
  • vmadd_{vv,vx}
  • vnmsub_{vv,vx}

12.14. Vector Widening Integer Multiply-Add Operations

Instructions

  • vwmaccu.{vv,vx}
  • vwmacc.{vv,vx}
  • vwmaccsu.{vv,vx}
  • vwmaccus.{vv,vx}

12.15. Vector Quad-Widening Integer Multiply-Add Operations (Extension Zvqmac)

Instuctions

  • vqmaccu.{vv,vx}
  • vqmacc.{vv,vx}
  • vqmaccsu.{vv,vx}
  • vqmaccus.vx

12.16. Vector Integer Merge Operations

Instructions

  • vmerge.{vvm,vxm,vim}

12.17. Vector Integer Move Operations

Instructions

  • vmv.v.v
  • vmv.v.x
  • vmv.v.i

13. Vector Fixed-Point Arithmetic Operations

13.1. Vector Single-Width Saturating Add and Subtract

Instructions

  • vsaddu.{vv,vx,vi}
  • vsadd.{vv,vx,vi}
  • vssubu.{vv,vx}
  • vssub.{vv,vx}

13.2. Vector Single-Width Averaging Add and Subtract

Instructions

  • vaadd.{vv,vx,vi}
  • vasub.{vv,vx}

13.3. Vector Single-Width Fractional Multiply with Rounding and Saturation

Instructions

  • vsmul.{vv,vx}

13.4. Vector Single-Width Scaling Shift Operations

Instructions

  • vssrl.{vv,vx,vi}
  • vssra.{vv,vx,vi}

13.5. Vector Narrowing Fixed-Point Clip Operations

Instructions

  • vnclipu.{wx,wv,wi}
  • vnclip.{wx,wv,wi}

14. Vector Floating-Point Operations

14.2. Vector Single-Width Floating-Point Add/Subtract Operations

Instructions

  • vfadd.{vv,vf}
  • vfsub.{vv,vf}
  • vfrsub.vf

14.3. Vector Widening Floating-Point Add/Subtract Operations

Instructions

  • vfwadd.{vv,vf,wv,wf}
  • vfwsub.{vv,vf,wv,wf}

14.4. Vector Single-Width Floating-Point Multiply/Divide Operations

Instructions

  • vfmul.{vv,vf}
  • vfdiv.{vv,vf}
  • vfrdiv.{vv,vf}

14.5. Vector Widening Floating-Point Multiply Operations

Instructions

  • vfwmul.{vv,vf}

14.6. Vector Single-Width Floating-Point Fused Multiply-Add Operations

Instructions

  • vfmacc.{vv,vf}
  • vfnmacc.{vv,vf}
  • vfmsac.{vv,vf}
  • vfnmsac.{vv,vf}
  • vfmadd.{vv,vf}
  • vfnmadd.{vv,vf}
  • vfmsub.{vv,vf}
  • vfnmsub.{vv,vf}

14.7. Vector Widening Floating-Point Fused Multiply-Add Operations

Instructions

  • vfwmacc.{vv,vf}
  • vfwnmacc.{vv,vf}
  • vfwmsac.{vv,vf}
  • vfwnmsac.{vv,vf}

14.8. Vector Floating-Point Square-Root Operations

Instructions

  • vfsqrt.v

14.9. Vector Floating-Point MIN/MAX Operations

  • vfmin.{vv,vf}
  • vfmax.{vv,vf}

14.10. Vector Floating-Point Sign-Injection Operations

Instructions

  • vfsgnj.{vv,vf}
  • vfsgnjn.{vv,vf}
  • vfsgnjx.{vv,vf}

14.11. Vector Floating-Point Compare Operations

Instructions

  • vmfeq.{vv,vf}
  • vmfne.{vv,vf}
  • vmflt.{vv,vf}
  • vmfle.{vv,vf}
  • vmfgt.vf
  • vmfge.vf

14.12. Vector Floating-Point Classify Operations

Instructions

  • vfclass.v

14.13. Vector Floating-Point Merge Operations

Instructions

  • vfmerge.vfm

14.14. Vector Floating-Point Move Operations

Instructions

  • vfmv.v.f

14.15. Single-Width Floating-Point/Integer Type-Convert Operations

Instructions

  • vfcvt.xu.f.v
  • vfcvt.x.f.v
  • vfcvt.f.xu.v
  • vfcvt.f.x.v

14.16. Widening Floating-Point/Integer Type-Convert Operations

Instructions

  • vfwcvt.xu.f.v
  • vfwcvt.x.f.v
  • vfwcvt.f.xu.v
  • vfwcvt.f.x.v
  • vfwcvt.f.f.v

14.17. Narrowing Floating-Point/Integer Type-Convert Operations

Instructions

  • vfncvt.xu.f.w
  • vfncvt.x.f.w
  • vfncvt.f.xu.w
  • vfncvt.f.x.w
  • vfncvt.f.f.w
  • vfncvt.rod.f.f.w

15. Vector Reduction Operations

15.1. Vector Single-Width Integer Reduction Operations

Instructions

  • vredsum.vs
  • vredmaxu.vs
  • vredmax.vs
  • vredminu.vs
  • vredmin.vs
  • vredand.vs
  • vredor.vs
  • vredxor.vs

15.2. Vector Widening Integer Reduction Operations

Instructions

  • vwredsumu.vs
  • vwredsum.vs

15.3. Vector Single-Width Floating-Point Reduction Operations

Instructions

  • vfredosum.vs
  • vfredsum.vs
  • vfredmax.vs
  • vfredmin.vs

15.4. Vector Widening Floating-Point Reduction Operations

Instructions

  • vfwredosum.vs
  • vfwredsum.vs

16. Vector Mask Instructions

16.1. Vector Mask-Register Logical Operations

Instructions

  • vmand.mm
  • vmnand.mm
  • vmandnot.mm
  • vmxor.mm
  • vmor.mm
  • vmnor.mm
  • vmornot.mm
  • vmxnor.mm
  • vmmv.m
  • vmclr.m
  • vmset.m
  • vmnot.m

16.2. Vector mask population count vpopc

Instructions

  • vpopc.m

16.3. vfirst find-first-set mask bit

Instructions

  • vfirst.m

16.4. vmsbf.m set-before-first mask bit

Instructions

  • vmsbf.m

16.5. vmsif.m set-including-first mask bit

Instructions

  • vmsif.m

16.6. vmsof.m set-only-first mask bit

Instructions

  • vmsof.m

16.8. Vector Iota Operations

Instructions

  • viota.m

16.9. Vector Element Index Operations

Instructions

  • vid.v

17. Vector Permutation Operations

17.1. Integer Scalar Move Operations

Instructions

  • vmv.s.x
  • vmv.x.s

17.2. Floating-Point Scalar Move Operations

Instructions

  • vfmv.f.s
  • vfmv.s.f

17.3. Vector Slide Operations

Instructions

  • vslideup.{vx,vi}
  • vslidedown.{vx,vi}
  • vslide1up.vx
  • vslide1down.vx
  • vfslide1up.vx
  • vfslide1down.vx

17.4. Vector Register Gather Operations

Instructions

  • vrgather.{vx,vi}

17.5. Vector Compress Operations

Instructions

  • vcompress.vm

18. None

Keep this chapter none to aligned to riscv-v-spec chapters

19. Divided Element Extension ('Zvediv')

19.3. Vector Integer Dot-Product Operations

Instructions

  • vdotu.vv
  • vdot.vv

Intrinsic functions list

TODO

19.4. Vector Floating-Point Dot Product Operations

Instructions

  • vfdotu.vv

Intrinsic functions list

TODO

20. RVV Intrinsic Examples