add pseudocode to setvl
[libreriscv.git] / simple_v_extension / specification / sv.setvl.mdwn
1 # SV setvl exploration
2
3 Formats for Vector Configuration Instructions under OP-V major opcode:
4
5 | 31|30 25|24 20|19 15|14 12|11 7|6 0| name |
6 |---|------------------------|----------|-------|---------|-------|---------|
7 | 0 | imm[10:6] |imm[4:0] | rs1 | 1 1 1 | rd |1010111| vsetvli |
8 | 1 | 000000 | rs2 | rs1 | 1 1 1 | rd |1010111| vsetvl |
9 | 1 | 6 | 5 | 5 | 3 | 5 | 7 | |
10
11 Requirement: fit MVL into this format.
12
13 | 31|30 25|24 20|19 15|14 12|11 7|6 0| name |
14 |---|-------------|----------|----------|-------|---------|-------|---------|
15 | 0 | imm[10:6] |imm[4:0] | rs1 | 1 1 1 | rd |1010111| vsetvli |
16 | 1 | imm[5:0] | rs2 | rs1 | 1 1 1 | rd |1010111| vsetvl |
17 | 1 | 6 | 5 | 5 | 3 | 5 | 7 | |
18
19 where:
20
21 * when bit 31==0, both MVL and VL are set to imm(10:6) - plus one to
22 get it out of the "NOP" scenario.
23 * when bit 31==1, MVL is set to imm(5:0) plus one.
24
25 hang on... no, that's a 4-argument setvl! what about this?
26
27
28 | 31 25|24 20|19 15|14 12|11 7|6 0| name | variant# - |
29 |-----------------|----------|----------|-------|---------|-------|---------|------------|
30 | 0 | imm[5:0] | 0b00000 | rs1 | 1 1 1 | rd |1010111| vsetvli | 1 |
31 | 0 | imm[5:0] | 0b00000 | 0b00000 | 1 1 1 | rd |1010111| vsetvli | 2 |
32 | 0 | imm[5:0] | rs2!=x0 | rs1 | 1 1 1 | rd |1010111| vsetvli | 3 |
33 | 0 | imm[5:0] | rs2!=x0 | 0b00000 | 1 1 1 | rd |1010111| vsetvli | 4 |
34 | 1 | imm[5:0] | 0b00000 | rs1 | 1 1 1 | rd |1010111| vsetvl | 5 |
35 | 1 | imm[5:0] | 0b00000 | 0b00000 | 1 1 1 | rd |1010111| vsetvl | 6 |
36 | 1 | imm[5:0] | rs2!=x0 | rs1 | 1 1 1 | rd |1010111| vsetvl | 7 |
37 | 1 | imm[5:0] | rs2!=x0 | 0b00000 | 1 1 1 | rd |1010111| vsetvl | 8 |
38 | 1 | 6 | 5 | 5 | 3 | 5 | 7 | | |
39
40 i think those are the 8 permutations: what can those be used for? some of them for actual
41 instructions (brownfield encodings).
42
43 | name | variant# - | purpose |
44 |---------|------------|------------------------------------------------|
45 | vsetvli | 1 | TBD |
46 | vsetvli | 2 | TBD |
47 | vsetvli | 3 | TBD |
48 | vsetvli | 4 | TBD |
49 | vsetvl | 5 | TBD |
50 | vsetvl | 6 | TBD |
51 | vsetvl | 7 | TBD |
52 | vsetvl | 8 | TBD |
53
54
55 pseudocode:
56
57 regs = [0u64; 128];
58 vl = 0;
59
60 // instruction fields:
61 rd = get_rd_field();
62 rs1 = get_rs1_field();
63 vlmax = get_immed_field();
64
65 // handle illegal instruction decoding
66 if vlmax > XLEN {
67 trap()
68 }
69
70 // calculate VL
71 if rs1 == 0 { // rs1 is x0
72 vl = vlmax
73 } else {
74 vl = min(regs[rs1], vlmax)
75 }
76
77 // write rd
78 if rd != 0 {
79 // rd is not x0
80 regs[rd] = vl
81 }