RISC-V manual
The instruction set cheatsheet
ortfero
The RISC-V instruction set as the aldan machine runs it: RV64
with M, F, D, Zicsr, Zifencei, Zba, Zbb, Zbs, Sdtrig and a
subset of V, in machine mode. Each instruction is listed with
what it does; whatever aldan leaves out is marked. Opcodes,
CSR numbers and codes are hexadecimal; bit positions, counts
and sizes are decimal. The devices and the memory map are in
the aldan codex.
Aldan manual
Architecture
Extensions
| Name | What it adds | Aldan |
| I | The base integer set | Yes |
| M | Multiply and divide | Yes |
| A | Atomics: LR/SC and AMO | No |
| F | Single-precision float | Yes |
| D | Double-precision float | Yes |
| C | 16-bit compressed encodings | No |
| V | Vectors | Subset |
| Zicsr | CSR access | Yes |
| Zifencei | fence.i | A no-op |
| Zicntr | Counters: time, cycle, instret | Partial |
| Zba | Address generation | Yes |
| Zbb | Basic bit manipulation | Yes |
| Zbs | Single-bit operations | Yes |
| Sdtrig | Debug triggers | Yes |
Aldan has time and instret but not cycle. G is shorthand for
IMAFD with Zicsr and Zifencei, so aldan is
rv64imfdv_zicsr_zifencei_zba_zbb_zbs: G without A, plus V.
Privilege levels
| Level | Name | Aldan |
| 3 | Machine | The only one |
| 1 | Supervisor | Absent: no paging, no satp |
| 0 | User | Absent: no PMP |
Integer registers
32 registers of XLEN = 64 bits, x0 to x31, and the pc. x0
always reads 0 and drops writes. The ABI names and who saves
them across a call:
| Register | ABI | Use | Saved |
| x0 | zero | Always 0 | — |
| x1 | ra | Return address | Caller |
| x2 | sp | Stack pointer | Callee |
| x3 | gp | Global pointer | — |
| x4 | tp | Thread pointer | — |
| x5-x7 | t0-t2 | Temporaries | Caller |
| x8 | s0, fp | Saved, frame pointer | Callee |
| x9 | s1 | Saved | Callee |
| x10-x11 | a0-a1 | Arguments, results | Caller |
| x12-x17 | a2-a7 | Arguments | Caller |
| x18-x27 | s2-s11 | Saved | Callee |
| x28-x31 | t3-t6 | Temporaries | Caller |
- Integer arguments go in a0 to a7, results in a0 and a1; whatever does not fit goes on the stack.
- sp is 16-aligned at every call, and the stack grows down.
- A 32-bit value is kept sign-extended to 64 bits, even an unsigned one.
Float registers
32 registers f0 to f31 of FLEN = 64 bits, and fcsr.
| Register | ABI | Use | Saved |
| f0-f7 | ft0-ft7 | Temporaries | Caller |
| f8-f9 | fs0-fs1 | Saved | Callee |
| f10-f11 | fa0-fa1 | Arguments, results | Caller |
| f12-f17 | fa2-fa7 | Arguments | Caller |
| f18-f27 | fs2-fs11 | Saved | Callee |
| f28-f31 | ft8-ft11 | Temporaries | Caller |
A single held in a 64-bit register is NaN-boxed: the upper 32
bits are all ones. A single that is not boxed reads as the
canonical NaN.
Vector registers
32 registers v0 to v31 of VLEN = 256 bits on aldan, and the
CSRs vl, vtype, vstart, vxrm and vxsat. v0 holds the mask of a
masked instruction. All of them are caller-saved.
Memory
- One byte-addressed space of 2^64 bytes, little-endian.
- Only loads and stores touch memory; every other instruction works on registers.
- An instruction is 32 bits and 4-aligned: without C, a jump or branch to a pc that is not 4-aligned traps (cause 0). Data may be misaligned, at the cost of a trap on some machines; aldan never traps on either.
- The model is RVWMO: another hart or a device may see stores in another order until a fence. Aldan has one hart and devices that finish inside the store, so a fence is never needed there.
Instruction formats
Every instruction is one 32-bit word. The opcode is bits 6-0,
rd 11-7, funct3 14-12, rs1 19-15 and rs2 24-20, in every
format that has them.
31-25 24-20 19-15 14-12 11-7 6-0
R | funct7 | rs2 | rs1 | f3 | rd | opcode |
I | imm 11:0 | rs1 | f3 | rd | opcode |
S | imm 11:5 | rs2 | rs1 | f3 | imm 4:0 | opcode |
B | 12,10:5 | rs2 | rs1 | f3 | 4:1,11 | opcode |
U | imm 31:12 | rd | opcode |
J | imm 20,10:1,11,19:12 | rd | opcode |
R4 | rs3,fmt | rs2 | rs1 | rm | rd | opcode |
V | f6,vm | vs2 | vs1 | f3 | vd | 57 |
- Every immediate is sign-extended from its top bit, which is always bit 31 of the word.
- I and S hold 12 bits: -2048 to 2047.
- B and J encode even offsets: a branch reaches 4 KB each way, jal 1 MB.
- U is the upper 20 bits of a 32-bit value: lui sets it, addi adds the low 12, and a negative low part needs the upper part one higher.
Major opcodes
| Opcode | Name | Opcode | Name |
| 03 | LOAD | 33 | OP |
| 07 | LOAD-FP | 37 | LUI |
| 0F | MISC-MEM | 3B | OP-32 |
| 13 | OP-IMM | 43-4F | MADD, MSUB, NMSUB, NMADD |
| 17 | AUIPC | 53 | OP-FP |
| 1B | OP-IMM-32 | 57 | OP-V |
| 23 | STORE | 63 | BRANCH |
| 27 | STORE-FP | 67 | JALR |
| | 6F | JAL |
| | 73 | SYSTEM |
LOAD-FP and STORE-FP carry the vector loads and stores too,
told apart by the width field.
Base integer set
Arithmetic and logic
| Instruction | What it does |
| add rd, rs1, rs2 | rd = rs1 + rs2 |
| sub rd, rs1, rs2 | rd = rs1 - rs2 |
| addi rd, rs1, imm | rd = rs1 + imm |
| and, or, xor | Bitwise, rd = rs1 op rs2 |
| andi, ori, xori | Bitwise with imm |
| slt rd, rs1, rs2 | rd = 1 if rs1 < rs2 signed, else 0 |
| sltu | The same, unsigned |
| slti, sltiu | The same against imm; sltiu still sign-extends imm |
| lui rd, imm | rd = imm << 12 |
| auipc rd, imm | rd = pc + (imm << 12) |
Overflow is ignored: there are no flags and no carry. A carry
out of an add is sltu rd, sum, rs1.
Shifts
| Instruction | What it does |
| sll rd, rs1, rs2 | Shift left by rs2 and 63 |
| srl | Logical shift right |
| sra | Arithmetic shift right |
| slli, srli, srai | By a 6-bit shamt |
32-bit operations
Each works on the low 32 bits and sign-extends the 32-bit
result to 64.
| Instruction | What it does |
| addw, subw | 32-bit add, subtract |
| addiw rd, rs1, imm | 32-bit add of imm; addiw rd, rs, 0 is sext.w |
| sllw, srlw, sraw | 32-bit shifts by rs2 and 31 |
| slliw, srliw, sraiw | By a 5-bit shamt |
Loads and stores
| Instruction | What it does |
| ld rd, off(rs1) | Load 64 bits from rs1 + off |
| lw, lh, lb | Load 32, 16, 8 bits, sign-extended |
| lwu, lhu, lbu | The same, zero-extended |
| sd rs2, off(rs1) | Store 64 bits at rs1 + off |
| sw, sh, sb | Store the low 32, 16, 8 bits |
Branches and jumps
| Instruction | What it does |
| beq rs1, rs2, label | Branch if rs1 = rs2 |
| bne | If rs1 is not rs2 |
| blt, bge | If rs1 < rs2, rs1 >= rs2, signed |
| bltu, bgeu | The same, unsigned |
| jal rd, label | rd = pc + 4, jump to label |
| jalr rd, off(rs1) | rd = pc + 4, pc = (rs1 + off) with bit 0 cleared |
jalr reads rs1 before it writes rd, so jalr ra, 0(ra) works.
auipc and jalr together reach any pc within 2 GB.
System
| Instruction | What it does |
| ecall | Trap to the environment: mcause B from machine mode |
| ebreak | Trap as a breakpoint: mcause 3 |
| fence pred, succ | Order memory: pred before succ (i, o, r, w); a no-op on aldan |
| fence.i | Make stored code visible to fetch; a no-op on aldan |
| mret | Return from a machine trap |
| wfi | Wait for an interrupt |
Pseudo-instructions
The assembler's shorthands, and what they stand for.
| Pseudo | Is |
| nop | addi zero, zero, 0 |
| li rd, imm | lui and addi, or a longer sequence for 64 bits |
| la rd, symbol | auipc and addi |
| mv rd, rs | addi rd, rs, 0 |
| not rd, rs | xori rd, rs, -1 |
| neg rd, rs | sub rd, zero, rs |
| negw rd, rs | subw rd, zero, rs |
| sext.w rd, rs | addiw rd, rs, 0 |
| zext.b rd, rs | andi rd, rs, 255 |
| seqz rd, rs | sltiu rd, rs, 1 |
| snez rd, rs | sltu rd, zero, rs |
| sltz, sgtz | slt rd, rs, zero; slt rd, zero, rs |
| beqz, bnez rs, label | beq, bne against zero |
| blez, bgez, bltz, bgtz | The signed branches against zero |
| bgt, ble, bgtu, bleu | blt, bge, bltu, bgeu with the operands swapped |
| j label | jal zero, label |
| jal label | jal ra, label |
| jr rs | jalr zero, 0(rs) |
| jalr rs | jalr ra, 0(rs) |
| ret | jalr zero, 0(ra) |
| call symbol | auipc ra and jalr ra: any distance within 2 GB |
| tail symbol | auipc t1 and jalr zero: a jump that does not return here |
M: multiply and divide
| Instruction | What it does |
| mul rd, rs1, rs2 | Low 64 bits of rs1 * rs2 |
| mulh | High 64 bits, signed * signed |
| mulhu | High 64 bits, unsigned |
| mulhsu | High 64 bits, signed rs1 * unsigned rs2 |
| div, divu | Quotient, signed, unsigned; rounds toward zero |
| rem, remu | Remainder, signed, unsigned; takes the sign of rs1 |
| mulw | 32-bit product, sign-extended |
| divw, divuw, remw, remuw | 32-bit divide and remainder, sign-extended |
Nothing traps. Division by zero gives all ones for the
quotient and rs1 for the remainder. The one signed overflow,
the most negative number divided by -1, gives rs1 and
remainder 0. For a full 128-bit product, take mulh then mul
with the same operands.
F and D: floating point
F works on 32-bit singles (suffix .s), D on 64-bit doubles
(.d); every instruction listed with .s has a .d twin. Operands
are f registers unless named rd or rs.
Arithmetic
| Instruction | What it does |
| flw, fld rd, off(rs) | Load a float |
| fsw, fsd rs2, off(rs1) | Store a float |
| fadd.s, fsub.s, fmul.s, fdiv.s | rd = rs1 op rs2 |
| fsqrt.s rd, rs1 | Square root |
| fmin.s, fmax.s | The smaller, the larger; a NaN loses to a number |
| fmadd.s rd, rs1, rs2, rs3 | rd = rs1 * rs2 + rs3, rounded once |
| fmsub.s | rd = rs1 * rs2 - rs3 |
| fnmsub.s | rd = -(rs1 * rs2) + rs3 |
| fnmadd.s | rd = -(rs1 * rs2) - rs3 |
Sign, compare, classify
| Instruction | What it does |
| fsgnj.s rd, rs1, rs2 | rs1 with the sign of rs2 |
| fsgnjn.s | With the sign of rs2 inverted |
| fsgnjx.s | With the two signs xored |
| feq.s rd, rs1, rs2 | rd = 1 if equal, else 0 |
| flt.s, fle.s | rd = 1 if less, less or equal |
| fclass.s rd, rs1 | One bit in rd for the class of rs1, below |
fmv.s, fneg.s and fabs.s are fsgnj, fsgnjn and fsgnjx with
rs1 = rs2. A comparison with a NaN gives 0; flt and fle also
raise NV for it, feq only for a signalling NaN.
| Bit | Class of fclass | Bit | Class of fclass |
| 0 | -inf | 5 | Positive subnormal |
| 1 | Negative normal | 6 | Positive normal |
| 2 | Negative subnormal | 7 | +inf |
| 3 | -0 | 8 | Signalling NaN |
| 4 | +0 | 9 | Quiet NaN |
Conversion and moves
| Instruction | What it does |
| fcvt.w.s rd, rs1 | Float to signed 32-bit integer |
| fcvt.wu.s, fcvt.l.s, fcvt.lu.s | To unsigned 32, signed 64, unsigned 64 |
| fcvt.s.w rd, rs1 | Signed 32-bit integer to float |
| fcvt.s.wu, fcvt.s.l, fcvt.s.lu | From unsigned 32, signed 64, unsigned 64 |
| fcvt.s.d, fcvt.d.s | Double to single, single to double |
| fmv.x.w rd, rs1 | The bits of a single to rd, sign-extended |
| fmv.w.x rd, rs1 | The low 32 bits of rs1 to a single |
| fmv.x.d, fmv.d.x | The 64 bits of a double, each way |
A conversion to an integer saturates: out of range or NaN
gives the largest value of the type (the smallest for a
negative number), and raises NV. A conversion or an arithmetic
instruction may take a rounding mode as its last operand:
fcvt.w.d a0, fa0, rtz truncates.
Rounding and flags
| rm | Mode | Meaning |
| 0 | rne | To nearest, ties to even |
| 1 | rtz | Toward zero |
| 2 | rdn | Down |
| 3 | rup | Up |
| 4 | rmm | To nearest, ties away |
| 7 | dyn | Take frm |
| Bit | Flag | Meaning |
| 4 | NV | Invalid operation |
| 3 | DZ | Divide by zero |
| 2 | OF | Overflow |
| 1 | UF | Underflow |
| 0 | NX | Inexact |
fcsr (CSR 3) holds frm in bits 7-5 and fflags in bits 4-0; frm
(2) and fflags (1) reach each part alone. The flags accrue:
they stay set until written 0. Nothing traps on a float
exception.
Zicsr: control and status registers
| Instruction | What it does |
| csrrw rd, csr, rs1 | rd = csr, csr = rs1 |
| csrrs rd, csr, rs1 | rd = csr, set the bits of rs1 |
| csrrc rd, csr, rs1 | rd = csr, clear the bits of rs1 |
| csrrwi, csrrsi, csrrci | The same with a 5-bit unsigned immediate |
| Pseudo | Is |
| csrr rd, csr | csrrs rd, csr, zero |
| csrw csr, rs | csrrw zero, csr, rs |
| csrs, csrc csr, rs | csrrs, csrrc with rd = zero |
| csrwi, csrsi, csrci | The immediate forms, rd = zero |
| rdtime rd | csrr rd, time |
| rdinstret rd | csrr rd, instret |
| frcsr, fscsr | Read, swap fcsr |
| frrm, fsrm | Read, swap frm |
csrrs and csrrc with rs1 = zero only read: they write nothing.
csrrw with rd = zero does not read. The cycle counter,
rdcycle, is not on aldan.
Zba: address generation
| Instruction | What it does |
| sh1add rd, rs1, rs2 | rd = (rs1 << 1) + rs2 |
| sh2add, sh3add | rd = (rs1 << 2) + rs2, (rs1 << 3) + rs2 |
| add.uw rd, rs1, rs2 | rd = zext32(rs1) + rs2 |
| sh1add.uw, sh2add.uw, sh3add.uw | rd = (zext32(rs1) << n) + rs2 |
| slli.uw rd, rs1, shamt | rd = zext32(rs1) << shamt |
sh3add a0, index, base is the address of base[index] for
64-bit elements. zext.w rd, rs is add.uw rd, rs, zero.
Zbb: basic bit manipulation
| Instruction | What it does |
| andn, orn rd, rs1, rs2 | rd = rs1 and, or the inverse of rs2 |
| xnor | rd = inverse of rs1 xor rs2 |
| clz, ctz rd, rs1 | Count the leading, trailing zeros; 64 for 0 |
| clzw, ctzw | The same on the low 32 bits |
| cpop, cpopw | Count the set bits, of 64 and of 32 |
| min, max | The smaller, the larger, signed |
| minu, maxu | The same, unsigned |
| sext.b, sext.h | Sign-extend the low 8, 16 bits |
| zext.h | Zero-extend the low 16 bits |
| rol, ror rd, rs1, rs2 | Rotate left, right by rs2 and 63 |
| rori | Rotate right by shamt; there is no roli |
| rolw, rorw, roriw | Rotate the low 32 bits, sign-extended |
| orc.b rd, rs1 | Each byte of rs1 becomes FF if it is not 0, else 00 |
| rev8 rd, rs1 | Reverse the order of the bytes |
orc.b finds a zero byte in a word at once, as a string search
wants; rev8 turns a big-endian value around.
Zbs: single-bit operations
| Instruction | What it does |
| bset rd, rs1, rs2 | rs1 with bit rs2 and 63 set |
| bclr | With that bit cleared |
| binv | With that bit inverted |
| bext rd, rs1, rs2 | rd = bit rs2 and 63 of rs1 |
| bseti, bclri, binvi, bexti | The same with a 6-bit index |
Machine mode
Trap CSRs
| CSR | Number | What it holds |
| mstatus | 300 | MIE bit 3, MPIE 7, MPP 12-11 |
| mie, mip | 304, 344 | Enabled, pending interrupts: MSIE/MSIP 3, MTIE/MTIP 7, MEIE/MEIP 11 |
| mtvec | 305 | Trap base; mode in bits 1-0: 0 direct, 1 vectored |
| mscratch | 340 | Scratch for the handler |
| mepc | 341 | The pc of the trapped instruction |
| mcause | 342 | Bit 63 for an interrupt, the code below |
| mtval | 343 | The bad address or instruction |
The rest of mstatus (FS, VS, the S and U bits) does nothing on
aldan, nor does the rest of mie. The full list of what works
is in the aldan codex.
Causes
| Code | Exception | Code | Interrupt |
| 0 | Instruction misaligned | 3 | Machine software |
| 1 | Instruction access | 7 | Machine timer |
| 2 | Illegal instruction | B | Machine external |
| 3 | Breakpoint | | |
| 4, 6 | Load, store misaligned | | |
| 5, 7 | Load, store access | | |
| 8, 9 | ecall from U, S | | |
| B | ecall from M | | |
| C, D, F | Page faults | | |
Aldan raises only 2, 3 and B, and the three machine
interrupts.
Taking a trap
- Entry: mepc = pc, mcause and mtval set, MPIE = MIE, MIE = 0, MPP = the old mode, pc = mtvec base. In vectored mode an interrupt goes to base + 4 * code.
- mepc points at the instruction itself: an ecall or ebreak handler adds 4 before mret.
- mret: MIE = MPIE, MPIE = 1, pc = mepc.
- An interrupt is taken when its mip and mie bits are both set and mstatus.MIE is on. External beats software, which beats timer.
- wfi waits until some interrupt is pending and enabled in mie, whatever mstatus.MIE says; with MIE off it just falls through to the next instruction.
Timer and software interrupts
MTIP is high while mtime >= mtimecmp, two 64-bit registers of
the clint; writing a later mtimecmp clears it. MSIP is bit 0
of the clint's msip register. The time CSR reads mtime.
Debug triggers (Sdtrig)
tselect (7A0) picks a trigger; tdata1 (7A1) sets it up, its
type in bits 63-60; tdata2 (7A2) holds its address; tinfo
(7A4) lists the types it can take. Aldan has 8 triggers of
type 6, mcontrol6 (execute at an exact address), and 3, icount
(step a count of instructions). A trigger that fires is a
breakpoint: mcause 3. tcontrol (7A5) holds the bit that keeps
triggers off inside a handler.
The PLIC
The platform-level interrupt controller gathers the lines of
the devices and offers them to the harts as one external
interrupt, MEIP.
- Each source 1 to 1023 has a gateway, a pending bit and a priority; 0 is no source. Priority 0 never interrupts, and the higher priority wins, then the lower id.
- A context is a hart in one mode; it has an enable bit per source and a threshold. A source interrupts the context when it is pending and enabled, and its priority is above the threshold.
- Claim: a read of the context's claim register returns the best source and clears its pending bit, or returns 0 when there is none.
- Complete: writing that id back to the same register. The gateway sends no new request for the source until then; a level-triggered line that is still high is pending again at once.
- So a handler claims, serves the device until its line drops, then completes, and claims again until 0.
| Offset | Register |
| 0 + 4 * source | Priority |
| 1000 | Pending bits, 32 sources a word |
| 2000 + 80 * context | Enable bits of the context |
| 200000 + 1000 * context | Threshold of the context |
| 200004 + 1000 * context | Claim on read, complete on write |
All registers are 32 bits. Aldan has one context, 0 for hart 0
in machine mode, sources 1 to 5F and priorities 0 to 7.
V: vectors
The model
- Each of the 32 registers holds VLEN bits: 256 on aldan, so vlenb = 32 bytes.
- vtype sets the element width SEW and the group LMUL: a group of LMUL registers acts as one longer register, and an operand names its first, a multiple of LMUL.
- vl is the number of elements an instruction works on, at most VLMAX = LMUL * VLEN / SEW. The ones past vl are the tail.
- A masked instruction, written with a last operand v0.t, works only on the elements whose bit is set in v0: bit i of v0 for element i.
- vta and vma pick what tail and masked-off elements become: undisturbed, or agnostic (anything, perhaps all ones). Aldan always leaves them undisturbed.
- vstart is the element to resume from after a trap; it is 0 otherwise.
| SEW | m1 | m2 | m4 | m8 | Elements of VLEN 256 |
| e8 | 32 | 64 | 128 | 256 | |
| e16 | 16 | 32 | 64 | 128 | |
| e32 | 8 | 16 | 32 | 64 | |
| e64 | 4 | 8 | 16 | 32 | |
Configuration
| Instruction | What it does |
| vsetvli rd, rs1, e32, m4, ta, ma | vtype = e32, m4, ta, ma; vl = min(rs1, VLMAX); rd = vl |
| vsetivli rd, uimm, vtype | The same with a 5-bit count |
| vsetvl rd, rs1, rs2 | The same with vtype in rs2 |
With rs1 = zero and rd not zero, vl = VLMAX. With both zero,
vl stays and only vtype changes.
| vtype bits | Field | Values |
| 2-0 | vlmul | 0 m1, 1 m2, 2 m4, 3 m8; 5 mf8, 6 mf4, 7 mf2 |
| 5-3 | vsew | 0 e8, 1 e16, 2 e32, 3 e64 |
| 6 | vta | Tail agnostic |
| 7 | vma | Mask agnostic |
| 63 | vill | The vtype asked for is not supported |
A vtype aldan does not support (fractional LMUL, or SEW above
64) sets vill and vl = 0, and then every vector instruction
but vset is illegal.
| CSR | Number | What it holds |
| vstart | 008 | The first element to work on |
| vxsat | 009 | Set by a saturating instruction that clamped |
| vxrm | 00A | Fixed-point rounding: 0 rnu (to nearest, up), 1 rne, 2 rdn (truncate), 3 rod (to odd) |
| vcsr | 00F | vxrm in bits 2-1, vxsat in bit 0 |
| vl | C20 | The element count, read only |
| vtype | C21 | The type, read only |
| vlenb | C22 | VLEN in bytes, read only |
A loop
The count left goes into vsetvli at each pass, and the pass
takes as many elements as fit; there is no remainder loop.
This adds 1 to a0 words from a1 into a2:
loop:
vsetvli t0, a0, e32, m8, ta, ma
vle32.v v8, (a1)
vadd.vi v8, v8, 1
vse32.v v8, (a2)
sub a0, a0, t0
sh2add a1, t0, a1
sh2add a2, t0, a2
bnez a0, loop
Operands
An instruction is named for its operands: .vv two vectors, .vx
a vector and an integer register, .vi a vector and a 5-bit
immediate, .vf a vector and a float register, .vs a vector and
element 0 of another, .mm two masks, .vvm and the rest a mask
in v0 as well. The second source comes first: vsub.vv vd, vs2,
vs1 is vd = vs2 - vs1. The immediate is signed, but unsigned
for shifts and slides.
Loads and stores
| Instruction | What it does |
| vle8.v, vle16.v, vle32.v, vle64.v vd, (rs1) | Unit stride: vl elements from rs1 on |
| vse8.v ... vse64.v vs3, (rs1) | Unit-stride store |
| vlse8.v ... vlse64.v vd, (rs1), rs2 | Strided: element i from rs1 + i * rs2 |
| vsse8.v ... vsse64.v | Strided store |
| vluxei8.v ... vluxei64.v vd, (rs1), vs2 | Indexed: element i from rs1 + vs2[i]; vloxei in order |
| vsuxei8.v ..., vsoxei8.v ... | Indexed stores |
| vl1r.v vd, (rs1) | One whole register, whatever vl |
| vs1r.v vs3, (rs1) | Store one whole register |
On aldan the element width of a load or store must equal SEW,
and an index is SEW bits too. There are no mask loads (vlm.v),
no fault-only-first, no segments and no vl2r.v to vl8r.v.
Integer arithmetic
| Instruction | What it does |
| vadd.vv, .vx, .vi | vd = vs2 + vs1 |
| vsub.vv, .vx | vd = vs2 - vs1 |
| vrsub.vx, .vi | vd = x - vs2; vneg.v is vrsub.vx vd, vs, zero |
| vand, vor, vxor .vv, .vx, .vi | Bitwise; vnot.v is vxor.vi vd, vs, -1 |
| vsll, vsrl, vsra .vv, .vx, .vi | Shifts by the low log2(SEW) bits |
| vmin, vminu, vmax, vmaxu .vv, .vx | Smaller, larger, signed and unsigned |
| vmul .vv, .vx | Low half of the product |
| vmulh, vmulhu, vmulhsu .vv, .vx | High half: signed, unsigned, signed * unsigned |
| vmacc.vv, .vx | vd = vd + vs1 * vs2 |
| vnmsac.vv, .vx | vd = vd - vs1 * vs2 |
| vwmul, vwmulu, vwmulsu .vv, .vx | Widening: a 2 * SEW product into a group of 2 * LMUL |
| vwadd, vwaddu .vv, .vx | Widening sum; vwadd.vx vd, vs, zero sign-extends |
| vmerge.vvm, .vxm, .vim | vd = vs1, x or imm where v0 is set, else vs2 |
| vmv.v.v, .v.x, .v.i | Copy or splat into vd |
Compare
Each sets bit i of the mask vd to the result for element i.
| Instruction | What it does |
| vmseq, vmsne .vv, .vx, .vi | Equal, not equal |
| vmslt, vmsltu .vv, .vx | Less, signed and unsigned |
| vmsle, vmsleu .vv, .vx, .vi | Less or equal |
| vmsgt, vmsgtu .vx, .vi | Greater; for .vv swap the operands of vmslt |
Fixed point
| Instruction | What it does |
| vsadd, vsaddu .vv, .vx, .vi | Add, clamped to the range |
| vssub, vssubu .vv, .vx | Subtract, clamped |
| vaadd.vv, .vx | (vs2 + vs1) / 2, rounded by vxrm, without overflow |
| vsmul.vv, .vx | vs2 * vs1 >> (SEW - 1), rounded and clamped: a Q15 or Q31 product |
| vssra.vv, .vx, .vi | Arithmetic shift right, rounded by vxrm |
A clamp sets vxsat.
Slides and moves
| Instruction | What it does |
| vslideup.vx, .vi vd, vs2, n | vd[i + n] = vs2[i]; vd[0] to vd[n - 1] keep their value |
| vslidedown.vx, .vi | vd[i] = vs2[i + n], 0 past VLMAX |
| vslide1up.vx vd, vs2, rs1 | vd[0] = rs1, vd[i + 1] = vs2[i] |
| vslide1down.vx | vd[i] = vs2[i + 1], vd[vl - 1] = rs1 |
| vmv.x.s rd, vs2 | rd = element 0, sign-extended |
| vmv.s.x vd, rs1 | Element 0 = rs1 |
Reductions and masks
| Instruction | What it does |
| vredsum.vs vd, vs2, vs1 | vd[0] = vs1[0] + the sum of vs2 |
| vredmax, vredmaxu, vredmin, vredminu | The same with max or min, from vs1[0] |
| vmand, vmnand, vmandn, vmor, vmnor, vmorn, vmxor, vmxnor .mm | Mask logic, bit by bit: vs2 op vs1. vmnand, vmnor, vmxnor invert the result; vmandn, vmorn invert vs1 |
| vcpop.m rd, vs2 | The count of set bits below vl |
| vfirst.m rd, vs2 | The index of the first set bit, or -1 |
vmmv.m is vmand.mm vd, vs, vs; vmnot.m is vmnand.mm vd, vs,
vs; vmclr.m is vmxor.mm vd, vd, vd; vmset.m is vmxnor.mm vd,
vd, vd.
Float
SEW 32 or 64 only, rounded by frm.
| Instruction | What it does |
| vfadd, vfsub, vfmul, vfdiv .vv, .vf | vd = vs2 op vs1, or op rs1 |
| vfmin, vfmax .vv, .vf | Smaller, larger |
| vfsgnj, vfsgnjn .vv, .vf | Sign injection; vfneg.v is vfsgnjn.vv vd, vs, vs |
| vfmacc.vv, .vf | vd = vd + vs1 * vs2 |
| vfsqrt.v vd, vs2 | Square root |
| vfcvt.x.f.v, vfcvt.xu.f.v | Float to integer, by frm |
| vfcvt.rtz.x.f.v, vfcvt.rtz.xu.f.v | Float to integer, truncated |
| vfcvt.f.x.v, vfcvt.f.xu.v | Integer to float |
| vfmv.v.f vd, rs1 | Splat a float |
| vfmv.f.s rd, vs2 | rd = element 0 |
| vfmv.s.f vd, rs1 | Element 0 = rs1 |
| vfredusum.vs | vd[0] = vs1[0] + the sum of vs2 |
Missing on aldan
These decode as illegal instructions: vdiv, vdivu, vrem and
vremu; vrgather, vcompress, vid.v and viota.m; vzext and
vsext; every narrowing instruction (vnsrl, vnclip, vfncvt) and
the widening ones but the vwmul and vwadd families; vmv1r.v to
vmv8r.v; vredand, vredor, vredxor, vmsbf, vmsif and vmsof;
vfrsub, vfrdiv, vfsgnjx, the float compares, vfclass,
vfredosum, vfredmax, vfredmin, vfmsac and the other fused
forms but vfmacc; vaaddu, vasub and vasubu; vmadd, vnmsub and
the carry instructions vadc, vsbc, vmadc and vmsbc. Instead of
vmv1r.v use vl1r.v and vs1r.v through memory, or vmv.v.v under
an LMUL that covers the group.