(no commit message)
authorlkcl <lkcl@web>
Wed, 2 Oct 2019 09:04:51 +0000 (10:04 +0100)
committerIkiWiki <ikiwiki.info>
Wed, 2 Oct 2019 09:04:51 +0000 (10:04 +0100)
simple_v_extension/specification/bitmanip.mdwn

index 0e741c3c97764674ac81d48a2b7552acc6bf339a..23925483e68f2856320e5ad9fa1afcb1b5e36468 100644 (file)
@@ -158,6 +158,22 @@ Pseudo-code:
                        sif a2, a3, a0
      1 1 x x x x 1 1   a2 contents
 
+Pseudo-code:
+
+    def sbf(rd, rs1, rs2):
+        rd = 0
+        setting_mode = rs2 == x0 or (regs[rs2] & 1)
+        while i < XLEN:
+            bit = 1<<i
+            if setting_mode:
+                regs[rd] |= bit
+                if regs[rs1] & bit: # found a bit in rs1: stop setting rd
+                    setting_mode = False
+            else if rs2 != x0: # searching mode
+                if (regs[rs2] & bit):
+                    setting_mode = True # back into "setting" mode
+            i += 1
+
 ## sof - set only first bit
 
      # Example