[WIP] Add twin-butterfly proposed insn
authorKonstantinos Margaritis <konstantinos.margaritis@vectorcamp.gr>
Thu, 27 Apr 2023 16:26:25 +0000 (16:26 +0000)
committerKonstantinos Margaritis <konstantinos.margaritis@vectorcamp.gr>
Thu, 27 Apr 2023 16:26:25 +0000 (16:26 +0000)
openpower/sv/twin_butterfly.mdwn

index 9234358554c09e201d91c8d5c8cdcf72fe5d0d83..4ce57a779df3b1f4f20a0439b3e878f9f0e794e7 100644 (file)
@@ -1,3 +1,83 @@
 <https://bugs.libre-soc.org/show_bug.cgi?id=1074>
 
-TODO
+# [DRAFT] Twin Butterfly DCT Instruction(s)
+
+The goal is to implement instructions that calculate the expression:
+
+```
+fdct_round_shift((a +/- b) * c)
+```
+
+For the single-coefficient butterfly instruction, and:
+
+```
+ fdct_round_shift(a * c1  +/- b * c2)
+```
+
+For the double-coefficient butterfly instruction.
+
+`fdct_round_shift` is defined as `ROUND_POWER_OF_TWO(x, 14)`
+
+```
+#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n)-1))) >> (n))
+```
+
+The suggestion is to have a single instruction to calculate both values `((a + b) * c) >> N`, and `((a - b) * c) >> N`.
+The instruction will run in accumulate mode, so in order to calculate the 2-coeff version one would just have to call the same instruction with different order a, b and a different constant c.
+
+```
+# [DRAFT] Integer Butterfly Multiply Add/Sub FFT/DCT
+
+BF-Form
+
+* maddsubrs  RT,RA,RB,RC,SH
+
+Pseudo-code:
+
+    RT2 <- RT + 1
+    sum <- (RA) + (RB)
+    diff <- (RA) - (RB)
+    prod1 <- MUL(RC, sum)
+    prod2 <- MUL(RC, diff)
+    res1 <- ROTL64(prod1, SH)
+    res2 <- ROTL64(prod2, SH)
+    RT <- (RT) + res1
+    RT2 <- (RT2) + res2
+
+Special Registers Altered:
+
+    None
+```
+
+Where BF-Form is defined in fields.txt:
+
+```
+# 1.6.39 BF-FORM
+    |0     | 6   |11   |16   |21   | 25  |30  |31  |
+    | PO   | RT  | RA  | RB  | RC  | SH  | XO | Rc |
+
+```
+
+The resulting autogenerated code is:
+
+```
+class butterfly:
+    @inject()
+    def op_maddsubrs(self, RA, RB, RC, RT):
+        RT2 = copy_assign_rhs(RT + 1)
+        sum = copy_assign_rhs(RA + RB)
+        diff = copy_assign_rhs(RA - RB)
+        prod1 = copy_assign_rhs(self.MUL(RC, sum))
+        prod2 = copy_assign_rhs(self.MUL(RC, diff))
+        res1 = copy_assign_rhs(self.ROTL64(prod1, SH))
+        res2 = copy_assign_rhs(self.ROTL64(prod2, SH))
+        RT = copy_assign_rhs(RT + res1)
+        RT2 = copy_assign_rhs(RT2 + res2)
+        return (RT,)
+```
+
+The instruction has been added to `minor_59.csv`:
+```
+1111011111,ALU,OP_MADDSUBRS,RA,RB,RC,RT,NONE,CR1,0,0,ZERO,0,NONE,0,0,0,0,1,0,RC_ONLY,0,0,maddsubrs,A,,1,unofficial until submitted and approved/renumbered by the opf isa wg
+```
+