add pseudocode to setvl
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 26 Jun 2019 08:24:28 +0000 (09:24 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 26 Jun 2019 08:24:28 +0000 (09:24 +0100)
simple_v_extension/specification/sv.setvl.mdwn

index f05e9bd249dd106318d8ac939f4f4b3bd003115f..a14a4d8408501bb609143dbe3b964460bca10cad 100644 (file)
@@ -51,3 +51,31 @@ instructions (brownfield encodings).
 | vsetvl  | 7          | TBD                                            |
 | vsetvl  | 8          | TBD                                            |
 
+
+pseudocode:
+
+    regs = [0u64; 128];
+    vl = 0;
+
+    // instruction fields:
+    rd = get_rd_field();
+    rs1 = get_rs1_field();
+    vlmax = get_immed_field();
+
+    // handle illegal instruction decoding
+    if vlmax > XLEN {
+        trap()
+    }
+
+    // calculate VL
+    if rs1 == 0 { // rs1 is x0
+        vl = vlmax
+    } else {
+        vl = min(regs[rs1], vlmax)
+    }
+
+    // write rd
+    if rd != 0 {
+        // rd is not x0
+        regs[rd] = vl
+    }